1 | /**
|
2 | * `Buffer` objects are used to represent a fixed-length sequence of bytes. Many
|
3 | * Node.js APIs support `Buffer`s.
|
4 | *
|
5 | * The `Buffer` class is a subclass of JavaScript's [`Uint8Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array) class and
|
6 | * extends it with methods that cover additional use cases. Node.js APIs accept
|
7 | * plain [`Uint8Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array) s wherever `Buffer`s are supported as well.
|
8 | *
|
9 | * While the `Buffer` class is available within the global scope, it is still
|
10 | * recommended to explicitly reference it via an import or require statement.
|
11 | *
|
12 | * ```js
|
13 | * import { Buffer } from 'buffer';
|
14 | *
|
15 | * // Creates a zero-filled Buffer of length 10.
|
16 | * const buf1 = Buffer.alloc(10);
|
17 | *
|
18 | * // Creates a Buffer of length 10,
|
19 | * // filled with bytes which all have the value `1`.
|
20 | * const buf2 = Buffer.alloc(10, 1);
|
21 | *
|
22 | * // Creates an uninitialized buffer of length 10.
|
23 | * // This is faster than calling Buffer.alloc() but the returned
|
24 | * // Buffer instance might contain old data that needs to be
|
25 | * // overwritten using fill(), write(), or other functions that fill the Buffer's
|
26 | * // contents.
|
27 | * const buf3 = Buffer.allocUnsafe(10);
|
28 | *
|
29 | * // Creates a Buffer containing the bytes [1, 2, 3].
|
30 | * const buf4 = Buffer.from([1, 2, 3]);
|
31 | *
|
32 | * // Creates a Buffer containing the bytes [1, 1, 1, 1] – the entries
|
33 | * // are all truncated using `(value & 255)` to fit into the range 0–255.
|
34 | * const buf5 = Buffer.from([257, 257.5, -255, '1']);
|
35 | *
|
36 | * // Creates a Buffer containing the UTF-8-encoded bytes for the string 'tést':
|
37 | * // [0x74, 0xc3, 0xa9, 0x73, 0x74] (in hexadecimal notation)
|
38 | * // [116, 195, 169, 115, 116] (in decimal notation)
|
39 | * const buf6 = Buffer.from('tést');
|
40 | *
|
41 | * // Creates a Buffer containing the Latin-1 bytes [0x74, 0xe9, 0x73, 0x74].
|
42 | * const buf7 = Buffer.from('tést', 'latin1');
|
43 | * ```
|
44 | * @see [source](https://github.com/nodejs/node/blob/v17.0.0/lib/buffer.js)
|
45 | */
|
46 | declare module 'buffer' {
|
47 | import { BinaryLike } from 'node:crypto';
|
48 | export const INSPECT_MAX_BYTES: number;
|
49 | export const kMaxLength: number;
|
50 | export const kStringMaxLength: number;
|
51 | export const constants: {
|
52 | MAX_LENGTH: number;
|
53 | MAX_STRING_LENGTH: number;
|
54 | };
|
55 | export type TranscodeEncoding = 'ascii' | 'utf8' | 'utf16le' | 'ucs2' | 'latin1' | 'binary';
|
56 | /**
|
57 | * Re-encodes the given `Buffer` or `Uint8Array` instance from one character
|
58 | * encoding to another. Returns a new `Buffer` instance.
|
59 | *
|
60 | * Throws if the `fromEnc` or `toEnc` specify invalid character encodings or if
|
61 | * conversion from `fromEnc` to `toEnc` is not permitted.
|
62 | *
|
63 | * Encodings supported by `buffer.transcode()` are: `'ascii'`, `'utf8'`,`'utf16le'`, `'ucs2'`, `'latin1'`, and `'binary'`.
|
64 | *
|
65 | * The transcoding process will use substitution characters if a given byte
|
66 | * sequence cannot be adequately represented in the target encoding. For instance:
|
67 | *
|
68 | * ```js
|
69 | * import { Buffer, transcode } from 'buffer';
|
70 | *
|
71 | * const newBuf = transcode(Buffer.from('€'), 'utf8', 'ascii');
|
72 | * console.log(newBuf.toString('ascii'));
|
73 | * // Prints: '?'
|
74 | * ```
|
75 | *
|
76 | * Because the Euro (`€`) sign is not representable in US-ASCII, it is replaced
|
77 | * with `?` in the transcoded `Buffer`.
|
78 | * @since v7.1.0
|
79 | * @param source A `Buffer` or `Uint8Array` instance.
|
80 | * @param fromEnc The current encoding.
|
81 | * @param toEnc To target encoding.
|
82 | */
|
83 | export function transcode(source: Uint8Array, fromEnc: TranscodeEncoding, toEnc: TranscodeEncoding): Buffer;
|
84 | export const SlowBuffer: {
|
85 | /** @deprecated since v6.0.0, use `Buffer.allocUnsafeSlow()` */
|
86 | new (size: number): Buffer;
|
87 | prototype: Buffer;
|
88 | };
|
89 | /**
|
90 | * Resolves a `'blob:nodedata:...'` an associated `Blob` object registered using
|
91 | * a prior call to `URL.createObjectURL()`.
|
92 | * @since v16.7.0
|
93 | * @experimental
|
94 | * @param id A `'blob:nodedata:...` URL string returned by a prior call to `URL.createObjectURL()`.
|
95 | */
|
96 | export function resolveObjectURL(id: string): Blob | undefined;
|
97 | export { Buffer };
|
98 | /**
|
99 | * @experimental
|
100 | */
|
101 | export interface BlobOptions {
|
102 | /**
|
103 | * @default 'utf8'
|
104 | */
|
105 | encoding?: BufferEncoding | undefined;
|
106 | /**
|
107 | * The Blob content-type. The intent is for `type` to convey
|
108 | * the MIME media type of the data, however no validation of the type format
|
109 | * is performed.
|
110 | */
|
111 | type?: string | undefined;
|
112 | }
|
113 | /**
|
114 | * A [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob) encapsulates immutable, raw data that can be safely shared across
|
115 | * multiple worker threads.
|
116 | * @since v15.7.0, v14.18.0
|
117 | * @experimental
|
118 | */
|
119 | export class Blob {
|
120 | /**
|
121 | * The total size of the `Blob` in bytes.
|
122 | * @since v15.7.0, v14.18.0
|
123 | */
|
124 | readonly size: number;
|
125 | /**
|
126 | * The content-type of the `Blob`.
|
127 | * @since v15.7.0, v14.18.0
|
128 | */
|
129 | readonly type: string;
|
130 | /**
|
131 | * Creates a new `Blob` object containing a concatenation of the given sources.
|
132 | *
|
133 | * {ArrayBuffer}, {TypedArray}, {DataView}, and {Buffer} sources are copied into
|
134 | * the 'Blob' and can therefore be safely modified after the 'Blob' is created.
|
135 | *
|
136 | * String sources are also copied into the `Blob`.
|
137 | */
|
138 | constructor(sources: Array<BinaryLike | Blob>, options?: BlobOptions);
|
139 | /**
|
140 | * Returns a promise that fulfills with an [ArrayBuffer](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer) containing a copy of
|
141 | * the `Blob` data.
|
142 | * v15.7.0, v14.18.0
|
143 | */
|
144 | arrayBuffer(): Promise<ArrayBuffer>;
|
145 | /**
|
146 | * Creates and returns a new `Blob` containing a subset of this `Blob` objects
|
147 | * data. The original `Blob` is not altered.
|
148 | * @since v15.7.0, v14.18.0
|
149 | * @param start The starting index.
|
150 | * @param end The ending index.
|
151 | * @param type The content-type for the new `Blob`
|
152 | */
|
153 | slice(start?: number, end?: number, type?: string): Blob;
|
154 | /**
|
155 | * Returns a promise that fulfills with the contents of the `Blob` decoded as a
|
156 | * UTF-8 string.
|
157 | * @since v15.7.0, v14.18.0
|
158 | */
|
159 | text(): Promise<string>;
|
160 | /**
|
161 | * Returns a new `ReadableStream` that allows the content of the `Blob` to be read.
|
162 | * @since v16.7.0
|
163 | */
|
164 | stream(): unknown; // pending web streams types
|
165 | }
|
166 | export import atob = globalThis.atob;
|
167 | export import btoa = globalThis.btoa;
|
168 | global {
|
169 | // Buffer class
|
170 | type BufferEncoding = 'ascii' | 'utf8' | 'utf-8' | 'utf16le' | 'ucs2' | 'ucs-2' | 'base64' | 'base64url' | 'latin1' | 'binary' | 'hex';
|
171 | type WithImplicitCoercion<T> =
|
172 | | T
|
173 | | {
|
174 | valueOf(): T;
|
175 | };
|
176 | /**
|
177 | * Raw data is stored in instances of the Buffer class.
|
178 | * A Buffer is similar to an array of integers but corresponds to a raw memory allocation outside the V8 heap. A Buffer cannot be resized.
|
179 | * Valid string encodings: 'ascii'|'utf8'|'utf16le'|'ucs2'(alias of 'utf16le')|'base64'|'base64url'|'binary'(deprecated)|'hex'
|
180 | */
|
181 | interface BufferConstructor {
|
182 | /**
|
183 | * Allocates a new buffer containing the given {str}.
|
184 | *
|
185 | * @param str String to store in buffer.
|
186 | * @param encoding encoding to use, optional. Default is 'utf8'
|
187 | * @deprecated since v10.0.0 - Use `Buffer.from(string[, encoding])` instead.
|
188 | */
|
189 | new (str: string, encoding?: BufferEncoding): Buffer;
|
190 | /**
|
191 | * Allocates a new buffer of {size} octets.
|
192 | *
|
193 | * @param size count of octets to allocate.
|
194 | * @deprecated since v10.0.0 - Use `Buffer.alloc()` instead (also see `Buffer.allocUnsafe()`).
|
195 | */
|
196 | new (size: number): Buffer;
|
197 | /**
|
198 | * Allocates a new buffer containing the given {array} of octets.
|
199 | *
|
200 | * @param array The octets to store.
|
201 | * @deprecated since v10.0.0 - Use `Buffer.from(array)` instead.
|
202 | */
|
203 | new (array: Uint8Array): Buffer;
|
204 | /**
|
205 | * Produces a Buffer backed by the same allocated memory as
|
206 | * the given {ArrayBuffer}/{SharedArrayBuffer}.
|
207 | *
|
208 | *
|
209 | * @param arrayBuffer The ArrayBuffer with which to share memory.
|
210 | * @deprecated since v10.0.0 - Use `Buffer.from(arrayBuffer[, byteOffset[, length]])` instead.
|
211 | */
|
212 | new (arrayBuffer: ArrayBuffer | SharedArrayBuffer): Buffer;
|
213 | /**
|
214 | * Allocates a new buffer containing the given {array} of octets.
|
215 | *
|
216 | * @param array The octets to store.
|
217 | * @deprecated since v10.0.0 - Use `Buffer.from(array)` instead.
|
218 | */
|
219 | new (array: ReadonlyArray<any>): Buffer;
|
220 | /**
|
221 | * Copies the passed {buffer} data onto a new {Buffer} instance.
|
222 | *
|
223 | * @param buffer The buffer to copy.
|
224 | * @deprecated since v10.0.0 - Use `Buffer.from(buffer)` instead.
|
225 | */
|
226 | new (buffer: Buffer): Buffer;
|
227 | /**
|
228 | * Allocates a new `Buffer` using an `array` of bytes in the range `0` – `255`.
|
229 | * Array entries outside that range will be truncated to fit into it.
|
230 | *
|
231 | * ```js
|
232 | * import { Buffer } from 'buffer';
|
233 | *
|
234 | * // Creates a new Buffer containing the UTF-8 bytes of the string 'buffer'.
|
235 | * const buf = Buffer.from([0x62, 0x75, 0x66, 0x66, 0x65, 0x72]);
|
236 | * ```
|
237 | *
|
238 | * A `TypeError` will be thrown if `array` is not an `Array` or another type
|
239 | * appropriate for `Buffer.from()` variants.
|
240 | *
|
241 | * `Buffer.from(array)` and `Buffer.from(string)` may also use the internal`Buffer` pool like `Buffer.allocUnsafe()` does.
|
242 | * @since v5.10.0
|
243 | */
|
244 | from(arrayBuffer: WithImplicitCoercion<ArrayBuffer | SharedArrayBuffer>, byteOffset?: number, length?: number): Buffer;
|
245 | /**
|
246 | * Creates a new Buffer using the passed {data}
|
247 | * @param data data to create a new Buffer
|
248 | */
|
249 | from(data: Uint8Array | ReadonlyArray<number>): Buffer;
|
250 | from(data: WithImplicitCoercion<Uint8Array | ReadonlyArray<number> | string>): Buffer;
|
251 | /**
|
252 | * Creates a new Buffer containing the given JavaScript string {str}.
|
253 | * If provided, the {encoding} parameter identifies the character encoding.
|
254 | * If not provided, {encoding} defaults to 'utf8'.
|
255 | */
|
256 | from(
|
257 | str:
|
258 | | WithImplicitCoercion<string>
|
259 | | {
|
260 | [Symbol.toPrimitive](hint: 'string'): string;
|
261 | },
|
262 | encoding?: BufferEncoding
|
263 | ): Buffer;
|
264 | /**
|
265 | * Creates a new Buffer using the passed {data}
|
266 | * @param values to create a new Buffer
|
267 | */
|
268 | of(...items: number[]): Buffer;
|
269 | /**
|
270 | * Returns `true` if `obj` is a `Buffer`, `false` otherwise.
|
271 | *
|
272 | * ```js
|
273 | * import { Buffer } from 'buffer';
|
274 | *
|
275 | * Buffer.isBuffer(Buffer.alloc(10)); // true
|
276 | * Buffer.isBuffer(Buffer.from('foo')); // true
|
277 | * Buffer.isBuffer('a string'); // false
|
278 | * Buffer.isBuffer([]); // false
|
279 | * Buffer.isBuffer(new Uint8Array(1024)); // false
|
280 | * ```
|
281 | * @since v0.1.101
|
282 | */
|
283 | isBuffer(obj: any): obj is Buffer;
|
284 | /**
|
285 | * Returns `true` if `encoding` is the name of a supported character encoding,
|
286 | * or `false` otherwise.
|
287 | *
|
288 | * ```js
|
289 | * import { Buffer } from 'buffer';
|
290 | *
|
291 | * console.log(Buffer.isEncoding('utf8'));
|
292 | * // Prints: true
|
293 | *
|
294 | * console.log(Buffer.isEncoding('hex'));
|
295 | * // Prints: true
|
296 | *
|
297 | * console.log(Buffer.isEncoding('utf/8'));
|
298 | * // Prints: false
|
299 | *
|
300 | * console.log(Buffer.isEncoding(''));
|
301 | * // Prints: false
|
302 | * ```
|
303 | * @since v0.9.1
|
304 | * @param encoding A character encoding name to check.
|
305 | */
|
306 | isEncoding(encoding: string): encoding is BufferEncoding;
|
307 | /**
|
308 | * Returns the byte length of a string when encoded using `encoding`.
|
309 | * This is not the same as [`String.prototype.length`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/length), which does not account
|
310 | * for the encoding that is used to convert the string into bytes.
|
311 | *
|
312 | * For `'base64'`, `'base64url'`, and `'hex'`, this function assumes valid input.
|
313 | * For strings that contain non-base64/hex-encoded data (e.g. whitespace), the
|
314 | * return value might be greater than the length of a `Buffer` created from the
|
315 | * string.
|
316 | *
|
317 | * ```js
|
318 | * import { Buffer } from 'buffer';
|
319 | *
|
320 | * const str = '\u00bd + \u00bc = \u00be';
|
321 | *
|
322 | * console.log(`${str}: ${str.length} characters, ` +
|
323 | * `${Buffer.byteLength(str, 'utf8')} bytes`);
|
324 | * // Prints: ½ + ¼ = ¾: 9 characters, 12 bytes
|
325 | * ```
|
326 | *
|
327 | * When `string` is a
|
328 | * `Buffer`/[`DataView`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView)/[`TypedArray`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/-
|
329 | * Reference/Global_Objects/TypedArray)/[`ArrayBuffer`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer)/[`SharedArrayBuffer`](https://develop-
|
330 | * er.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer), the byte length as reported by `.byteLength`is returned.
|
331 | * @since v0.1.90
|
332 | * @param string A value to calculate the length of.
|
333 | * @param [encoding='utf8'] If `string` is a string, this is its encoding.
|
334 | * @return The number of bytes contained within `string`.
|
335 | */
|
336 | byteLength(string: string | NodeJS.ArrayBufferView | ArrayBuffer | SharedArrayBuffer, encoding?: BufferEncoding): number;
|
337 | /**
|
338 | * Returns a new `Buffer` which is the result of concatenating all the `Buffer`instances in the `list` together.
|
339 | *
|
340 | * If the list has no items, or if the `totalLength` is 0, then a new zero-length`Buffer` is returned.
|
341 | *
|
342 | * If `totalLength` is not provided, it is calculated from the `Buffer` instances
|
343 | * in `list` by adding their lengths.
|
344 | *
|
345 | * If `totalLength` is provided, it is coerced to an unsigned integer. If the
|
346 | * combined length of the `Buffer`s in `list` exceeds `totalLength`, the result is
|
347 | * truncated to `totalLength`.
|
348 | *
|
349 | * ```js
|
350 | * import { Buffer } from 'buffer';
|
351 | *
|
352 | * // Create a single `Buffer` from a list of three `Buffer` instances.
|
353 | *
|
354 | * const buf1 = Buffer.alloc(10);
|
355 | * const buf2 = Buffer.alloc(14);
|
356 | * const buf3 = Buffer.alloc(18);
|
357 | * const totalLength = buf1.length + buf2.length + buf3.length;
|
358 | *
|
359 | * console.log(totalLength);
|
360 | * // Prints: 42
|
361 | *
|
362 | * const bufA = Buffer.concat([buf1, buf2, buf3], totalLength);
|
363 | *
|
364 | * console.log(bufA);
|
365 | * // Prints: <Buffer 00 00 00 00 ...>
|
366 | * console.log(bufA.length);
|
367 | * // Prints: 42
|
368 | * ```
|
369 | *
|
370 | * `Buffer.concat()` may also use the internal `Buffer` pool like `Buffer.allocUnsafe()` does.
|
371 | * @since v0.7.11
|
372 | * @param list List of `Buffer` or {@link Uint8Array} instances to concatenate.
|
373 | * @param totalLength Total length of the `Buffer` instances in `list` when concatenated.
|
374 | */
|
375 | concat(list: ReadonlyArray<Uint8Array>, totalLength?: number): Buffer;
|
376 | /**
|
377 | * Compares `buf1` to `buf2`, typically for the purpose of sorting arrays of`Buffer` instances. This is equivalent to calling `buf1.compare(buf2)`.
|
378 | *
|
379 | * ```js
|
380 | * import { Buffer } from 'buffer';
|
381 | *
|
382 | * const buf1 = Buffer.from('1234');
|
383 | * const buf2 = Buffer.from('0123');
|
384 | * const arr = [buf1, buf2];
|
385 | *
|
386 | * console.log(arr.sort(Buffer.compare));
|
387 | * // Prints: [ <Buffer 30 31 32 33>, <Buffer 31 32 33 34> ]
|
388 | * // (This result is equal to: [buf2, buf1].)
|
389 | * ```
|
390 | * @since v0.11.13
|
391 | * @return Either `-1`, `0`, or `1`, depending on the result of the comparison. See `compare` for details.
|
392 | */
|
393 | compare(buf1: Uint8Array, buf2: Uint8Array): -1 | 0 | 1;
|
394 | /**
|
395 | * Allocates a new `Buffer` of `size` bytes. If `fill` is `undefined`, the`Buffer` will be zero-filled.
|
396 | *
|
397 | * ```js
|
398 | * import { Buffer } from 'buffer';
|
399 | *
|
400 | * const buf = Buffer.alloc(5);
|
401 | *
|
402 | * console.log(buf);
|
403 | * // Prints: <Buffer 00 00 00 00 00>
|
404 | * ```
|
405 | *
|
406 | * If `size` is larger than {@link constants.MAX_LENGTH} or smaller than 0, `ERR_INVALID_ARG_VALUE` is thrown.
|
407 | *
|
408 | * If `fill` is specified, the allocated `Buffer` will be initialized by calling `buf.fill(fill)`.
|
409 | *
|
410 | * ```js
|
411 | * import { Buffer } from 'buffer';
|
412 | *
|
413 | * const buf = Buffer.alloc(5, 'a');
|
414 | *
|
415 | * console.log(buf);
|
416 | * // Prints: <Buffer 61 61 61 61 61>
|
417 | * ```
|
418 | *
|
419 | * If both `fill` and `encoding` are specified, the allocated `Buffer` will be
|
420 | * initialized by calling `buf.fill(fill, encoding)`.
|
421 | *
|
422 | * ```js
|
423 | * import { Buffer } from 'buffer';
|
424 | *
|
425 | * const buf = Buffer.alloc(11, 'aGVsbG8gd29ybGQ=', 'base64');
|
426 | *
|
427 | * console.log(buf);
|
428 | * // Prints: <Buffer 68 65 6c 6c 6f 20 77 6f 72 6c 64>
|
429 | * ```
|
430 | *
|
431 | * Calling `Buffer.alloc()` can be measurably slower than the alternative `Buffer.allocUnsafe()` but ensures that the newly created `Buffer` instance
|
432 | * contents will never contain sensitive data from previous allocations, including
|
433 | * data that might not have been allocated for `Buffer`s.
|
434 | *
|
435 | * A `TypeError` will be thrown if `size` is not a number.
|
436 | * @since v5.10.0
|
437 | * @param size The desired length of the new `Buffer`.
|
438 | * @param [fill=0] A value to pre-fill the new `Buffer` with.
|
439 | * @param [encoding='utf8'] If `fill` is a string, this is its encoding.
|
440 | */
|
441 | alloc(size: number, fill?: string | Buffer | number, encoding?: BufferEncoding): Buffer;
|
442 | /**
|
443 | * Allocates a new `Buffer` of `size` bytes. If `size` is larger than {@link constants.MAX_LENGTH} or smaller than 0, `ERR_INVALID_ARG_VALUE` is thrown.
|
444 | *
|
445 | * The underlying memory for `Buffer` instances created in this way is _not_
|
446 | * _initialized_. The contents of the newly created `Buffer` are unknown and _may contain sensitive data_. Use `Buffer.alloc()` instead to initialize`Buffer` instances with zeroes.
|
447 | *
|
448 | * ```js
|
449 | * import { Buffer } from 'buffer';
|
450 | *
|
451 | * const buf = Buffer.allocUnsafe(10);
|
452 | *
|
453 | * console.log(buf);
|
454 | * // Prints (contents may vary): <Buffer a0 8b 28 3f 01 00 00 00 50 32>
|
455 | *
|
456 | * buf.fill(0);
|
457 | *
|
458 | * console.log(buf);
|
459 | * // Prints: <Buffer 00 00 00 00 00 00 00 00 00 00>
|
460 | * ```
|
461 | *
|
462 | * A `TypeError` will be thrown if `size` is not a number.
|
463 | *
|
464 | * The `Buffer` module pre-allocates an internal `Buffer` instance of
|
465 | * size `Buffer.poolSize` that is used as a pool for the fast allocation of new`Buffer` instances created using `Buffer.allocUnsafe()`,`Buffer.from(array)`, `Buffer.concat()`, and the
|
466 | * deprecated`new Buffer(size)` constructor only when `size` is less than or equal
|
467 | * to `Buffer.poolSize >> 1` (floor of `Buffer.poolSize` divided by two).
|
468 | *
|
469 | * Use of this pre-allocated internal memory pool is a key difference between
|
470 | * calling `Buffer.alloc(size, fill)` vs. `Buffer.allocUnsafe(size).fill(fill)`.
|
471 | * Specifically, `Buffer.alloc(size, fill)` will _never_ use the internal `Buffer`pool, while `Buffer.allocUnsafe(size).fill(fill)`_will_ use the internal`Buffer` pool if `size` is less
|
472 | * than or equal to half `Buffer.poolSize`. The
|
473 | * difference is subtle but can be important when an application requires the
|
474 | * additional performance that `Buffer.allocUnsafe()` provides.
|
475 | * @since v5.10.0
|
476 | * @param size The desired length of the new `Buffer`.
|
477 | */
|
478 | allocUnsafe(size: number): Buffer;
|
479 | /**
|
480 | * Allocates a new `Buffer` of `size` bytes. If `size` is larger than {@link constants.MAX_LENGTH} or smaller than 0, `ERR_INVALID_ARG_VALUE` is thrown. A zero-length `Buffer` is created
|
481 | * if `size` is 0.
|
482 | *
|
483 | * The underlying memory for `Buffer` instances created in this way is _not_
|
484 | * _initialized_. The contents of the newly created `Buffer` are unknown and_may contain sensitive data_. Use `buf.fill(0)` to initialize
|
485 | * such `Buffer` instances with zeroes.
|
486 | *
|
487 | * When using `Buffer.allocUnsafe()` to allocate new `Buffer` instances,
|
488 | * allocations under 4 KB are sliced from a single pre-allocated `Buffer`. This
|
489 | * allows applications to avoid the garbage collection overhead of creating many
|
490 | * individually allocated `Buffer` instances. This approach improves both
|
491 | * performance and memory usage by eliminating the need to track and clean up as
|
492 | * many individual `ArrayBuffer` objects.
|
493 | *
|
494 | * However, in the case where a developer may need to retain a small chunk of
|
495 | * memory from a pool for an indeterminate amount of time, it may be appropriate
|
496 | * to create an un-pooled `Buffer` instance using `Buffer.allocUnsafeSlow()` and
|
497 | * then copying out the relevant bits.
|
498 | *
|
499 | * ```js
|
500 | * import { Buffer } from 'buffer';
|
501 | *
|
502 | * // Need to keep around a few small chunks of memory.
|
503 | * const store = [];
|
504 | *
|
505 | * socket.on('readable', () => {
|
506 | * let data;
|
507 | * while (null !== (data = readable.read())) {
|
508 | * // Allocate for retained data.
|
509 | * const sb = Buffer.allocUnsafeSlow(10);
|
510 | *
|
511 | * // Copy the data into the new allocation.
|
512 | * data.copy(sb, 0, 0, 10);
|
513 | *
|
514 | * store.push(sb);
|
515 | * }
|
516 | * });
|
517 | * ```
|
518 | *
|
519 | * A `TypeError` will be thrown if `size` is not a number.
|
520 | * @since v5.12.0
|
521 | * @param size The desired length of the new `Buffer`.
|
522 | */
|
523 | allocUnsafeSlow(size: number): Buffer;
|
524 | /**
|
525 | * This is the size (in bytes) of pre-allocated internal `Buffer` instances used
|
526 | * for pooling. This value may be modified.
|
527 | * @since v0.11.3
|
528 | */
|
529 | poolSize: number;
|
530 | }
|
531 | interface Buffer extends Uint8Array {
|
532 | /**
|
533 | * Writes `string` to `buf` at `offset` according to the character encoding in`encoding`. The `length` parameter is the number of bytes to write. If `buf` did
|
534 | * not contain enough space to fit the entire string, only part of `string` will be
|
535 | * written. However, partially encoded characters will not be written.
|
536 | *
|
537 | * ```js
|
538 | * import { Buffer } from 'buffer';
|
539 | *
|
540 | * const buf = Buffer.alloc(256);
|
541 | *
|
542 | * const len = buf.write('\u00bd + \u00bc = \u00be', 0);
|
543 | *
|
544 | * console.log(`${len} bytes: ${buf.toString('utf8', 0, len)}`);
|
545 | * // Prints: 12 bytes: ½ + ¼ = ¾
|
546 | *
|
547 | * const buffer = Buffer.alloc(10);
|
548 | *
|
549 | * const length = buffer.write('abcd', 8);
|
550 | *
|
551 | * console.log(`${length} bytes: ${buffer.toString('utf8', 8, 10)}`);
|
552 | * // Prints: 2 bytes : ab
|
553 | * ```
|
554 | * @since v0.1.90
|
555 | * @param string String to write to `buf`.
|
556 | * @param [offset=0] Number of bytes to skip before starting to write `string`.
|
557 | * @param [length=buf.length - offset] Maximum number of bytes to write (written bytes will not exceed `buf.length - offset`).
|
558 | * @param [encoding='utf8'] The character encoding of `string`.
|
559 | * @return Number of bytes written.
|
560 | */
|
561 | write(string: string, encoding?: BufferEncoding): number;
|
562 | write(string: string, offset: number, encoding?: BufferEncoding): number;
|
563 | write(string: string, offset: number, length: number, encoding?: BufferEncoding): number;
|
564 | /**
|
565 | * Decodes `buf` to a string according to the specified character encoding in`encoding`. `start` and `end` may be passed to decode only a subset of `buf`.
|
566 | *
|
567 | * If `encoding` is `'utf8'` and a byte sequence in the input is not valid UTF-8,
|
568 | * then each invalid byte is replaced with the replacement character `U+FFFD`.
|
569 | *
|
570 | * The maximum length of a string instance (in UTF-16 code units) is available
|
571 | * as {@link constants.MAX_STRING_LENGTH}.
|
572 | *
|
573 | * ```js
|
574 | * import { Buffer } from 'buffer';
|
575 | *
|
576 | * const buf1 = Buffer.allocUnsafe(26);
|
577 | *
|
578 | * for (let i = 0; i < 26; i++) {
|
579 | * // 97 is the decimal ASCII value for 'a'.
|
580 | * buf1[i] = i + 97;
|
581 | * }
|
582 | *
|
583 | * console.log(buf1.toString('utf8'));
|
584 | * // Prints: abcdefghijklmnopqrstuvwxyz
|
585 | * console.log(buf1.toString('utf8', 0, 5));
|
586 | * // Prints: abcde
|
587 | *
|
588 | * const buf2 = Buffer.from('tést');
|
589 | *
|
590 | * console.log(buf2.toString('hex'));
|
591 | * // Prints: 74c3a97374
|
592 | * console.log(buf2.toString('utf8', 0, 3));
|
593 | * // Prints: té
|
594 | * console.log(buf2.toString(undefined, 0, 3));
|
595 | * // Prints: té
|
596 | * ```
|
597 | * @since v0.1.90
|
598 | * @param [encoding='utf8'] The character encoding to use.
|
599 | * @param [start=0] The byte offset to start decoding at.
|
600 | * @param [end=buf.length] The byte offset to stop decoding at (not inclusive).
|
601 | */
|
602 | toString(encoding?: BufferEncoding, start?: number, end?: number): string;
|
603 | /**
|
604 | * Returns a JSON representation of `buf`. [`JSON.stringify()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify) implicitly calls
|
605 | * this function when stringifying a `Buffer` instance.
|
606 | *
|
607 | * `Buffer.from()` accepts objects in the format returned from this method.
|
608 | * In particular, `Buffer.from(buf.toJSON())` works like `Buffer.from(buf)`.
|
609 | *
|
610 | * ```js
|
611 | * import { Buffer } from 'buffer';
|
612 | *
|
613 | * const buf = Buffer.from([0x1, 0x2, 0x3, 0x4, 0x5]);
|
614 | * const json = JSON.stringify(buf);
|
615 | *
|
616 | * console.log(json);
|
617 | * // Prints: {"type":"Buffer","data":[1,2,3,4,5]}
|
618 | *
|
619 | * const copy = JSON.parse(json, (key, value) => {
|
620 | * return value && value.type === 'Buffer' ?
|
621 | * Buffer.from(value) :
|
622 | * value;
|
623 | * });
|
624 | *
|
625 | * console.log(copy);
|
626 | * // Prints: <Buffer 01 02 03 04 05>
|
627 | * ```
|
628 | * @since v0.9.2
|
629 | */
|
630 | toJSON(): {
|
631 | type: 'Buffer';
|
632 | data: number[];
|
633 | };
|
634 | /**
|
635 | * Returns `true` if both `buf` and `otherBuffer` have exactly the same bytes,`false` otherwise. Equivalent to `buf.compare(otherBuffer) === 0`.
|
636 | *
|
637 | * ```js
|
638 | * import { Buffer } from 'buffer';
|
639 | *
|
640 | * const buf1 = Buffer.from('ABC');
|
641 | * const buf2 = Buffer.from('414243', 'hex');
|
642 | * const buf3 = Buffer.from('ABCD');
|
643 | *
|
644 | * console.log(buf1.equals(buf2));
|
645 | * // Prints: true
|
646 | * console.log(buf1.equals(buf3));
|
647 | * // Prints: false
|
648 | * ```
|
649 | * @since v0.11.13
|
650 | * @param otherBuffer A `Buffer` or {@link Uint8Array} with which to compare `buf`.
|
651 | */
|
652 | equals(otherBuffer: Uint8Array): boolean;
|
653 | /**
|
654 | * Compares `buf` with `target` and returns a number indicating whether `buf`comes before, after, or is the same as `target` in sort order.
|
655 | * Comparison is based on the actual sequence of bytes in each `Buffer`.
|
656 | *
|
657 | * * `0` is returned if `target` is the same as `buf`
|
658 | * * `1` is returned if `target` should come _before_`buf` when sorted.
|
659 | * * `-1` is returned if `target` should come _after_`buf` when sorted.
|
660 | *
|
661 | * ```js
|
662 | * import { Buffer } from 'buffer';
|
663 | *
|
664 | * const buf1 = Buffer.from('ABC');
|
665 | * const buf2 = Buffer.from('BCD');
|
666 | * const buf3 = Buffer.from('ABCD');
|
667 | *
|
668 | * console.log(buf1.compare(buf1));
|
669 | * // Prints: 0
|
670 | * console.log(buf1.compare(buf2));
|
671 | * // Prints: -1
|
672 | * console.log(buf1.compare(buf3));
|
673 | * // Prints: -1
|
674 | * console.log(buf2.compare(buf1));
|
675 | * // Prints: 1
|
676 | * console.log(buf2.compare(buf3));
|
677 | * // Prints: 1
|
678 | * console.log([buf1, buf2, buf3].sort(Buffer.compare));
|
679 | * // Prints: [ <Buffer 41 42 43>, <Buffer 41 42 43 44>, <Buffer 42 43 44> ]
|
680 | * // (This result is equal to: [buf1, buf3, buf2].)
|
681 | * ```
|
682 | *
|
683 | * The optional `targetStart`, `targetEnd`, `sourceStart`, and `sourceEnd`arguments can be used to limit the comparison to specific ranges within `target`and `buf` respectively.
|
684 | *
|
685 | * ```js
|
686 | * import { Buffer } from 'buffer';
|
687 | *
|
688 | * const buf1 = Buffer.from([1, 2, 3, 4, 5, 6, 7, 8, 9]);
|
689 | * const buf2 = Buffer.from([5, 6, 7, 8, 9, 1, 2, 3, 4]);
|
690 | *
|
691 | * console.log(buf1.compare(buf2, 5, 9, 0, 4));
|
692 | * // Prints: 0
|
693 | * console.log(buf1.compare(buf2, 0, 6, 4));
|
694 | * // Prints: -1
|
695 | * console.log(buf1.compare(buf2, 5, 6, 5));
|
696 | * // Prints: 1
|
697 | * ```
|
698 | *
|
699 | * `ERR_OUT_OF_RANGE` is thrown if `targetStart < 0`, `sourceStart < 0`,`targetEnd > target.byteLength`, or `sourceEnd > source.byteLength`.
|
700 | * @since v0.11.13
|
701 | * @param target A `Buffer` or {@link Uint8Array} with which to compare `buf`.
|
702 | * @param [targetStart=0] The offset within `target` at which to begin comparison.
|
703 | * @param [targetEnd=target.length] The offset within `target` at which to end comparison (not inclusive).
|
704 | * @param [sourceStart=0] The offset within `buf` at which to begin comparison.
|
705 | * @param [sourceEnd=buf.length] The offset within `buf` at which to end comparison (not inclusive).
|
706 | */
|
707 | compare(target: Uint8Array, targetStart?: number, targetEnd?: number, sourceStart?: number, sourceEnd?: number): -1 | 0 | 1;
|
708 | /**
|
709 | * Copies data from a region of `buf` to a region in `target`, even if the `target`memory region overlaps with `buf`.
|
710 | *
|
711 | * [`TypedArray.prototype.set()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/set) performs the same operation, and is available
|
712 | * for all TypedArrays, including Node.js `Buffer`s, although it takes
|
713 | * different function arguments.
|
714 | *
|
715 | * ```js
|
716 | * import { Buffer } from 'buffer';
|
717 | *
|
718 | * // Create two `Buffer` instances.
|
719 | * const buf1 = Buffer.allocUnsafe(26);
|
720 | * const buf2 = Buffer.allocUnsafe(26).fill('!');
|
721 | *
|
722 | * for (let i = 0; i < 26; i++) {
|
723 | * // 97 is the decimal ASCII value for 'a'.
|
724 | * buf1[i] = i + 97;
|
725 | * }
|
726 | *
|
727 | * // Copy `buf1` bytes 16 through 19 into `buf2` starting at byte 8 of `buf2`.
|
728 | * buf1.copy(buf2, 8, 16, 20);
|
729 | * // This is equivalent to:
|
730 | * // buf2.set(buf1.subarray(16, 20), 8);
|
731 | *
|
732 | * console.log(buf2.toString('ascii', 0, 25));
|
733 | * // Prints: !!!!!!!!qrst!!!!!!!!!!!!!
|
734 | * ```
|
735 | *
|
736 | * ```js
|
737 | * import { Buffer } from 'buffer';
|
738 | *
|
739 | * // Create a `Buffer` and copy data from one region to an overlapping region
|
740 | * // within the same `Buffer`.
|
741 | *
|
742 | * const buf = Buffer.allocUnsafe(26);
|
743 | *
|
744 | * for (let i = 0; i < 26; i++) {
|
745 | * // 97 is the decimal ASCII value for 'a'.
|
746 | * buf[i] = i + 97;
|
747 | * }
|
748 | *
|
749 | * buf.copy(buf, 0, 4, 10);
|
750 | *
|
751 | * console.log(buf.toString());
|
752 | * // Prints: efghijghijklmnopqrstuvwxyz
|
753 | * ```
|
754 | * @since v0.1.90
|
755 | * @param target A `Buffer` or {@link Uint8Array} to copy into.
|
756 | * @param [targetStart=0] The offset within `target` at which to begin writing.
|
757 | * @param [sourceStart=0] The offset within `buf` from which to begin copying.
|
758 | * @param [sourceEnd=buf.length] The offset within `buf` at which to stop copying (not inclusive).
|
759 | * @return The number of bytes copied.
|
760 | */
|
761 | copy(target: Uint8Array, targetStart?: number, sourceStart?: number, sourceEnd?: number): number;
|
762 | /**
|
763 | * Returns a new `Buffer` that references the same memory as the original, but
|
764 | * offset and cropped by the `start` and `end` indices.
|
765 | *
|
766 | * This is the same behavior as `buf.subarray()`.
|
767 | *
|
768 | * This method is not compatible with the `Uint8Array.prototype.slice()`,
|
769 | * which is a superclass of `Buffer`. To copy the slice, use`Uint8Array.prototype.slice()`.
|
770 | *
|
771 | * ```js
|
772 | * import { Buffer } from 'buffer';
|
773 | *
|
774 | * const buf = Buffer.from('buffer');
|
775 | *
|
776 | * const copiedBuf = Uint8Array.prototype.slice.call(buf);
|
777 | * copiedBuf[0]++;
|
778 | * console.log(copiedBuf.toString());
|
779 | * // Prints: cuffer
|
780 | *
|
781 | * console.log(buf.toString());
|
782 | * // Prints: buffer
|
783 | * ```
|
784 | * @since v0.3.0
|
785 | * @param [start=0] Where the new `Buffer` will start.
|
786 | * @param [end=buf.length] Where the new `Buffer` will end (not inclusive).
|
787 | */
|
788 | slice(start?: number, end?: number): Buffer;
|
789 | /**
|
790 | * Returns a new `Buffer` that references the same memory as the original, but
|
791 | * offset and cropped by the `start` and `end` indices.
|
792 | *
|
793 | * Specifying `end` greater than `buf.length` will return the same result as
|
794 | * that of `end` equal to `buf.length`.
|
795 | *
|
796 | * This method is inherited from [`TypedArray.prototype.subarray()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/subarray).
|
797 | *
|
798 | * Modifying the new `Buffer` slice will modify the memory in the original `Buffer`because the allocated memory of the two objects overlap.
|
799 | *
|
800 | * ```js
|
801 | * import { Buffer } from 'buffer';
|
802 | *
|
803 | * // Create a `Buffer` with the ASCII alphabet, take a slice, and modify one byte
|
804 | * // from the original `Buffer`.
|
805 | *
|
806 | * const buf1 = Buffer.allocUnsafe(26);
|
807 | *
|
808 | * for (let i = 0; i < 26; i++) {
|
809 | * // 97 is the decimal ASCII value for 'a'.
|
810 | * buf1[i] = i + 97;
|
811 | * }
|
812 | *
|
813 | * const buf2 = buf1.subarray(0, 3);
|
814 | *
|
815 | * console.log(buf2.toString('ascii', 0, buf2.length));
|
816 | * // Prints: abc
|
817 | *
|
818 | * buf1[0] = 33;
|
819 | *
|
820 | * console.log(buf2.toString('ascii', 0, buf2.length));
|
821 | * // Prints: !bc
|
822 | * ```
|
823 | *
|
824 | * Specifying negative indexes causes the slice to be generated relative to the
|
825 | * end of `buf` rather than the beginning.
|
826 | *
|
827 | * ```js
|
828 | * import { Buffer } from 'buffer';
|
829 | *
|
830 | * const buf = Buffer.from('buffer');
|
831 | *
|
832 | * console.log(buf.subarray(-6, -1).toString());
|
833 | * // Prints: buffe
|
834 | * // (Equivalent to buf.subarray(0, 5).)
|
835 | *
|
836 | * console.log(buf.subarray(-6, -2).toString());
|
837 | * // Prints: buff
|
838 | * // (Equivalent to buf.subarray(0, 4).)
|
839 | *
|
840 | * console.log(buf.subarray(-5, -2).toString());
|
841 | * // Prints: uff
|
842 | * // (Equivalent to buf.subarray(1, 4).)
|
843 | * ```
|
844 | * @since v3.0.0
|
845 | * @param [start=0] Where the new `Buffer` will start.
|
846 | * @param [end=buf.length] Where the new `Buffer` will end (not inclusive).
|
847 | */
|
848 | subarray(start?: number, end?: number): Buffer;
|
849 | /**
|
850 | * Writes `value` to `buf` at the specified `offset` as big-endian.
|
851 | *
|
852 | * `value` is interpreted and written as a two's complement signed integer.
|
853 | *
|
854 | * ```js
|
855 | * import { Buffer } from 'buffer';
|
856 | *
|
857 | * const buf = Buffer.allocUnsafe(8);
|
858 | *
|
859 | * buf.writeBigInt64BE(0x0102030405060708n, 0);
|
860 | *
|
861 | * console.log(buf);
|
862 | * // Prints: <Buffer 01 02 03 04 05 06 07 08>
|
863 | * ```
|
864 | * @since v12.0.0, v10.20.0
|
865 | * @param value Number to be written to `buf`.
|
866 | * @param [offset=0] Number of bytes to skip before starting to write. Must satisfy: `0 <= offset <= buf.length - 8`.
|
867 | * @return `offset` plus the number of bytes written.
|
868 | */
|
869 | writeBigInt64BE(value: bigint, offset?: number): number;
|
870 | /**
|
871 | * Writes `value` to `buf` at the specified `offset` as little-endian.
|
872 | *
|
873 | * `value` is interpreted and written as a two's complement signed integer.
|
874 | *
|
875 | * ```js
|
876 | * import { Buffer } from 'buffer';
|
877 | *
|
878 | * const buf = Buffer.allocUnsafe(8);
|
879 | *
|
880 | * buf.writeBigInt64LE(0x0102030405060708n, 0);
|
881 | *
|
882 | * console.log(buf);
|
883 | * // Prints: <Buffer 08 07 06 05 04 03 02 01>
|
884 | * ```
|
885 | * @since v12.0.0, v10.20.0
|
886 | * @param value Number to be written to `buf`.
|
887 | * @param [offset=0] Number of bytes to skip before starting to write. Must satisfy: `0 <= offset <= buf.length - 8`.
|
888 | * @return `offset` plus the number of bytes written.
|
889 | */
|
890 | writeBigInt64LE(value: bigint, offset?: number): number;
|
891 | /**
|
892 | * Writes `value` to `buf` at the specified `offset` as big-endian.
|
893 | *
|
894 | * This function is also available under the `writeBigUint64BE` alias.
|
895 | *
|
896 | * ```js
|
897 | * import { Buffer } from 'buffer';
|
898 | *
|
899 | * const buf = Buffer.allocUnsafe(8);
|
900 | *
|
901 | * buf.writeBigUInt64BE(0xdecafafecacefaden, 0);
|
902 | *
|
903 | * console.log(buf);
|
904 | * // Prints: <Buffer de ca fa fe ca ce fa de>
|
905 | * ```
|
906 | * @since v12.0.0, v10.20.0
|
907 | * @param value Number to be written to `buf`.
|
908 | * @param [offset=0] Number of bytes to skip before starting to write. Must satisfy: `0 <= offset <= buf.length - 8`.
|
909 | * @return `offset` plus the number of bytes written.
|
910 | */
|
911 | writeBigUInt64BE(value: bigint, offset?: number): number;
|
912 | /**
|
913 | * @alias Buffer.writeBigUInt64BE
|
914 | * @since v14.10.0, v12.19.0
|
915 | */
|
916 | writeBigUint64BE(value: bigint, offset?: number): number;
|
917 | /**
|
918 | * Writes `value` to `buf` at the specified `offset` as little-endian
|
919 | *
|
920 | * ```js
|
921 | * import { Buffer } from 'buffer';
|
922 | *
|
923 | * const buf = Buffer.allocUnsafe(8);
|
924 | *
|
925 | * buf.writeBigUInt64LE(0xdecafafecacefaden, 0);
|
926 | *
|
927 | * console.log(buf);
|
928 | * // Prints: <Buffer de fa ce ca fe fa ca de>
|
929 | * ```
|
930 | *
|
931 | * This function is also available under the `writeBigUint64LE` alias.
|
932 | * @since v12.0.0, v10.20.0
|
933 | * @param value Number to be written to `buf`.
|
934 | * @param [offset=0] Number of bytes to skip before starting to write. Must satisfy: `0 <= offset <= buf.length - 8`.
|
935 | * @return `offset` plus the number of bytes written.
|
936 | */
|
937 | writeBigUInt64LE(value: bigint, offset?: number): number;
|
938 | /**
|
939 | * @alias Buffer.writeBigUInt64LE
|
940 | * @since v14.10.0, v12.19.0
|
941 | */
|
942 | writeBigUint64LE(value: bigint, offset?: number): number;
|
943 | /**
|
944 | * Writes `byteLength` bytes of `value` to `buf` at the specified `offset`as little-endian. Supports up to 48 bits of accuracy. Behavior is undefined
|
945 | * when `value` is anything other than an unsigned integer.
|
946 | *
|
947 | * This function is also available under the `writeUintLE` alias.
|
948 | *
|
949 | * ```js
|
950 | * import { Buffer } from 'buffer';
|
951 | *
|
952 | * const buf = Buffer.allocUnsafe(6);
|
953 | *
|
954 | * buf.writeUIntLE(0x1234567890ab, 0, 6);
|
955 | *
|
956 | * console.log(buf);
|
957 | * // Prints: <Buffer ab 90 78 56 34 12>
|
958 | * ```
|
959 | * @since v0.5.5
|
960 | * @param value Number to be written to `buf`.
|
961 | * @param offset Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - byteLength`.
|
962 | * @param byteLength Number of bytes to write. Must satisfy `0 < byteLength <= 6`.
|
963 | * @return `offset` plus the number of bytes written.
|
964 | */
|
965 | writeUIntLE(value: number, offset: number, byteLength: number): number;
|
966 | /**
|
967 | * @alias Buffer.writeUIntLE
|
968 | * @since v14.9.0, v12.19.0
|
969 | */
|
970 | writeUintLE(value: number, offset: number, byteLength: number): number;
|
971 | /**
|
972 | * Writes `byteLength` bytes of `value` to `buf` at the specified `offset`as big-endian. Supports up to 48 bits of accuracy. Behavior is undefined
|
973 | * when `value` is anything other than an unsigned integer.
|
974 | *
|
975 | * This function is also available under the `writeUintBE` alias.
|
976 | *
|
977 | * ```js
|
978 | * import { Buffer } from 'buffer';
|
979 | *
|
980 | * const buf = Buffer.allocUnsafe(6);
|
981 | *
|
982 | * buf.writeUIntBE(0x1234567890ab, 0, 6);
|
983 | *
|
984 | * console.log(buf);
|
985 | * // Prints: <Buffer 12 34 56 78 90 ab>
|
986 | * ```
|
987 | * @since v0.5.5
|
988 | * @param value Number to be written to `buf`.
|
989 | * @param offset Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - byteLength`.
|
990 | * @param byteLength Number of bytes to write. Must satisfy `0 < byteLength <= 6`.
|
991 | * @return `offset` plus the number of bytes written.
|
992 | */
|
993 | writeUIntBE(value: number, offset: number, byteLength: number): number;
|
994 | /**
|
995 | * @alias Buffer.writeUIntBE
|
996 | * @since v14.9.0, v12.19.0
|
997 | */
|
998 | writeUintBE(value: number, offset: number, byteLength: number): number;
|
999 | /**
|
1000 | * Writes `byteLength` bytes of `value` to `buf` at the specified `offset`as little-endian. Supports up to 48 bits of accuracy. Behavior is undefined
|
1001 | * when `value` is anything other than a signed integer.
|
1002 | *
|
1003 | * ```js
|
1004 | * import { Buffer } from 'buffer';
|
1005 | *
|
1006 | * const buf = Buffer.allocUnsafe(6);
|
1007 | *
|
1008 | * buf.writeIntLE(0x1234567890ab, 0, 6);
|
1009 | *
|
1010 | * console.log(buf);
|
1011 | * // Prints: <Buffer ab 90 78 56 34 12>
|
1012 | * ```
|
1013 | * @since v0.11.15
|
1014 | * @param value Number to be written to `buf`.
|
1015 | * @param offset Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - byteLength`.
|
1016 | * @param byteLength Number of bytes to write. Must satisfy `0 < byteLength <= 6`.
|
1017 | * @return `offset` plus the number of bytes written.
|
1018 | */
|
1019 | writeIntLE(value: number, offset: number, byteLength: number): number;
|
1020 | /**
|
1021 | * Writes `byteLength` bytes of `value` to `buf` at the specified `offset`as big-endian. Supports up to 48 bits of accuracy. Behavior is undefined when`value` is anything other than a
|
1022 | * signed integer.
|
1023 | *
|
1024 | * ```js
|
1025 | * import { Buffer } from 'buffer';
|
1026 | *
|
1027 | * const buf = Buffer.allocUnsafe(6);
|
1028 | *
|
1029 | * buf.writeIntBE(0x1234567890ab, 0, 6);
|
1030 | *
|
1031 | * console.log(buf);
|
1032 | * // Prints: <Buffer 12 34 56 78 90 ab>
|
1033 | * ```
|
1034 | * @since v0.11.15
|
1035 | * @param value Number to be written to `buf`.
|
1036 | * @param offset Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - byteLength`.
|
1037 | * @param byteLength Number of bytes to write. Must satisfy `0 < byteLength <= 6`.
|
1038 | * @return `offset` plus the number of bytes written.
|
1039 | */
|
1040 | writeIntBE(value: number, offset: number, byteLength: number): number;
|
1041 | /**
|
1042 | * Reads an unsigned, big-endian 64-bit integer from `buf` at the specified`offset`.
|
1043 | *
|
1044 | * This function is also available under the `readBigUint64BE` alias.
|
1045 | *
|
1046 | * ```js
|
1047 | * import { Buffer } from 'buffer';
|
1048 | *
|
1049 | * const buf = Buffer.from([0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff]);
|
1050 | *
|
1051 | * console.log(buf.readBigUInt64BE(0));
|
1052 | * // Prints: 4294967295n
|
1053 | * ```
|
1054 | * @since v12.0.0, v10.20.0
|
1055 | * @param [offset=0] Number of bytes to skip before starting to read. Must satisfy: `0 <= offset <= buf.length - 8`.
|
1056 | */
|
1057 | readBigUInt64BE(offset?: number): bigint;
|
1058 | /**
|
1059 | * @alias Buffer.readBigUInt64BE
|
1060 | * @since v14.10.0, v12.19.0
|
1061 | */
|
1062 | readBigUint64BE(offset?: number): bigint;
|
1063 | /**
|
1064 | * Reads an unsigned, little-endian 64-bit integer from `buf` at the specified`offset`.
|
1065 | *
|
1066 | * This function is also available under the `readBigUint64LE` alias.
|
1067 | *
|
1068 | * ```js
|
1069 | * import { Buffer } from 'buffer';
|
1070 | *
|
1071 | * const buf = Buffer.from([0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff]);
|
1072 | *
|
1073 | * console.log(buf.readBigUInt64LE(0));
|
1074 | * // Prints: 18446744069414584320n
|
1075 | * ```
|
1076 | * @since v12.0.0, v10.20.0
|
1077 | * @param [offset=0] Number of bytes to skip before starting to read. Must satisfy: `0 <= offset <= buf.length - 8`.
|
1078 | */
|
1079 | readBigUInt64LE(offset?: number): bigint;
|
1080 | /**
|
1081 | * @alias Buffer.readBigUInt64LE
|
1082 | * @since v14.10.0, v12.19.0
|
1083 | */
|
1084 | readBigUint64LE(offset?: number): bigint;
|
1085 | /**
|
1086 | * Reads a signed, big-endian 64-bit integer from `buf` at the specified `offset`.
|
1087 | *
|
1088 | * Integers read from a `Buffer` are interpreted as two's complement signed
|
1089 | * values.
|
1090 | * @since v12.0.0, v10.20.0
|
1091 | * @param [offset=0] Number of bytes to skip before starting to read. Must satisfy: `0 <= offset <= buf.length - 8`.
|
1092 | */
|
1093 | readBigInt64BE(offset?: number): bigint;
|
1094 | /**
|
1095 | * Reads a signed, little-endian 64-bit integer from `buf` at the specified`offset`.
|
1096 | *
|
1097 | * Integers read from a `Buffer` are interpreted as two's complement signed
|
1098 | * values.
|
1099 | * @since v12.0.0, v10.20.0
|
1100 | * @param [offset=0] Number of bytes to skip before starting to read. Must satisfy: `0 <= offset <= buf.length - 8`.
|
1101 | */
|
1102 | readBigInt64LE(offset?: number): bigint;
|
1103 | /**
|
1104 | * Reads `byteLength` number of bytes from `buf` at the specified `offset`and interprets the result as an unsigned, little-endian integer supporting
|
1105 | * up to 48 bits of accuracy.
|
1106 | *
|
1107 | * This function is also available under the `readUintLE` alias.
|
1108 | *
|
1109 | * ```js
|
1110 | * import { Buffer } from 'buffer';
|
1111 | *
|
1112 | * const buf = Buffer.from([0x12, 0x34, 0x56, 0x78, 0x90, 0xab]);
|
1113 | *
|
1114 | * console.log(buf.readUIntLE(0, 6).toString(16));
|
1115 | * // Prints: ab9078563412
|
1116 | * ```
|
1117 | * @since v0.11.15
|
1118 | * @param offset Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - byteLength`.
|
1119 | * @param byteLength Number of bytes to read. Must satisfy `0 < byteLength <= 6`.
|
1120 | */
|
1121 | readUIntLE(offset: number, byteLength: number): number;
|
1122 | /**
|
1123 | * @alias Buffer.readUIntLE
|
1124 | * @since v14.9.0, v12.19.0
|
1125 | */
|
1126 | readUintLE(offset: number, byteLength: number): number;
|
1127 | /**
|
1128 | * Reads `byteLength` number of bytes from `buf` at the specified `offset`and interprets the result as an unsigned big-endian integer supporting
|
1129 | * up to 48 bits of accuracy.
|
1130 | *
|
1131 | * This function is also available under the `readUintBE` alias.
|
1132 | *
|
1133 | * ```js
|
1134 | * import { Buffer } from 'buffer';
|
1135 | *
|
1136 | * const buf = Buffer.from([0x12, 0x34, 0x56, 0x78, 0x90, 0xab]);
|
1137 | *
|
1138 | * console.log(buf.readUIntBE(0, 6).toString(16));
|
1139 | * // Prints: 1234567890ab
|
1140 | * console.log(buf.readUIntBE(1, 6).toString(16));
|
1141 | * // Throws ERR_OUT_OF_RANGE.
|
1142 | * ```
|
1143 | * @since v0.11.15
|
1144 | * @param offset Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - byteLength`.
|
1145 | * @param byteLength Number of bytes to read. Must satisfy `0 < byteLength <= 6`.
|
1146 | */
|
1147 | readUIntBE(offset: number, byteLength: number): number;
|
1148 | /**
|
1149 | * @alias Buffer.readUIntBE
|
1150 | * @since v14.9.0, v12.19.0
|
1151 | */
|
1152 | readUintBE(offset: number, byteLength: number): number;
|
1153 | /**
|
1154 | * Reads `byteLength` number of bytes from `buf` at the specified `offset`and interprets the result as a little-endian, two's complement signed value
|
1155 | * supporting up to 48 bits of accuracy.
|
1156 | *
|
1157 | * ```js
|
1158 | * import { Buffer } from 'buffer';
|
1159 | *
|
1160 | * const buf = Buffer.from([0x12, 0x34, 0x56, 0x78, 0x90, 0xab]);
|
1161 | *
|
1162 | * console.log(buf.readIntLE(0, 6).toString(16));
|
1163 | * // Prints: -546f87a9cbee
|
1164 | * ```
|
1165 | * @since v0.11.15
|
1166 | * @param offset Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - byteLength`.
|
1167 | * @param byteLength Number of bytes to read. Must satisfy `0 < byteLength <= 6`.
|
1168 | */
|
1169 | readIntLE(offset: number, byteLength: number): number;
|
1170 | /**
|
1171 | * Reads `byteLength` number of bytes from `buf` at the specified `offset`and interprets the result as a big-endian, two's complement signed value
|
1172 | * supporting up to 48 bits of accuracy.
|
1173 | *
|
1174 | * ```js
|
1175 | * import { Buffer } from 'buffer';
|
1176 | *
|
1177 | * const buf = Buffer.from([0x12, 0x34, 0x56, 0x78, 0x90, 0xab]);
|
1178 | *
|
1179 | * console.log(buf.readIntBE(0, 6).toString(16));
|
1180 | * // Prints: 1234567890ab
|
1181 | * console.log(buf.readIntBE(1, 6).toString(16));
|
1182 | * // Throws ERR_OUT_OF_RANGE.
|
1183 | * console.log(buf.readIntBE(1, 0).toString(16));
|
1184 | * // Throws ERR_OUT_OF_RANGE.
|
1185 | * ```
|
1186 | * @since v0.11.15
|
1187 | * @param offset Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - byteLength`.
|
1188 | * @param byteLength Number of bytes to read. Must satisfy `0 < byteLength <= 6`.
|
1189 | */
|
1190 | readIntBE(offset: number, byteLength: number): number;
|
1191 | /**
|
1192 | * Reads an unsigned 8-bit integer from `buf` at the specified `offset`.
|
1193 | *
|
1194 | * This function is also available under the `readUint8` alias.
|
1195 | *
|
1196 | * ```js
|
1197 | * import { Buffer } from 'buffer';
|
1198 | *
|
1199 | * const buf = Buffer.from([1, -2]);
|
1200 | *
|
1201 | * console.log(buf.readUInt8(0));
|
1202 | * // Prints: 1
|
1203 | * console.log(buf.readUInt8(1));
|
1204 | * // Prints: 254
|
1205 | * console.log(buf.readUInt8(2));
|
1206 | * // Throws ERR_OUT_OF_RANGE.
|
1207 | * ```
|
1208 | * @since v0.5.0
|
1209 | * @param [offset=0] Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 1`.
|
1210 | */
|
1211 | readUInt8(offset?: number): number;
|
1212 | /**
|
1213 | * @alias Buffer.readUInt8
|
1214 | * @since v14.9.0, v12.19.0
|
1215 | */
|
1216 | readUint8(offset?: number): number;
|
1217 | /**
|
1218 | * Reads an unsigned, little-endian 16-bit integer from `buf` at the specified`offset`.
|
1219 | *
|
1220 | * This function is also available under the `readUint16LE` alias.
|
1221 | *
|
1222 | * ```js
|
1223 | * import { Buffer } from 'buffer';
|
1224 | *
|
1225 | * const buf = Buffer.from([0x12, 0x34, 0x56]);
|
1226 | *
|
1227 | * console.log(buf.readUInt16LE(0).toString(16));
|
1228 | * // Prints: 3412
|
1229 | * console.log(buf.readUInt16LE(1).toString(16));
|
1230 | * // Prints: 5634
|
1231 | * console.log(buf.readUInt16LE(2).toString(16));
|
1232 | * // Throws ERR_OUT_OF_RANGE.
|
1233 | * ```
|
1234 | * @since v0.5.5
|
1235 | * @param [offset=0] Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 2`.
|
1236 | */
|
1237 | readUInt16LE(offset?: number): number;
|
1238 | /**
|
1239 | * @alias Buffer.readUInt16LE
|
1240 | * @since v14.9.0, v12.19.0
|
1241 | */
|
1242 | readUint16LE(offset?: number): number;
|
1243 | /**
|
1244 | * Reads an unsigned, big-endian 16-bit integer from `buf` at the specified`offset`.
|
1245 | *
|
1246 | * This function is also available under the `readUint16BE` alias.
|
1247 | *
|
1248 | * ```js
|
1249 | * import { Buffer } from 'buffer';
|
1250 | *
|
1251 | * const buf = Buffer.from([0x12, 0x34, 0x56]);
|
1252 | *
|
1253 | * console.log(buf.readUInt16BE(0).toString(16));
|
1254 | * // Prints: 1234
|
1255 | * console.log(buf.readUInt16BE(1).toString(16));
|
1256 | * // Prints: 3456
|
1257 | * ```
|
1258 | * @since v0.5.5
|
1259 | * @param [offset=0] Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 2`.
|
1260 | */
|
1261 | readUInt16BE(offset?: number): number;
|
1262 | /**
|
1263 | * @alias Buffer.readUInt16BE
|
1264 | * @since v14.9.0, v12.19.0
|
1265 | */
|
1266 | readUint16BE(offset?: number): number;
|
1267 | /**
|
1268 | * Reads an unsigned, little-endian 32-bit integer from `buf` at the specified`offset`.
|
1269 | *
|
1270 | * This function is also available under the `readUint32LE` alias.
|
1271 | *
|
1272 | * ```js
|
1273 | * import { Buffer } from 'buffer';
|
1274 | *
|
1275 | * const buf = Buffer.from([0x12, 0x34, 0x56, 0x78]);
|
1276 | *
|
1277 | * console.log(buf.readUInt32LE(0).toString(16));
|
1278 | * // Prints: 78563412
|
1279 | * console.log(buf.readUInt32LE(1).toString(16));
|
1280 | * // Throws ERR_OUT_OF_RANGE.
|
1281 | * ```
|
1282 | * @since v0.5.5
|
1283 | * @param [offset=0] Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 4`.
|
1284 | */
|
1285 | readUInt32LE(offset?: number): number;
|
1286 | /**
|
1287 | * @alias Buffer.readUInt32LE
|
1288 | * @since v14.9.0, v12.19.0
|
1289 | */
|
1290 | readUint32LE(offset?: number): number;
|
1291 | /**
|
1292 | * Reads an unsigned, big-endian 32-bit integer from `buf` at the specified`offset`.
|
1293 | *
|
1294 | * This function is also available under the `readUint32BE` alias.
|
1295 | *
|
1296 | * ```js
|
1297 | * import { Buffer } from 'buffer';
|
1298 | *
|
1299 | * const buf = Buffer.from([0x12, 0x34, 0x56, 0x78]);
|
1300 | *
|
1301 | * console.log(buf.readUInt32BE(0).toString(16));
|
1302 | * // Prints: 12345678
|
1303 | * ```
|
1304 | * @since v0.5.5
|
1305 | * @param [offset=0] Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 4`.
|
1306 | */
|
1307 | readUInt32BE(offset?: number): number;
|
1308 | /**
|
1309 | * @alias Buffer.readUInt32BE
|
1310 | * @since v14.9.0, v12.19.0
|
1311 | */
|
1312 | readUint32BE(offset?: number): number;
|
1313 | /**
|
1314 | * Reads a signed 8-bit integer from `buf` at the specified `offset`.
|
1315 | *
|
1316 | * Integers read from a `Buffer` are interpreted as two's complement signed values.
|
1317 | *
|
1318 | * ```js
|
1319 | * import { Buffer } from 'buffer';
|
1320 | *
|
1321 | * const buf = Buffer.from([-1, 5]);
|
1322 | *
|
1323 | * console.log(buf.readInt8(0));
|
1324 | * // Prints: -1
|
1325 | * console.log(buf.readInt8(1));
|
1326 | * // Prints: 5
|
1327 | * console.log(buf.readInt8(2));
|
1328 | * // Throws ERR_OUT_OF_RANGE.
|
1329 | * ```
|
1330 | * @since v0.5.0
|
1331 | * @param [offset=0] Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 1`.
|
1332 | */
|
1333 | readInt8(offset?: number): number;
|
1334 | /**
|
1335 | * Reads a signed, little-endian 16-bit integer from `buf` at the specified`offset`.
|
1336 | *
|
1337 | * Integers read from a `Buffer` are interpreted as two's complement signed values.
|
1338 | *
|
1339 | * ```js
|
1340 | * import { Buffer } from 'buffer';
|
1341 | *
|
1342 | * const buf = Buffer.from([0, 5]);
|
1343 | *
|
1344 | * console.log(buf.readInt16LE(0));
|
1345 | * // Prints: 1280
|
1346 | * console.log(buf.readInt16LE(1));
|
1347 | * // Throws ERR_OUT_OF_RANGE.
|
1348 | * ```
|
1349 | * @since v0.5.5
|
1350 | * @param [offset=0] Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 2`.
|
1351 | */
|
1352 | readInt16LE(offset?: number): number;
|
1353 | /**
|
1354 | * Reads a signed, big-endian 16-bit integer from `buf` at the specified `offset`.
|
1355 | *
|
1356 | * Integers read from a `Buffer` are interpreted as two's complement signed values.
|
1357 | *
|
1358 | * ```js
|
1359 | * import { Buffer } from 'buffer';
|
1360 | *
|
1361 | * const buf = Buffer.from([0, 5]);
|
1362 | *
|
1363 | * console.log(buf.readInt16BE(0));
|
1364 | * // Prints: 5
|
1365 | * ```
|
1366 | * @since v0.5.5
|
1367 | * @param [offset=0] Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 2`.
|
1368 | */
|
1369 | readInt16BE(offset?: number): number;
|
1370 | /**
|
1371 | * Reads a signed, little-endian 32-bit integer from `buf` at the specified`offset`.
|
1372 | *
|
1373 | * Integers read from a `Buffer` are interpreted as two's complement signed values.
|
1374 | *
|
1375 | * ```js
|
1376 | * import { Buffer } from 'buffer';
|
1377 | *
|
1378 | * const buf = Buffer.from([0, 0, 0, 5]);
|
1379 | *
|
1380 | * console.log(buf.readInt32LE(0));
|
1381 | * // Prints: 83886080
|
1382 | * console.log(buf.readInt32LE(1));
|
1383 | * // Throws ERR_OUT_OF_RANGE.
|
1384 | * ```
|
1385 | * @since v0.5.5
|
1386 | * @param [offset=0] Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 4`.
|
1387 | */
|
1388 | readInt32LE(offset?: number): number;
|
1389 | /**
|
1390 | * Reads a signed, big-endian 32-bit integer from `buf` at the specified `offset`.
|
1391 | *
|
1392 | * Integers read from a `Buffer` are interpreted as two's complement signed values.
|
1393 | *
|
1394 | * ```js
|
1395 | * import { Buffer } from 'buffer';
|
1396 | *
|
1397 | * const buf = Buffer.from([0, 0, 0, 5]);
|
1398 | *
|
1399 | * console.log(buf.readInt32BE(0));
|
1400 | * // Prints: 5
|
1401 | * ```
|
1402 | * @since v0.5.5
|
1403 | * @param [offset=0] Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 4`.
|
1404 | */
|
1405 | readInt32BE(offset?: number): number;
|
1406 | /**
|
1407 | * Reads a 32-bit, little-endian float from `buf` at the specified `offset`.
|
1408 | *
|
1409 | * ```js
|
1410 | * import { Buffer } from 'buffer';
|
1411 | *
|
1412 | * const buf = Buffer.from([1, 2, 3, 4]);
|
1413 | *
|
1414 | * console.log(buf.readFloatLE(0));
|
1415 | * // Prints: 1.539989614439558e-36
|
1416 | * console.log(buf.readFloatLE(1));
|
1417 | * // Throws ERR_OUT_OF_RANGE.
|
1418 | * ```
|
1419 | * @since v0.11.15
|
1420 | * @param [offset=0] Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 4`.
|
1421 | */
|
1422 | readFloatLE(offset?: number): number;
|
1423 | /**
|
1424 | * Reads a 32-bit, big-endian float from `buf` at the specified `offset`.
|
1425 | *
|
1426 | * ```js
|
1427 | * import { Buffer } from 'buffer';
|
1428 | *
|
1429 | * const buf = Buffer.from([1, 2, 3, 4]);
|
1430 | *
|
1431 | * console.log(buf.readFloatBE(0));
|
1432 | * // Prints: 2.387939260590663e-38
|
1433 | * ```
|
1434 | * @since v0.11.15
|
1435 | * @param [offset=0] Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 4`.
|
1436 | */
|
1437 | readFloatBE(offset?: number): number;
|
1438 | /**
|
1439 | * Reads a 64-bit, little-endian double from `buf` at the specified `offset`.
|
1440 | *
|
1441 | * ```js
|
1442 | * import { Buffer } from 'buffer';
|
1443 | *
|
1444 | * const buf = Buffer.from([1, 2, 3, 4, 5, 6, 7, 8]);
|
1445 | *
|
1446 | * console.log(buf.readDoubleLE(0));
|
1447 | * // Prints: 5.447603722011605e-270
|
1448 | * console.log(buf.readDoubleLE(1));
|
1449 | * // Throws ERR_OUT_OF_RANGE.
|
1450 | * ```
|
1451 | * @since v0.11.15
|
1452 | * @param [offset=0] Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 8`.
|
1453 | */
|
1454 | readDoubleLE(offset?: number): number;
|
1455 | /**
|
1456 | * Reads a 64-bit, big-endian double from `buf` at the specified `offset`.
|
1457 | *
|
1458 | * ```js
|
1459 | * import { Buffer } from 'buffer';
|
1460 | *
|
1461 | * const buf = Buffer.from([1, 2, 3, 4, 5, 6, 7, 8]);
|
1462 | *
|
1463 | * console.log(buf.readDoubleBE(0));
|
1464 | * // Prints: 8.20788039913184e-304
|
1465 | * ```
|
1466 | * @since v0.11.15
|
1467 | * @param [offset=0] Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 8`.
|
1468 | */
|
1469 | readDoubleBE(offset?: number): number;
|
1470 | reverse(): this;
|
1471 | /**
|
1472 | * Interprets `buf` as an array of unsigned 16-bit integers and swaps the
|
1473 | * byte order _in-place_. Throws `ERR_INVALID_BUFFER_SIZE` if `buf.length` is not a multiple of 2.
|
1474 | *
|
1475 | * ```js
|
1476 | * import { Buffer } from 'buffer';
|
1477 | *
|
1478 | * const buf1 = Buffer.from([0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8]);
|
1479 | *
|
1480 | * console.log(buf1);
|
1481 | * // Prints: <Buffer 01 02 03 04 05 06 07 08>
|
1482 | *
|
1483 | * buf1.swap16();
|
1484 | *
|
1485 | * console.log(buf1);
|
1486 | * // Prints: <Buffer 02 01 04 03 06 05 08 07>
|
1487 | *
|
1488 | * const buf2 = Buffer.from([0x1, 0x2, 0x3]);
|
1489 | *
|
1490 | * buf2.swap16();
|
1491 | * // Throws ERR_INVALID_BUFFER_SIZE.
|
1492 | * ```
|
1493 | *
|
1494 | * One convenient use of `buf.swap16()` is to perform a fast in-place conversion
|
1495 | * between UTF-16 little-endian and UTF-16 big-endian:
|
1496 | *
|
1497 | * ```js
|
1498 | * import { Buffer } from 'buffer';
|
1499 | *
|
1500 | * const buf = Buffer.from('This is little-endian UTF-16', 'utf16le');
|
1501 | * buf.swap16(); // Convert to big-endian UTF-16 text.
|
1502 | * ```
|
1503 | * @since v5.10.0
|
1504 | * @return A reference to `buf`.
|
1505 | */
|
1506 | swap16(): Buffer;
|
1507 | /**
|
1508 | * Interprets `buf` as an array of unsigned 32-bit integers and swaps the
|
1509 | * byte order _in-place_. Throws `ERR_INVALID_BUFFER_SIZE` if `buf.length` is not a multiple of 4.
|
1510 | *
|
1511 | * ```js
|
1512 | * import { Buffer } from 'buffer';
|
1513 | *
|
1514 | * const buf1 = Buffer.from([0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8]);
|
1515 | *
|
1516 | * console.log(buf1);
|
1517 | * // Prints: <Buffer 01 02 03 04 05 06 07 08>
|
1518 | *
|
1519 | * buf1.swap32();
|
1520 | *
|
1521 | * console.log(buf1);
|
1522 | * // Prints: <Buffer 04 03 02 01 08 07 06 05>
|
1523 | *
|
1524 | * const buf2 = Buffer.from([0x1, 0x2, 0x3]);
|
1525 | *
|
1526 | * buf2.swap32();
|
1527 | * // Throws ERR_INVALID_BUFFER_SIZE.
|
1528 | * ```
|
1529 | * @since v5.10.0
|
1530 | * @return A reference to `buf`.
|
1531 | */
|
1532 | swap32(): Buffer;
|
1533 | /**
|
1534 | * Interprets `buf` as an array of 64-bit numbers and swaps byte order _in-place_.
|
1535 | * Throws `ERR_INVALID_BUFFER_SIZE` if `buf.length` is not a multiple of 8.
|
1536 | *
|
1537 | * ```js
|
1538 | * import { Buffer } from 'buffer';
|
1539 | *
|
1540 | * const buf1 = Buffer.from([0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8]);
|
1541 | *
|
1542 | * console.log(buf1);
|
1543 | * // Prints: <Buffer 01 02 03 04 05 06 07 08>
|
1544 | *
|
1545 | * buf1.swap64();
|
1546 | *
|
1547 | * console.log(buf1);
|
1548 | * // Prints: <Buffer 08 07 06 05 04 03 02 01>
|
1549 | *
|
1550 | * const buf2 = Buffer.from([0x1, 0x2, 0x3]);
|
1551 | *
|
1552 | * buf2.swap64();
|
1553 | * // Throws ERR_INVALID_BUFFER_SIZE.
|
1554 | * ```
|
1555 | * @since v6.3.0
|
1556 | * @return A reference to `buf`.
|
1557 | */
|
1558 | swap64(): Buffer;
|
1559 | /**
|
1560 | * Writes `value` to `buf` at the specified `offset`. `value` must be a
|
1561 | * valid unsigned 8-bit integer. Behavior is undefined when `value` is anything
|
1562 | * other than an unsigned 8-bit integer.
|
1563 | *
|
1564 | * This function is also available under the `writeUint8` alias.
|
1565 | *
|
1566 | * ```js
|
1567 | * import { Buffer } from 'buffer';
|
1568 | *
|
1569 | * const buf = Buffer.allocUnsafe(4);
|
1570 | *
|
1571 | * buf.writeUInt8(0x3, 0);
|
1572 | * buf.writeUInt8(0x4, 1);
|
1573 | * buf.writeUInt8(0x23, 2);
|
1574 | * buf.writeUInt8(0x42, 3);
|
1575 | *
|
1576 | * console.log(buf);
|
1577 | * // Prints: <Buffer 03 04 23 42>
|
1578 | * ```
|
1579 | * @since v0.5.0
|
1580 | * @param value Number to be written to `buf`.
|
1581 | * @param [offset=0] Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - 1`.
|
1582 | * @return `offset` plus the number of bytes written.
|
1583 | */
|
1584 | writeUInt8(value: number, offset?: number): number;
|
1585 | /**
|
1586 | * @alias Buffer.writeUInt8
|
1587 | * @since v14.9.0, v12.19.0
|
1588 | */
|
1589 | writeUint8(value: number, offset?: number): number;
|
1590 | /**
|
1591 | * Writes `value` to `buf` at the specified `offset` as little-endian. The `value`must be a valid unsigned 16-bit integer. Behavior is undefined when `value` is
|
1592 | * anything other than an unsigned 16-bit integer.
|
1593 | *
|
1594 | * This function is also available under the `writeUint16LE` alias.
|
1595 | *
|
1596 | * ```js
|
1597 | * import { Buffer } from 'buffer';
|
1598 | *
|
1599 | * const buf = Buffer.allocUnsafe(4);
|
1600 | *
|
1601 | * buf.writeUInt16LE(0xdead, 0);
|
1602 | * buf.writeUInt16LE(0xbeef, 2);
|
1603 | *
|
1604 | * console.log(buf);
|
1605 | * // Prints: <Buffer ad de ef be>
|
1606 | * ```
|
1607 | * @since v0.5.5
|
1608 | * @param value Number to be written to `buf`.
|
1609 | * @param [offset=0] Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - 2`.
|
1610 | * @return `offset` plus the number of bytes written.
|
1611 | */
|
1612 | writeUInt16LE(value: number, offset?: number): number;
|
1613 | /**
|
1614 | * @alias Buffer.writeUInt16LE
|
1615 | * @since v14.9.0, v12.19.0
|
1616 | */
|
1617 | writeUint16LE(value: number, offset?: number): number;
|
1618 | /**
|
1619 | * Writes `value` to `buf` at the specified `offset` as big-endian. The `value`must be a valid unsigned 16-bit integer. Behavior is undefined when `value`is anything other than an
|
1620 | * unsigned 16-bit integer.
|
1621 | *
|
1622 | * This function is also available under the `writeUint16BE` alias.
|
1623 | *
|
1624 | * ```js
|
1625 | * import { Buffer } from 'buffer';
|
1626 | *
|
1627 | * const buf = Buffer.allocUnsafe(4);
|
1628 | *
|
1629 | * buf.writeUInt16BE(0xdead, 0);
|
1630 | * buf.writeUInt16BE(0xbeef, 2);
|
1631 | *
|
1632 | * console.log(buf);
|
1633 | * // Prints: <Buffer de ad be ef>
|
1634 | * ```
|
1635 | * @since v0.5.5
|
1636 | * @param value Number to be written to `buf`.
|
1637 | * @param [offset=0] Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - 2`.
|
1638 | * @return `offset` plus the number of bytes written.
|
1639 | */
|
1640 | writeUInt16BE(value: number, offset?: number): number;
|
1641 | /**
|
1642 | * @alias Buffer.writeUInt16BE
|
1643 | * @since v14.9.0, v12.19.0
|
1644 | */
|
1645 | writeUint16BE(value: number, offset?: number): number;
|
1646 | /**
|
1647 | * Writes `value` to `buf` at the specified `offset` as little-endian. The `value`must be a valid unsigned 32-bit integer. Behavior is undefined when `value` is
|
1648 | * anything other than an unsigned 32-bit integer.
|
1649 | *
|
1650 | * This function is also available under the `writeUint32LE` alias.
|
1651 | *
|
1652 | * ```js
|
1653 | * import { Buffer } from 'buffer';
|
1654 | *
|
1655 | * const buf = Buffer.allocUnsafe(4);
|
1656 | *
|
1657 | * buf.writeUInt32LE(0xfeedface, 0);
|
1658 | *
|
1659 | * console.log(buf);
|
1660 | * // Prints: <Buffer ce fa ed fe>
|
1661 | * ```
|
1662 | * @since v0.5.5
|
1663 | * @param value Number to be written to `buf`.
|
1664 | * @param [offset=0] Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - 4`.
|
1665 | * @return `offset` plus the number of bytes written.
|
1666 | */
|
1667 | writeUInt32LE(value: number, offset?: number): number;
|
1668 | /**
|
1669 | * @alias Buffer.writeUInt32LE
|
1670 | * @since v14.9.0, v12.19.0
|
1671 | */
|
1672 | writeUint32LE(value: number, offset?: number): number;
|
1673 | /**
|
1674 | * Writes `value` to `buf` at the specified `offset` as big-endian. The `value`must be a valid unsigned 32-bit integer. Behavior is undefined when `value`is anything other than an
|
1675 | * unsigned 32-bit integer.
|
1676 | *
|
1677 | * This function is also available under the `writeUint32BE` alias.
|
1678 | *
|
1679 | * ```js
|
1680 | * import { Buffer } from 'buffer';
|
1681 | *
|
1682 | * const buf = Buffer.allocUnsafe(4);
|
1683 | *
|
1684 | * buf.writeUInt32BE(0xfeedface, 0);
|
1685 | *
|
1686 | * console.log(buf);
|
1687 | * // Prints: <Buffer fe ed fa ce>
|
1688 | * ```
|
1689 | * @since v0.5.5
|
1690 | * @param value Number to be written to `buf`.
|
1691 | * @param [offset=0] Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - 4`.
|
1692 | * @return `offset` plus the number of bytes written.
|
1693 | */
|
1694 | writeUInt32BE(value: number, offset?: number): number;
|
1695 | /**
|
1696 | * @alias Buffer.writeUInt32BE
|
1697 | * @since v14.9.0, v12.19.0
|
1698 | */
|
1699 | writeUint32BE(value: number, offset?: number): number;
|
1700 | /**
|
1701 | * Writes `value` to `buf` at the specified `offset`. `value` must be a valid
|
1702 | * signed 8-bit integer. Behavior is undefined when `value` is anything other than
|
1703 | * a signed 8-bit integer.
|
1704 | *
|
1705 | * `value` is interpreted and written as a two's complement signed integer.
|
1706 | *
|
1707 | * ```js
|
1708 | * import { Buffer } from 'buffer';
|
1709 | *
|
1710 | * const buf = Buffer.allocUnsafe(2);
|
1711 | *
|
1712 | * buf.writeInt8(2, 0);
|
1713 | * buf.writeInt8(-2, 1);
|
1714 | *
|
1715 | * console.log(buf);
|
1716 | * // Prints: <Buffer 02 fe>
|
1717 | * ```
|
1718 | * @since v0.5.0
|
1719 | * @param value Number to be written to `buf`.
|
1720 | * @param [offset=0] Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - 1`.
|
1721 | * @return `offset` plus the number of bytes written.
|
1722 | */
|
1723 | writeInt8(value: number, offset?: number): number;
|
1724 | /**
|
1725 | * Writes `value` to `buf` at the specified `offset` as little-endian. The `value`must be a valid signed 16-bit integer. Behavior is undefined when `value` is
|
1726 | * anything other than a signed 16-bit integer.
|
1727 | *
|
1728 | * The `value` is interpreted and written as a two's complement signed integer.
|
1729 | *
|
1730 | * ```js
|
1731 | * import { Buffer } from 'buffer';
|
1732 | *
|
1733 | * const buf = Buffer.allocUnsafe(2);
|
1734 | *
|
1735 | * buf.writeInt16LE(0x0304, 0);
|
1736 | *
|
1737 | * console.log(buf);
|
1738 | * // Prints: <Buffer 04 03>
|
1739 | * ```
|
1740 | * @since v0.5.5
|
1741 | * @param value Number to be written to `buf`.
|
1742 | * @param [offset=0] Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - 2`.
|
1743 | * @return `offset` plus the number of bytes written.
|
1744 | */
|
1745 | writeInt16LE(value: number, offset?: number): number;
|
1746 | /**
|
1747 | * Writes `value` to `buf` at the specified `offset` as big-endian. The `value`must be a valid signed 16-bit integer. Behavior is undefined when `value` is
|
1748 | * anything other than a signed 16-bit integer.
|
1749 | *
|
1750 | * The `value` is interpreted and written as a two's complement signed integer.
|
1751 | *
|
1752 | * ```js
|
1753 | * import { Buffer } from 'buffer';
|
1754 | *
|
1755 | * const buf = Buffer.allocUnsafe(2);
|
1756 | *
|
1757 | * buf.writeInt16BE(0x0102, 0);
|
1758 | *
|
1759 | * console.log(buf);
|
1760 | * // Prints: <Buffer 01 02>
|
1761 | * ```
|
1762 | * @since v0.5.5
|
1763 | * @param value Number to be written to `buf`.
|
1764 | * @param [offset=0] Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - 2`.
|
1765 | * @return `offset` plus the number of bytes written.
|
1766 | */
|
1767 | writeInt16BE(value: number, offset?: number): number;
|
1768 | /**
|
1769 | * Writes `value` to `buf` at the specified `offset` as little-endian. The `value`must be a valid signed 32-bit integer. Behavior is undefined when `value` is
|
1770 | * anything other than a signed 32-bit integer.
|
1771 | *
|
1772 | * The `value` is interpreted and written as a two's complement signed integer.
|
1773 | *
|
1774 | * ```js
|
1775 | * import { Buffer } from 'buffer';
|
1776 | *
|
1777 | * const buf = Buffer.allocUnsafe(4);
|
1778 | *
|
1779 | * buf.writeInt32LE(0x05060708, 0);
|
1780 | *
|
1781 | * console.log(buf);
|
1782 | * // Prints: <Buffer 08 07 06 05>
|
1783 | * ```
|
1784 | * @since v0.5.5
|
1785 | * @param value Number to be written to `buf`.
|
1786 | * @param [offset=0] Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - 4`.
|
1787 | * @return `offset` plus the number of bytes written.
|
1788 | */
|
1789 | writeInt32LE(value: number, offset?: number): number;
|
1790 | /**
|
1791 | * Writes `value` to `buf` at the specified `offset` as big-endian. The `value`must be a valid signed 32-bit integer. Behavior is undefined when `value` is
|
1792 | * anything other than a signed 32-bit integer.
|
1793 | *
|
1794 | * The `value` is interpreted and written as a two's complement signed integer.
|
1795 | *
|
1796 | * ```js
|
1797 | * import { Buffer } from 'buffer';
|
1798 | *
|
1799 | * const buf = Buffer.allocUnsafe(4);
|
1800 | *
|
1801 | * buf.writeInt32BE(0x01020304, 0);
|
1802 | *
|
1803 | * console.log(buf);
|
1804 | * // Prints: <Buffer 01 02 03 04>
|
1805 | * ```
|
1806 | * @since v0.5.5
|
1807 | * @param value Number to be written to `buf`.
|
1808 | * @param [offset=0] Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - 4`.
|
1809 | * @return `offset` plus the number of bytes written.
|
1810 | */
|
1811 | writeInt32BE(value: number, offset?: number): number;
|
1812 | /**
|
1813 | * Writes `value` to `buf` at the specified `offset` as little-endian. Behavior is
|
1814 | * undefined when `value` is anything other than a JavaScript number.
|
1815 | *
|
1816 | * ```js
|
1817 | * import { Buffer } from 'buffer';
|
1818 | *
|
1819 | * const buf = Buffer.allocUnsafe(4);
|
1820 | *
|
1821 | * buf.writeFloatLE(0xcafebabe, 0);
|
1822 | *
|
1823 | * console.log(buf);
|
1824 | * // Prints: <Buffer bb fe 4a 4f>
|
1825 | * ```
|
1826 | * @since v0.11.15
|
1827 | * @param value Number to be written to `buf`.
|
1828 | * @param [offset=0] Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - 4`.
|
1829 | * @return `offset` plus the number of bytes written.
|
1830 | */
|
1831 | writeFloatLE(value: number, offset?: number): number;
|
1832 | /**
|
1833 | * Writes `value` to `buf` at the specified `offset` as big-endian. Behavior is
|
1834 | * undefined when `value` is anything other than a JavaScript number.
|
1835 | *
|
1836 | * ```js
|
1837 | * import { Buffer } from 'buffer';
|
1838 | *
|
1839 | * const buf = Buffer.allocUnsafe(4);
|
1840 | *
|
1841 | * buf.writeFloatBE(0xcafebabe, 0);
|
1842 | *
|
1843 | * console.log(buf);
|
1844 | * // Prints: <Buffer 4f 4a fe bb>
|
1845 | * ```
|
1846 | * @since v0.11.15
|
1847 | * @param value Number to be written to `buf`.
|
1848 | * @param [offset=0] Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - 4`.
|
1849 | * @return `offset` plus the number of bytes written.
|
1850 | */
|
1851 | writeFloatBE(value: number, offset?: number): number;
|
1852 | /**
|
1853 | * Writes `value` to `buf` at the specified `offset` as little-endian. The `value`must be a JavaScript number. Behavior is undefined when `value` is anything
|
1854 | * other than a JavaScript number.
|
1855 | *
|
1856 | * ```js
|
1857 | * import { Buffer } from 'buffer';
|
1858 | *
|
1859 | * const buf = Buffer.allocUnsafe(8);
|
1860 | *
|
1861 | * buf.writeDoubleLE(123.456, 0);
|
1862 | *
|
1863 | * console.log(buf);
|
1864 | * // Prints: <Buffer 77 be 9f 1a 2f dd 5e 40>
|
1865 | * ```
|
1866 | * @since v0.11.15
|
1867 | * @param value Number to be written to `buf`.
|
1868 | * @param [offset=0] Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - 8`.
|
1869 | * @return `offset` plus the number of bytes written.
|
1870 | */
|
1871 | writeDoubleLE(value: number, offset?: number): number;
|
1872 | /**
|
1873 | * Writes `value` to `buf` at the specified `offset` as big-endian. The `value`must be a JavaScript number. Behavior is undefined when `value` is anything
|
1874 | * other than a JavaScript number.
|
1875 | *
|
1876 | * ```js
|
1877 | * import { Buffer } from 'buffer';
|
1878 | *
|
1879 | * const buf = Buffer.allocUnsafe(8);
|
1880 | *
|
1881 | * buf.writeDoubleBE(123.456, 0);
|
1882 | *
|
1883 | * console.log(buf);
|
1884 | * // Prints: <Buffer 40 5e dd 2f 1a 9f be 77>
|
1885 | * ```
|
1886 | * @since v0.11.15
|
1887 | * @param value Number to be written to `buf`.
|
1888 | * @param [offset=0] Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - 8`.
|
1889 | * @return `offset` plus the number of bytes written.
|
1890 | */
|
1891 | writeDoubleBE(value: number, offset?: number): number;
|
1892 | /**
|
1893 | * Fills `buf` with the specified `value`. If the `offset` and `end` are not given,
|
1894 | * the entire `buf` will be filled:
|
1895 | *
|
1896 | * ```js
|
1897 | * import { Buffer } from 'buffer';
|
1898 | *
|
1899 | * // Fill a `Buffer` with the ASCII character 'h'.
|
1900 | *
|
1901 | * const b = Buffer.allocUnsafe(50).fill('h');
|
1902 | *
|
1903 | * console.log(b.toString());
|
1904 | * // Prints: hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
|
1905 | * ```
|
1906 | *
|
1907 | * `value` is coerced to a `uint32` value if it is not a string, `Buffer`, or
|
1908 | * integer. If the resulting integer is greater than `255` (decimal), `buf` will be
|
1909 | * filled with `value & 255`.
|
1910 | *
|
1911 | * If the final write of a `fill()` operation falls on a multi-byte character,
|
1912 | * then only the bytes of that character that fit into `buf` are written:
|
1913 | *
|
1914 | * ```js
|
1915 | * import { Buffer } from 'buffer';
|
1916 | *
|
1917 | * // Fill a `Buffer` with character that takes up two bytes in UTF-8.
|
1918 | *
|
1919 | * console.log(Buffer.allocUnsafe(5).fill('\u0222'));
|
1920 | * // Prints: <Buffer c8 a2 c8 a2 c8>
|
1921 | * ```
|
1922 | *
|
1923 | * If `value` contains invalid characters, it is truncated; if no valid
|
1924 | * fill data remains, an exception is thrown:
|
1925 | *
|
1926 | * ```js
|
1927 | * import { Buffer } from 'buffer';
|
1928 | *
|
1929 | * const buf = Buffer.allocUnsafe(5);
|
1930 | *
|
1931 | * console.log(buf.fill('a'));
|
1932 | * // Prints: <Buffer 61 61 61 61 61>
|
1933 | * console.log(buf.fill('aazz', 'hex'));
|
1934 | * // Prints: <Buffer aa aa aa aa aa>
|
1935 | * console.log(buf.fill('zz', 'hex'));
|
1936 | * // Throws an exception.
|
1937 | * ```
|
1938 | * @since v0.5.0
|
1939 | * @param value The value with which to fill `buf`.
|
1940 | * @param [offset=0] Number of bytes to skip before starting to fill `buf`.
|
1941 | * @param [end=buf.length] Where to stop filling `buf` (not inclusive).
|
1942 | * @param [encoding='utf8'] The encoding for `value` if `value` is a string.
|
1943 | * @return A reference to `buf`.
|
1944 | */
|
1945 | fill(value: string | Uint8Array | number, offset?: number, end?: number, encoding?: BufferEncoding): this;
|
1946 | /**
|
1947 | * If `value` is:
|
1948 | *
|
1949 | * * a string, `value` is interpreted according to the character encoding in`encoding`.
|
1950 | * * a `Buffer` or [`Uint8Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array), `value` will be used in its entirety.
|
1951 | * To compare a partial `Buffer`, use `buf.slice()`.
|
1952 | * * a number, `value` will be interpreted as an unsigned 8-bit integer
|
1953 | * value between `0` and `255`.
|
1954 | *
|
1955 | * ```js
|
1956 | * import { Buffer } from 'buffer';
|
1957 | *
|
1958 | * const buf = Buffer.from('this is a buffer');
|
1959 | *
|
1960 | * console.log(buf.indexOf('this'));
|
1961 | * // Prints: 0
|
1962 | * console.log(buf.indexOf('is'));
|
1963 | * // Prints: 2
|
1964 | * console.log(buf.indexOf(Buffer.from('a buffer')));
|
1965 | * // Prints: 8
|
1966 | * console.log(buf.indexOf(97));
|
1967 | * // Prints: 8 (97 is the decimal ASCII value for 'a')
|
1968 | * console.log(buf.indexOf(Buffer.from('a buffer example')));
|
1969 | * // Prints: -1
|
1970 | * console.log(buf.indexOf(Buffer.from('a buffer example').slice(0, 8)));
|
1971 | * // Prints: 8
|
1972 | *
|
1973 | * const utf16Buffer = Buffer.from('\u039a\u0391\u03a3\u03a3\u0395', 'utf16le');
|
1974 | *
|
1975 | * console.log(utf16Buffer.indexOf('\u03a3', 0, 'utf16le'));
|
1976 | * // Prints: 4
|
1977 | * console.log(utf16Buffer.indexOf('\u03a3', -4, 'utf16le'));
|
1978 | * // Prints: 6
|
1979 | * ```
|
1980 | *
|
1981 | * If `value` is not a string, number, or `Buffer`, this method will throw a`TypeError`. If `value` is a number, it will be coerced to a valid byte value,
|
1982 | * an integer between 0 and 255.
|
1983 | *
|
1984 | * If `byteOffset` is not a number, it will be coerced to a number. If the result
|
1985 | * of coercion is `NaN` or `0`, then the entire buffer will be searched. This
|
1986 | * behavior matches [`String.prototype.indexOf()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/indexOf).
|
1987 | *
|
1988 | * ```js
|
1989 | * import { Buffer } from 'buffer';
|
1990 | *
|
1991 | * const b = Buffer.from('abcdef');
|
1992 | *
|
1993 | * // Passing a value that's a number, but not a valid byte.
|
1994 | * // Prints: 2, equivalent to searching for 99 or 'c'.
|
1995 | * console.log(b.indexOf(99.9));
|
1996 | * console.log(b.indexOf(256 + 99));
|
1997 | *
|
1998 | * // Passing a byteOffset that coerces to NaN or 0.
|
1999 | * // Prints: 1, searching the whole buffer.
|
2000 | * console.log(b.indexOf('b', undefined));
|
2001 | * console.log(b.indexOf('b', {}));
|
2002 | * console.log(b.indexOf('b', null));
|
2003 | * console.log(b.indexOf('b', []));
|
2004 | * ```
|
2005 | *
|
2006 | * If `value` is an empty string or empty `Buffer` and `byteOffset` is less
|
2007 | * than `buf.length`, `byteOffset` will be returned. If `value` is empty and`byteOffset` is at least `buf.length`, `buf.length` will be returned.
|
2008 | * @since v1.5.0
|
2009 | * @param value What to search for.
|
2010 | * @param [byteOffset=0] Where to begin searching in `buf`. If negative, then offset is calculated from the end of `buf`.
|
2011 | * @param [encoding='utf8'] If `value` is a string, this is the encoding used to determine the binary representation of the string that will be searched for in `buf`.
|
2012 | * @return The index of the first occurrence of `value` in `buf`, or `-1` if `buf` does not contain `value`.
|
2013 | */
|
2014 | indexOf(value: string | number | Uint8Array, byteOffset?: number, encoding?: BufferEncoding): number;
|
2015 | /**
|
2016 | * Identical to `buf.indexOf()`, except the last occurrence of `value` is found
|
2017 | * rather than the first occurrence.
|
2018 | *
|
2019 | * ```js
|
2020 | * import { Buffer } from 'buffer';
|
2021 | *
|
2022 | * const buf = Buffer.from('this buffer is a buffer');
|
2023 | *
|
2024 | * console.log(buf.lastIndexOf('this'));
|
2025 | * // Prints: 0
|
2026 | * console.log(buf.lastIndexOf('buffer'));
|
2027 | * // Prints: 17
|
2028 | * console.log(buf.lastIndexOf(Buffer.from('buffer')));
|
2029 | * // Prints: 17
|
2030 | * console.log(buf.lastIndexOf(97));
|
2031 | * // Prints: 15 (97 is the decimal ASCII value for 'a')
|
2032 | * console.log(buf.lastIndexOf(Buffer.from('yolo')));
|
2033 | * // Prints: -1
|
2034 | * console.log(buf.lastIndexOf('buffer', 5));
|
2035 | * // Prints: 5
|
2036 | * console.log(buf.lastIndexOf('buffer', 4));
|
2037 | * // Prints: -1
|
2038 | *
|
2039 | * const utf16Buffer = Buffer.from('\u039a\u0391\u03a3\u03a3\u0395', 'utf16le');
|
2040 | *
|
2041 | * console.log(utf16Buffer.lastIndexOf('\u03a3', undefined, 'utf16le'));
|
2042 | * // Prints: 6
|
2043 | * console.log(utf16Buffer.lastIndexOf('\u03a3', -5, 'utf16le'));
|
2044 | * // Prints: 4
|
2045 | * ```
|
2046 | *
|
2047 | * If `value` is not a string, number, or `Buffer`, this method will throw a`TypeError`. If `value` is a number, it will be coerced to a valid byte value,
|
2048 | * an integer between 0 and 255.
|
2049 | *
|
2050 | * If `byteOffset` is not a number, it will be coerced to a number. Any arguments
|
2051 | * that coerce to `NaN`, like `{}` or `undefined`, will search the whole buffer.
|
2052 | * This behavior matches [`String.prototype.lastIndexOf()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/lastIndexOf).
|
2053 | *
|
2054 | * ```js
|
2055 | * import { Buffer } from 'buffer';
|
2056 | *
|
2057 | * const b = Buffer.from('abcdef');
|
2058 | *
|
2059 | * // Passing a value that's a number, but not a valid byte.
|
2060 | * // Prints: 2, equivalent to searching for 99 or 'c'.
|
2061 | * console.log(b.lastIndexOf(99.9));
|
2062 | * console.log(b.lastIndexOf(256 + 99));
|
2063 | *
|
2064 | * // Passing a byteOffset that coerces to NaN.
|
2065 | * // Prints: 1, searching the whole buffer.
|
2066 | * console.log(b.lastIndexOf('b', undefined));
|
2067 | * console.log(b.lastIndexOf('b', {}));
|
2068 | *
|
2069 | * // Passing a byteOffset that coerces to 0.
|
2070 | * // Prints: -1, equivalent to passing 0.
|
2071 | * console.log(b.lastIndexOf('b', null));
|
2072 | * console.log(b.lastIndexOf('b', []));
|
2073 | * ```
|
2074 | *
|
2075 | * If `value` is an empty string or empty `Buffer`, `byteOffset` will be returned.
|
2076 | * @since v6.0.0
|
2077 | * @param value What to search for.
|
2078 | * @param [byteOffset=buf.length - 1] Where to begin searching in `buf`. If negative, then offset is calculated from the end of `buf`.
|
2079 | * @param [encoding='utf8'] If `value` is a string, this is the encoding used to determine the binary representation of the string that will be searched for in `buf`.
|
2080 | * @return The index of the last occurrence of `value` in `buf`, or `-1` if `buf` does not contain `value`.
|
2081 | */
|
2082 | lastIndexOf(value: string | number | Uint8Array, byteOffset?: number, encoding?: BufferEncoding): number;
|
2083 | /**
|
2084 | * Creates and returns an [iterator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols) of `[index, byte]` pairs from the contents
|
2085 | * of `buf`.
|
2086 | *
|
2087 | * ```js
|
2088 | * import { Buffer } from 'buffer';
|
2089 | *
|
2090 | * // Log the entire contents of a `Buffer`.
|
2091 | *
|
2092 | * const buf = Buffer.from('buffer');
|
2093 | *
|
2094 | * for (const pair of buf.entries()) {
|
2095 | * console.log(pair);
|
2096 | * }
|
2097 | * // Prints:
|
2098 | * // [0, 98]
|
2099 | * // [1, 117]
|
2100 | * // [2, 102]
|
2101 | * // [3, 102]
|
2102 | * // [4, 101]
|
2103 | * // [5, 114]
|
2104 | * ```
|
2105 | * @since v1.1.0
|
2106 | */
|
2107 | entries(): IterableIterator<[number, number]>;
|
2108 | /**
|
2109 | * Equivalent to `buf.indexOf() !== -1`.
|
2110 | *
|
2111 | * ```js
|
2112 | * import { Buffer } from 'buffer';
|
2113 | *
|
2114 | * const buf = Buffer.from('this is a buffer');
|
2115 | *
|
2116 | * console.log(buf.includes('this'));
|
2117 | * // Prints: true
|
2118 | * console.log(buf.includes('is'));
|
2119 | * // Prints: true
|
2120 | * console.log(buf.includes(Buffer.from('a buffer')));
|
2121 | * // Prints: true
|
2122 | * console.log(buf.includes(97));
|
2123 | * // Prints: true (97 is the decimal ASCII value for 'a')
|
2124 | * console.log(buf.includes(Buffer.from('a buffer example')));
|
2125 | * // Prints: false
|
2126 | * console.log(buf.includes(Buffer.from('a buffer example').slice(0, 8)));
|
2127 | * // Prints: true
|
2128 | * console.log(buf.includes('this', 4));
|
2129 | * // Prints: false
|
2130 | * ```
|
2131 | * @since v5.3.0
|
2132 | * @param value What to search for.
|
2133 | * @param [byteOffset=0] Where to begin searching in `buf`. If negative, then offset is calculated from the end of `buf`.
|
2134 | * @param [encoding='utf8'] If `value` is a string, this is its encoding.
|
2135 | * @return `true` if `value` was found in `buf`, `false` otherwise.
|
2136 | */
|
2137 | includes(value: string | number | Buffer, byteOffset?: number, encoding?: BufferEncoding): boolean;
|
2138 | /**
|
2139 | * Creates and returns an [iterator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols) of `buf` keys (indices).
|
2140 | *
|
2141 | * ```js
|
2142 | * import { Buffer } from 'buffer';
|
2143 | *
|
2144 | * const buf = Buffer.from('buffer');
|
2145 | *
|
2146 | * for (const key of buf.keys()) {
|
2147 | * console.log(key);
|
2148 | * }
|
2149 | * // Prints:
|
2150 | * // 0
|
2151 | * // 1
|
2152 | * // 2
|
2153 | * // 3
|
2154 | * // 4
|
2155 | * // 5
|
2156 | * ```
|
2157 | * @since v1.1.0
|
2158 | */
|
2159 | keys(): IterableIterator<number>;
|
2160 | /**
|
2161 | * Creates and returns an [iterator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols) for `buf` values (bytes). This function is
|
2162 | * called automatically when a `Buffer` is used in a `for..of` statement.
|
2163 | *
|
2164 | * ```js
|
2165 | * import { Buffer } from 'buffer';
|
2166 | *
|
2167 | * const buf = Buffer.from('buffer');
|
2168 | *
|
2169 | * for (const value of buf.values()) {
|
2170 | * console.log(value);
|
2171 | * }
|
2172 | * // Prints:
|
2173 | * // 98
|
2174 | * // 117
|
2175 | * // 102
|
2176 | * // 102
|
2177 | * // 101
|
2178 | * // 114
|
2179 | *
|
2180 | * for (const value of buf) {
|
2181 | * console.log(value);
|
2182 | * }
|
2183 | * // Prints:
|
2184 | * // 98
|
2185 | * // 117
|
2186 | * // 102
|
2187 | * // 102
|
2188 | * // 101
|
2189 | * // 114
|
2190 | * ```
|
2191 | * @since v1.1.0
|
2192 | */
|
2193 | values(): IterableIterator<number>;
|
2194 | }
|
2195 | var Buffer: BufferConstructor;
|
2196 | /**
|
2197 | * Decodes a string of Base64-encoded data into bytes, and encodes those bytes
|
2198 | * into a string using Latin-1 (ISO-8859-1).
|
2199 | *
|
2200 | * The `data` may be any JavaScript-value that can be coerced into a string.
|
2201 | *
|
2202 | * **This function is only provided for compatibility with legacy web platform APIs**
|
2203 | * **and should never be used in new code, because they use strings to represent**
|
2204 | * **binary data and predate the introduction of typed arrays in JavaScript.**
|
2205 | * **For code running using Node.js APIs, converting between base64-encoded strings**
|
2206 | * **and binary data should be performed using `Buffer.from(str, 'base64')` and`buf.toString('base64')`.**
|
2207 | * @since v15.13.0, v14.17.0
|
2208 | * @deprecated Use `Buffer.from(data, 'base64')` instead.
|
2209 | * @param data The Base64-encoded input string.
|
2210 | */
|
2211 | function atob(data: string): string;
|
2212 | /**
|
2213 | * Decodes a string into bytes using Latin-1 (ISO-8859), and encodes those bytes
|
2214 | * into a string using Base64.
|
2215 | *
|
2216 | * The `data` may be any JavaScript-value that can be coerced into a string.
|
2217 | *
|
2218 | * **This function is only provided for compatibility with legacy web platform APIs**
|
2219 | * **and should never be used in new code, because they use strings to represent**
|
2220 | * **binary data and predate the introduction of typed arrays in JavaScript.**
|
2221 | * **For code running using Node.js APIs, converting between base64-encoded strings**
|
2222 | * **and binary data should be performed using `Buffer.from(str, 'base64')` and`buf.toString('base64')`.**
|
2223 | * @since v15.13.0, v14.17.0
|
2224 | * @deprecated Use `buf.toString('base64')` instead.
|
2225 | * @param data An ASCII (Latin1) string.
|
2226 | */
|
2227 | function btoa(data: string): string;
|
2228 | }
|
2229 | }
|
2230 | declare module 'node:buffer' {
|
2231 | export * from 'buffer';
|
2232 | }
|
2233 |
|
\ | No newline at end of file |