@types/node 16.18.86 → 16.18.88

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