UNPKG

9.19 kBTypeScriptView Raw
1export class Buffer extends Uint8Array {
2 length: number
3 write(string: string, offset?: number, length?: number, encoding?: string): number;
4 toString(encoding?: string, start?: number, end?: number): string;
5 toJSON(): { type: 'Buffer', data: any[] };
6 equals(otherBuffer: Buffer): boolean;
7 compare(otherBuffer: Uint8Array, targetStart?: number, targetEnd?: number, sourceStart?: number, sourceEnd?: number): number;
8 copy(targetBuffer: Buffer, targetStart?: number, sourceStart?: number, sourceEnd?: number): number;
9 slice(start?: number, end?: number): Buffer;
10 writeUIntLE(value: number, offset: number, byteLength: number, noAssert?: boolean): number;
11 writeUIntBE(value: number, offset: number, byteLength: number, noAssert?: boolean): number;
12 writeIntLE(value: number, offset: number, byteLength: number, noAssert?: boolean): number;
13 writeIntBE(value: number, offset: number, byteLength: number, noAssert?: boolean): number;
14 readUIntLE(offset: number, byteLength: number, noAssert?: boolean): number;
15 readUIntBE(offset: number, byteLength: number, noAssert?: boolean): number;
16 readIntLE(offset: number, byteLength: number, noAssert?: boolean): number;
17 readIntBE(offset: number, byteLength: number, noAssert?: boolean): number;
18 readUInt8(offset: number, noAssert?: boolean): number;
19 readUInt16LE(offset: number, noAssert?: boolean): number;
20 readUInt16BE(offset: number, noAssert?: boolean): number;
21 readUInt32LE(offset: number, noAssert?: boolean): number;
22 readUInt32BE(offset: number, noAssert?: boolean): number;
23 readBigUInt64LE(offset: number): BigInt;
24 readBigUInt64BE(offset: number): BigInt;
25 readInt8(offset: number, noAssert?: boolean): number;
26 readInt16LE(offset: number, noAssert?: boolean): number;
27 readInt16BE(offset: number, noAssert?: boolean): number;
28 readInt32LE(offset: number, noAssert?: boolean): number;
29 readInt32BE(offset: number, noAssert?: boolean): number;
30 readBigInt64LE(offset: number): BigInt;
31 readBigInt64BE(offset: number): BigInt;
32 readFloatLE(offset: number, noAssert?: boolean): number;
33 readFloatBE(offset: number, noAssert?: boolean): number;
34 readDoubleLE(offset: number, noAssert?: boolean): number;
35 readDoubleBE(offset: number, noAssert?: boolean): number;
36 reverse(): this;
37 swap16(): Buffer;
38 swap32(): Buffer;
39 swap64(): Buffer;
40 writeUInt8(value: number, offset: number, noAssert?: boolean): number;
41 writeUInt16LE(value: number, offset: number, noAssert?: boolean): number;
42 writeUInt16BE(value: number, offset: number, noAssert?: boolean): number;
43 writeUInt32LE(value: number, offset: number, noAssert?: boolean): number;
44 writeUInt32BE(value: number, offset: number, noAssert?: boolean): number;
45 writeBigUInt64LE(value: number, offset: number): BigInt;
46 writeBigUInt64BE(value: number, offset: number): BigInt;
47 writeInt8(value: number, offset: number, noAssert?: boolean): number;
48 writeInt16LE(value: number, offset: number, noAssert?: boolean): number;
49 writeInt16BE(value: number, offset: number, noAssert?: boolean): number;
50 writeInt32LE(value: number, offset: number, noAssert?: boolean): number;
51 writeInt32BE(value: number, offset: number, noAssert?: boolean): number;
52 writeBigInt64LE(value: number, offset: number): BigInt;
53 writeBigInt64BE(value: number, offset: number): BigInt;
54 writeFloatLE(value: number, offset: number, noAssert?: boolean): number;
55 writeFloatBE(value: number, offset: number, noAssert?: boolean): number;
56 writeDoubleLE(value: number, offset: number, noAssert?: boolean): number;
57 writeDoubleBE(value: number, offset: number, noAssert?: boolean): number;
58 fill(value: any, offset?: number, end?: number): this;
59 indexOf(value: string | number | Buffer, byteOffset?: number, encoding?: string): number;
60 lastIndexOf(value: string | number | Buffer, byteOffset?: number, encoding?: string): number;
61 includes(value: string | number | Buffer, byteOffset?: number, encoding?: string): boolean;
62
63 /**
64 * Allocates a new buffer containing the given {str}.
65 *
66 * @param str String to store in buffer.
67 * @param encoding encoding to use, optional. Default is 'utf8'
68 */
69 constructor (str: string, encoding?: string);
70 /**
71 * Allocates a new buffer of {size} octets.
72 *
73 * @param size count of octets to allocate.
74 */
75 constructor (size: number);
76 /**
77 * Allocates a new buffer containing the given {array} of octets.
78 *
79 * @param array The octets to store.
80 */
81 constructor (array: Uint8Array);
82 /**
83 * Produces a Buffer backed by the same allocated memory as
84 * the given {ArrayBuffer}.
85 *
86 *
87 * @param arrayBuffer The ArrayBuffer with which to share memory.
88 */
89 constructor (arrayBuffer: ArrayBuffer);
90 /**
91 * Allocates a new buffer containing the given {array} of octets.
92 *
93 * @param array The octets to store.
94 */
95 constructor (array: any[]);
96 /**
97 * Copies the passed {buffer} data onto a new {Buffer} instance.
98 *
99 * @param buffer The buffer to copy.
100 */
101 constructor (buffer: Buffer);
102 prototype: Buffer;
103 /**
104 * Allocates a new Buffer using an {array} of octets.
105 *
106 * @param array
107 */
108 static from(array: any[]): Buffer;
109 /**
110 * When passed a reference to the .buffer property of a TypedArray instance,
111 * the newly created Buffer will share the same allocated memory as the TypedArray.
112 * The optional {byteOffset} and {length} arguments specify a memory range
113 * within the {arrayBuffer} that will be shared by the Buffer.
114 *
115 * @param arrayBuffer The .buffer property of a TypedArray or a new ArrayBuffer()
116 * @param byteOffset
117 * @param length
118 */
119 static from(arrayBuffer: ArrayBuffer, byteOffset?: number, length?: number): Buffer;
120 /**
121 * Copies the passed {buffer} data onto a new Buffer instance.
122 *
123 * @param buffer
124 */
125 static from(buffer: Buffer | Uint8Array): Buffer;
126 /**
127 * Creates a new Buffer containing the given JavaScript string {str}.
128 * If provided, the {encoding} parameter identifies the character encoding.
129 * If not provided, {encoding} defaults to 'utf8'.
130 *
131 * @param str
132 */
133 static from(str: string, encoding?: string): Buffer;
134 /**
135 * Returns true if {obj} is a Buffer
136 *
137 * @param obj object to test.
138 */
139 static isBuffer(obj: any): obj is Buffer;
140 /**
141 * Returns true if {encoding} is a valid encoding argument.
142 * Valid string encodings in Node 0.12: 'ascii'|'utf8'|'utf16le'|'ucs2'(alias of 'utf16le')|'base64'|'binary'(deprecated)|'hex'
143 *
144 * @param encoding string to test.
145 */
146 static isEncoding(encoding: string): boolean;
147 /**
148 * Gives the actual byte length of a string. encoding defaults to 'utf8'.
149 * This is not the same as String.prototype.length since that returns the number of characters in a string.
150 *
151 * @param string string to test.
152 * @param encoding encoding used to evaluate (defaults to 'utf8')
153 */
154 static byteLength(string: string, encoding?: string): number;
155 /**
156 * Returns a buffer which is the result of concatenating all the buffers in the list together.
157 *
158 * If the list has no items, or if the totalLength is 0, then it returns a zero-length buffer.
159 * If the list has exactly one item, then the first item of the list is returned.
160 * If the list has more than one item, then a new Buffer is created.
161 *
162 * @param list An array of Buffer objects to concatenate
163 * @param totalLength Total length of the buffers when concatenated.
164 * If totalLength is not provided, it is read from the buffers in the list. However, this adds an additional loop to the function, so it is faster to provide the length explicitly.
165 */
166 static concat(list: Uint8Array[], totalLength?: number): Buffer;
167 /**
168 * The same as buf1.compare(buf2).
169 */
170 static compare(buf1: Uint8Array, buf2: Uint8Array): number;
171 /**
172 * Allocates a new buffer of {size} octets.
173 *
174 * @param size count of octets to allocate.
175 * @param fill if specified, buffer will be initialized by calling buf.fill(fill).
176 * If parameter is omitted, buffer will be filled with zeros.
177 * @param encoding encoding used for call to buf.fill while initializing
178 */
179 static alloc(size: number, fill?: string | Buffer | number, encoding?: string): Buffer;
180 /**
181 * Allocates a new buffer of {size} octets, leaving memory not initialized, so the contents
182 * of the newly created Buffer are unknown and may contain sensitive data.
183 *
184 * @param size count of octets to allocate
185 */
186 static allocUnsafe(size: number): Buffer;
187 /**
188 * Allocates a new non-pooled buffer of {size} octets, leaving memory not initialized, so the contents
189 * of the newly created Buffer are unknown and may contain sensitive data.
190 *
191 * @param size count of octets to allocate
192 */
193 static allocUnsafeSlow(size: number): Buffer;
194}