@types/node 18.19.17 → 18.19.19

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.
node v18.19/buffer.d.ts CHANGED
@@ -10,7 +10,7 @@
10
10
  * recommended to explicitly reference it via an import or require statement.
11
11
  *
12
12
  * ```js
13
- * import { Buffer } from 'buffer';
13
+ * import { Buffer } from 'node:buffer';
14
14
  *
15
15
  * // Creates a zero-filled Buffer of length 10.
16
16
  * const buf1 = Buffer.alloc(10);
@@ -41,12 +41,28 @@
41
41
  * // Creates a Buffer containing the Latin-1 bytes [0x74, 0xe9, 0x73, 0x74].
42
42
  * const buf7 = Buffer.from('tést', 'latin1');
43
43
  * ```
44
- * @see [source](https://github.com/nodejs/node/blob/v18.0.0/lib/buffer.js)
44
+ * @see [source](https://github.com/nodejs/node/blob/v18.19.0/lib/buffer.js)
45
45
  */
46
46
  declare module "buffer" {
47
47
  import { BinaryLike } from "node:crypto";
48
48
  import { ReadableStream as WebReadableStream } from "node:stream/web";
49
+ /**
50
+ * This function returns `true` if `input` contains only valid UTF-8-encoded data,
51
+ * including the case in which `input` is empty.
52
+ *
53
+ * Throws if the `input` is a detached array buffer.
54
+ * @since v18.14.0
55
+ * @param input The input to validate.
56
+ */
49
57
  export function isUtf8(input: Buffer | ArrayBuffer | NodeJS.TypedArray): boolean;
58
+ /**
59
+ * This function returns `true` if `input` contains only valid ASCII-encoded data,
60
+ * including the case in which `input` is empty.
61
+ *
62
+ * Throws if the `input` is a detached array buffer.
63
+ * @since v18.15.0
64
+ * @param input The input to validate.
65
+ */
50
66
  export function isAscii(input: Buffer | ArrayBuffer | NodeJS.TypedArray): boolean;
51
67
  export const INSPECT_MAX_BYTES: number;
52
68
  export const kMaxLength: number;
@@ -69,7 +85,7 @@ declare module "buffer" {
69
85
  * sequence cannot be adequately represented in the target encoding. For instance:
70
86
  *
71
87
  * ```js
72
- * import { Buffer, transcode } from 'buffer';
88
+ * import { Buffer, transcode } from 'node:buffer';
73
89
  *
74
90
  * const newBuf = transcode(Buffer.from('€'), 'utf8', 'ascii');
75
91
  * console.log(newBuf.toString('ascii'));
@@ -103,9 +119,10 @@ declare module "buffer" {
103
119
  */
104
120
  export interface BlobOptions {
105
121
  /**
106
- * @default 'utf8'
122
+ * One of either `'transparent'` or `'native'`. When set to `'native'`, line endings in string source parts
123
+ * will be converted to the platform native line-ending as specified by `require('node:os').EOL`.
107
124
  */
108
- encoding?: BufferEncoding | undefined;
125
+ endings?: "transparent" | "native";
109
126
  /**
110
127
  * The Blob content-type. The intent is for `type` to convey
111
128
  * the MIME media type of the data, however no validation of the type format
@@ -137,7 +154,7 @@ declare module "buffer" {
137
154
  *
138
155
  * String sources are also copied into the `Blob`.
139
156
  */
140
- constructor(sources: Array<BinaryLike | Blob>, options?: BlobOptions);
157
+ constructor(sources: Array<ArrayBuffer | BinaryLike | Blob>, options?: BlobOptions);
141
158
  /**
142
159
  * 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
143
160
  * the `Blob` data.
@@ -160,7 +177,7 @@ declare module "buffer" {
160
177
  */
161
178
  text(): Promise<string>;
162
179
  /**
163
- * Returns a new (WHATWG) `ReadableStream` that allows the content of the `Blob` to be read.
180
+ * Returns a new `ReadableStream` that allows the content of the `Blob` to be read.
164
181
  * @since v16.7.0
165
182
  */
166
183
  stream(): WebReadableStream;
@@ -178,7 +195,6 @@ declare module "buffer" {
178
195
  }
179
196
  /**
180
197
  * A [`File`](https://developer.mozilla.org/en-US/docs/Web/API/File) provides information about files.
181
- * @experimental
182
198
  * @since v18.13.0
183
199
  */
184
200
  export class File extends Blob {
@@ -196,7 +212,6 @@ declare module "buffer" {
196
212
  }
197
213
  export import atob = globalThis.atob;
198
214
  export import btoa = globalThis.btoa;
199
-
200
215
  import { Blob as NodeBlob } from "buffer";
201
216
  // This conditional type will be the existing global Blob in a browser, or
202
217
  // the copy below in a Node environment.
@@ -278,12 +293,16 @@ declare module "buffer" {
278
293
  * Array entries outside that range will be truncated to fit into it.
279
294
  *
280
295
  * ```js
281
- * import { Buffer } from 'buffer';
296
+ * import { Buffer } from 'node:buffer';
282
297
  *
283
298
  * // Creates a new Buffer containing the UTF-8 bytes of the string 'buffer'.
284
299
  * const buf = Buffer.from([0x62, 0x75, 0x66, 0x66, 0x65, 0x72]);
285
300
  * ```
286
301
  *
302
+ * If `array` is an `Array`\-like object (that is, one with a `length` property of
303
+ * type `number`), it is treated as if it is an array, unless it is a `Buffer` or
304
+ * a `Uint8Array`. This means all other `TypedArray` variants get treated as an`Array`. To create a `Buffer` from the bytes backing a `TypedArray`, use `Buffer.copyBytesFrom()`.
305
+ *
287
306
  * A `TypeError` will be thrown if `array` is not an `Array` or another type
288
307
  * appropriate for `Buffer.from()` variants.
289
308
  *
@@ -323,7 +342,7 @@ declare module "buffer" {
323
342
  * Returns `true` if `obj` is a `Buffer`, `false` otherwise.
324
343
  *
325
344
  * ```js
326
- * import { Buffer } from 'buffer';
345
+ * import { Buffer } from 'node:buffer';
327
346
  *
328
347
  * Buffer.isBuffer(Buffer.alloc(10)); // true
329
348
  * Buffer.isBuffer(Buffer.from('foo')); // true
@@ -339,7 +358,7 @@ declare module "buffer" {
339
358
  * or `false` otherwise.
340
359
  *
341
360
  * ```js
342
- * import { Buffer } from 'buffer';
361
+ * import { Buffer } from 'node:buffer';
343
362
  *
344
363
  * console.log(Buffer.isEncoding('utf8'));
345
364
  * // Prints: true
@@ -368,7 +387,7 @@ declare module "buffer" {
368
387
  * string.
369
388
  *
370
389
  * ```js
371
- * import { Buffer } from 'buffer';
390
+ * import { Buffer } from 'node:buffer';
372
391
  *
373
392
  * const str = '\u00bd + \u00bc = \u00be';
374
393
  *
@@ -387,7 +406,7 @@ declare module "buffer" {
387
406
  * @return The number of bytes contained within `string`.
388
407
  */
389
408
  byteLength(
390
- string: string | NodeJS.ArrayBufferView | ArrayBuffer | SharedArrayBuffer,
409
+ string: string | Buffer | NodeJS.ArrayBufferView | ArrayBuffer | SharedArrayBuffer,
391
410
  encoding?: BufferEncoding,
392
411
  ): number;
393
412
  /**
@@ -403,7 +422,7 @@ declare module "buffer" {
403
422
  * truncated to `totalLength`.
404
423
  *
405
424
  * ```js
406
- * import { Buffer } from 'buffer';
425
+ * import { Buffer } from 'node:buffer';
407
426
  *
408
427
  * // Create a single `Buffer` from a list of three `Buffer` instances.
409
428
  *
@@ -431,17 +450,26 @@ declare module "buffer" {
431
450
  concat(list: readonly Uint8Array[], totalLength?: number): Buffer;
432
451
  /**
433
452
  * Copies the underlying memory of `view` into a new `Buffer`.
453
+ *
454
+ * ```js
455
+ * const u16 = new Uint16Array([0, 0xffff]);
456
+ * const buf = Buffer.copyBytesFrom(u16, 1, 1);
457
+ * u16[1] = 0;
458
+ * console.log(buf.length); // 2
459
+ * console.log(buf[0]); // 255
460
+ * console.log(buf[1]); // 255
461
+ * ```
434
462
  * @since v18.16.0
435
- * @param view The `TypedArray` to copy.
436
- * @param offset The starting offset within `view`.
437
- * @param length The number of elements from `view` to copy.
463
+ * @param view The {TypedArray} to copy.
464
+ * @param [offset=0] The starting offset within `view`.
465
+ * @param [length=view.length - offset] The number of elements from `view` to copy.
438
466
  */
439
467
  copyBytesFrom(view: NodeJS.TypedArray, offset?: number, length?: number): Buffer;
440
468
  /**
441
469
  * Compares `buf1` to `buf2`, typically for the purpose of sorting arrays of`Buffer` instances. This is equivalent to calling `buf1.compare(buf2)`.
442
470
  *
443
471
  * ```js
444
- * import { Buffer } from 'buffer';
472
+ * import { Buffer } from 'node:buffer';
445
473
  *
446
474
  * const buf1 = Buffer.from('1234');
447
475
  * const buf2 = Buffer.from('0123');
@@ -459,7 +487,7 @@ declare module "buffer" {
459
487
  * Allocates a new `Buffer` of `size` bytes. If `fill` is `undefined`, the`Buffer` will be zero-filled.
460
488
  *
461
489
  * ```js
462
- * import { Buffer } from 'buffer';
490
+ * import { Buffer } from 'node:buffer';
463
491
  *
464
492
  * const buf = Buffer.alloc(5);
465
493
  *
@@ -467,12 +495,12 @@ declare module "buffer" {
467
495
  * // Prints: <Buffer 00 00 00 00 00>
468
496
  * ```
469
497
  *
470
- * If `size` is larger than {@link constants.MAX_LENGTH} or smaller than 0, `ERR_INVALID_ARG_VALUE` is thrown.
498
+ * If `size` is larger than {@link constants.MAX_LENGTH} or smaller than 0, `ERR_OUT_OF_RANGE` is thrown.
471
499
  *
472
500
  * If `fill` is specified, the allocated `Buffer` will be initialized by calling `buf.fill(fill)`.
473
501
  *
474
502
  * ```js
475
- * import { Buffer } from 'buffer';
503
+ * import { Buffer } from 'node:buffer';
476
504
  *
477
505
  * const buf = Buffer.alloc(5, 'a');
478
506
  *
@@ -484,7 +512,7 @@ declare module "buffer" {
484
512
  * initialized by calling `buf.fill(fill, encoding)`.
485
513
  *
486
514
  * ```js
487
- * import { Buffer } from 'buffer';
515
+ * import { Buffer } from 'node:buffer';
488
516
  *
489
517
  * const buf = Buffer.alloc(11, 'aGVsbG8gd29ybGQ=', 'base64');
490
518
  *
@@ -504,13 +532,13 @@ declare module "buffer" {
504
532
  */
505
533
  alloc(size: number, fill?: string | Uint8Array | number, encoding?: BufferEncoding): Buffer;
506
534
  /**
507
- * 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.
535
+ * Allocates a new `Buffer` of `size` bytes. If `size` is larger than {@link constants.MAX_LENGTH} or smaller than 0, `ERR_OUT_OF_RANGE` is thrown.
508
536
  *
509
537
  * The underlying memory for `Buffer` instances created in this way is _not_
510
538
  * _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.
511
539
  *
512
540
  * ```js
513
- * import { Buffer } from 'buffer';
541
+ * import { Buffer } from 'node:buffer';
514
542
  *
515
543
  * const buf = Buffer.allocUnsafe(10);
516
544
  *
@@ -526,9 +554,8 @@ declare module "buffer" {
526
554
  * A `TypeError` will be thrown if `size` is not a number.
527
555
  *
528
556
  * The `Buffer` module pre-allocates an internal `Buffer` instance of
529
- * 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
530
- * deprecated`new Buffer(size)` constructor only when `size` is less than or equal
531
- * to `Buffer.poolSize >> 1` (floor of `Buffer.poolSize` divided by two).
557
+ * size `Buffer.poolSize` that is used as a pool for the fast allocation of new `Buffer` instances created using `Buffer.allocUnsafe()`, `Buffer.from(array)`,
558
+ * and `Buffer.concat()` only when `size` is less than `Buffer.poolSize >> 1` (floor of `Buffer.poolSize` divided by two).
532
559
  *
533
560
  * Use of this pre-allocated internal memory pool is a key difference between
534
561
  * calling `Buffer.alloc(size, fill)` vs. `Buffer.allocUnsafe(size).fill(fill)`.
@@ -541,15 +568,15 @@ declare module "buffer" {
541
568
  */
542
569
  allocUnsafe(size: number): Buffer;
543
570
  /**
544
- * 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
545
- * if `size` is 0.
571
+ * Allocates a new `Buffer` of `size` bytes. If `size` is larger than {@link constants.MAX_LENGTH} or smaller than 0, `ERR_OUT_OF_RANGE` is thrown. A zero-length `Buffer` is created if
572
+ * `size` is 0.
546
573
  *
547
574
  * The underlying memory for `Buffer` instances created in this way is _not_
548
575
  * _initialized_. The contents of the newly created `Buffer` are unknown and _may contain sensitive data_. Use `buf.fill(0)` to initialize
549
576
  * such `Buffer` instances with zeroes.
550
577
  *
551
578
  * When using `Buffer.allocUnsafe()` to allocate new `Buffer` instances,
552
- * allocations under 4 KB are sliced from a single pre-allocated `Buffer`. This
579
+ * allocations under 4 KiB are sliced from a single pre-allocated `Buffer`. This
553
580
  * allows applications to avoid the garbage collection overhead of creating many
554
581
  * individually allocated `Buffer` instances. This approach improves both
555
582
  * performance and memory usage by eliminating the need to track and clean up as
@@ -561,7 +588,7 @@ declare module "buffer" {
561
588
  * then copying out the relevant bits.
562
589
  *
563
590
  * ```js
564
- * import { Buffer } from 'buffer';
591
+ * import { Buffer } from 'node:buffer';
565
592
  *
566
593
  * // Need to keep around a few small chunks of memory.
567
594
  * const store = [];
@@ -599,7 +626,7 @@ declare module "buffer" {
599
626
  * written. However, partially encoded characters will not be written.
600
627
  *
601
628
  * ```js
602
- * import { Buffer } from 'buffer';
629
+ * import { Buffer } from 'node:buffer';
603
630
  *
604
631
  * const buf = Buffer.alloc(256);
605
632
  *
@@ -635,7 +662,7 @@ declare module "buffer" {
635
662
  * as {@link constants.MAX_STRING_LENGTH}.
636
663
  *
637
664
  * ```js
638
- * import { Buffer } from 'buffer';
665
+ * import { Buffer } from 'node:buffer';
639
666
  *
640
667
  * const buf1 = Buffer.allocUnsafe(26);
641
668
  *
@@ -672,7 +699,7 @@ declare module "buffer" {
672
699
  * In particular, `Buffer.from(buf.toJSON())` works like `Buffer.from(buf)`.
673
700
  *
674
701
  * ```js
675
- * import { Buffer } from 'buffer';
702
+ * import { Buffer } from 'node:buffer';
676
703
  *
677
704
  * const buf = Buffer.from([0x1, 0x2, 0x3, 0x4, 0x5]);
678
705
  * const json = JSON.stringify(buf);
@@ -699,7 +726,7 @@ declare module "buffer" {
699
726
  * Returns `true` if both `buf` and `otherBuffer` have exactly the same bytes,`false` otherwise. Equivalent to `buf.compare(otherBuffer) === 0`.
700
727
  *
701
728
  * ```js
702
- * import { Buffer } from 'buffer';
729
+ * import { Buffer } from 'node:buffer';
703
730
  *
704
731
  * const buf1 = Buffer.from('ABC');
705
732
  * const buf2 = Buffer.from('414243', 'hex');
@@ -723,7 +750,7 @@ declare module "buffer" {
723
750
  * * `-1` is returned if `target` should come _after_`buf` when sorted.
724
751
  *
725
752
  * ```js
726
- * import { Buffer } from 'buffer';
753
+ * import { Buffer } from 'node:buffer';
727
754
  *
728
755
  * const buf1 = Buffer.from('ABC');
729
756
  * const buf2 = Buffer.from('BCD');
@@ -747,7 +774,7 @@ declare module "buffer" {
747
774
  * The optional `targetStart`, `targetEnd`, `sourceStart`, and `sourceEnd`arguments can be used to limit the comparison to specific ranges within `target`and `buf` respectively.
748
775
  *
749
776
  * ```js
750
- * import { Buffer } from 'buffer';
777
+ * import { Buffer } from 'node:buffer';
751
778
  *
752
779
  * const buf1 = Buffer.from([1, 2, 3, 4, 5, 6, 7, 8, 9]);
753
780
  * const buf2 = Buffer.from([5, 6, 7, 8, 9, 1, 2, 3, 4]);
@@ -783,7 +810,7 @@ declare module "buffer" {
783
810
  * different function arguments.
784
811
  *
785
812
  * ```js
786
- * import { Buffer } from 'buffer';
813
+ * import { Buffer } from 'node:buffer';
787
814
  *
788
815
  * // Create two `Buffer` instances.
789
816
  * const buf1 = Buffer.allocUnsafe(26);
@@ -804,7 +831,7 @@ declare module "buffer" {
804
831
  * ```
805
832
  *
806
833
  * ```js
807
- * import { Buffer } from 'buffer';
834
+ * import { Buffer } from 'node:buffer';
808
835
  *
809
836
  * // Create a `Buffer` and copy data from one region to an overlapping region
810
837
  * // within the same `Buffer`.
@@ -837,7 +864,7 @@ declare module "buffer" {
837
864
  * which is a superclass of `Buffer`. To copy the slice, use`Uint8Array.prototype.slice()`.
838
865
  *
839
866
  * ```js
840
- * import { Buffer } from 'buffer';
867
+ * import { Buffer } from 'node:buffer';
841
868
  *
842
869
  * const buf = Buffer.from('buffer');
843
870
  *
@@ -875,7 +902,7 @@ declare module "buffer" {
875
902
  * Modifying the new `Buffer` slice will modify the memory in the original `Buffer`because the allocated memory of the two objects overlap.
876
903
  *
877
904
  * ```js
878
- * import { Buffer } from 'buffer';
905
+ * import { Buffer } from 'node:buffer';
879
906
  *
880
907
  * // Create a `Buffer` with the ASCII alphabet, take a slice, and modify one byte
881
908
  * // from the original `Buffer`.
@@ -902,7 +929,7 @@ declare module "buffer" {
902
929
  * end of `buf` rather than the beginning.
903
930
  *
904
931
  * ```js
905
- * import { Buffer } from 'buffer';
932
+ * import { Buffer } from 'node:buffer';
906
933
  *
907
934
  * const buf = Buffer.from('buffer');
908
935
  *
@@ -929,7 +956,7 @@ declare module "buffer" {
929
956
  * `value` is interpreted and written as a two's complement signed integer.
930
957
  *
931
958
  * ```js
932
- * import { Buffer } from 'buffer';
959
+ * import { Buffer } from 'node:buffer';
933
960
  *
934
961
  * const buf = Buffer.allocUnsafe(8);
935
962
  *
@@ -950,7 +977,7 @@ declare module "buffer" {
950
977
  * `value` is interpreted and written as a two's complement signed integer.
951
978
  *
952
979
  * ```js
953
- * import { Buffer } from 'buffer';
980
+ * import { Buffer } from 'node:buffer';
954
981
  *
955
982
  * const buf = Buffer.allocUnsafe(8);
956
983
  *
@@ -971,7 +998,7 @@ declare module "buffer" {
971
998
  * This function is also available under the `writeBigUint64BE` alias.
972
999
  *
973
1000
  * ```js
974
- * import { Buffer } from 'buffer';
1001
+ * import { Buffer } from 'node:buffer';
975
1002
  *
976
1003
  * const buf = Buffer.allocUnsafe(8);
977
1004
  *
@@ -995,7 +1022,7 @@ declare module "buffer" {
995
1022
  * Writes `value` to `buf` at the specified `offset` as little-endian
996
1023
  *
997
1024
  * ```js
998
- * import { Buffer } from 'buffer';
1025
+ * import { Buffer } from 'node:buffer';
999
1026
  *
1000
1027
  * const buf = Buffer.allocUnsafe(8);
1001
1028
  *
@@ -1024,7 +1051,7 @@ declare module "buffer" {
1024
1051
  * This function is also available under the `writeUintLE` alias.
1025
1052
  *
1026
1053
  * ```js
1027
- * import { Buffer } from 'buffer';
1054
+ * import { Buffer } from 'node:buffer';
1028
1055
  *
1029
1056
  * const buf = Buffer.allocUnsafe(6);
1030
1057
  *
@@ -1052,7 +1079,7 @@ declare module "buffer" {
1052
1079
  * This function is also available under the `writeUintBE` alias.
1053
1080
  *
1054
1081
  * ```js
1055
- * import { Buffer } from 'buffer';
1082
+ * import { Buffer } from 'node:buffer';
1056
1083
  *
1057
1084
  * const buf = Buffer.allocUnsafe(6);
1058
1085
  *
@@ -1078,7 +1105,7 @@ declare module "buffer" {
1078
1105
  * when `value` is anything other than a signed integer.
1079
1106
  *
1080
1107
  * ```js
1081
- * import { Buffer } from 'buffer';
1108
+ * import { Buffer } from 'node:buffer';
1082
1109
  *
1083
1110
  * const buf = Buffer.allocUnsafe(6);
1084
1111
  *
@@ -1099,7 +1126,7 @@ declare module "buffer" {
1099
1126
  * signed integer.
1100
1127
  *
1101
1128
  * ```js
1102
- * import { Buffer } from 'buffer';
1129
+ * import { Buffer } from 'node:buffer';
1103
1130
  *
1104
1131
  * const buf = Buffer.allocUnsafe(6);
1105
1132
  *
@@ -1121,7 +1148,7 @@ declare module "buffer" {
1121
1148
  * This function is also available under the `readBigUint64BE` alias.
1122
1149
  *
1123
1150
  * ```js
1124
- * import { Buffer } from 'buffer';
1151
+ * import { Buffer } from 'node:buffer';
1125
1152
  *
1126
1153
  * const buf = Buffer.from([0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff]);
1127
1154
  *
@@ -1143,7 +1170,7 @@ declare module "buffer" {
1143
1170
  * This function is also available under the `readBigUint64LE` alias.
1144
1171
  *
1145
1172
  * ```js
1146
- * import { Buffer } from 'buffer';
1173
+ * import { Buffer } from 'node:buffer';
1147
1174
  *
1148
1175
  * const buf = Buffer.from([0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff]);
1149
1176
  *
@@ -1184,7 +1211,7 @@ declare module "buffer" {
1184
1211
  * This function is also available under the `readUintLE` alias.
1185
1212
  *
1186
1213
  * ```js
1187
- * import { Buffer } from 'buffer';
1214
+ * import { Buffer } from 'node:buffer';
1188
1215
  *
1189
1216
  * const buf = Buffer.from([0x12, 0x34, 0x56, 0x78, 0x90, 0xab]);
1190
1217
  *
@@ -1208,7 +1235,7 @@ declare module "buffer" {
1208
1235
  * This function is also available under the `readUintBE` alias.
1209
1236
  *
1210
1237
  * ```js
1211
- * import { Buffer } from 'buffer';
1238
+ * import { Buffer } from 'node:buffer';
1212
1239
  *
1213
1240
  * const buf = Buffer.from([0x12, 0x34, 0x56, 0x78, 0x90, 0xab]);
1214
1241
  *
@@ -1232,7 +1259,7 @@ declare module "buffer" {
1232
1259
  * supporting up to 48 bits of accuracy.
1233
1260
  *
1234
1261
  * ```js
1235
- * import { Buffer } from 'buffer';
1262
+ * import { Buffer } from 'node:buffer';
1236
1263
  *
1237
1264
  * const buf = Buffer.from([0x12, 0x34, 0x56, 0x78, 0x90, 0xab]);
1238
1265
  *
@@ -1249,7 +1276,7 @@ declare module "buffer" {
1249
1276
  * supporting up to 48 bits of accuracy.
1250
1277
  *
1251
1278
  * ```js
1252
- * import { Buffer } from 'buffer';
1279
+ * import { Buffer } from 'node:buffer';
1253
1280
  *
1254
1281
  * const buf = Buffer.from([0x12, 0x34, 0x56, 0x78, 0x90, 0xab]);
1255
1282
  *
@@ -1271,7 +1298,7 @@ declare module "buffer" {
1271
1298
  * This function is also available under the `readUint8` alias.
1272
1299
  *
1273
1300
  * ```js
1274
- * import { Buffer } from 'buffer';
1301
+ * import { Buffer } from 'node:buffer';
1275
1302
  *
1276
1303
  * const buf = Buffer.from([1, -2]);
1277
1304
  *
@@ -1297,7 +1324,7 @@ declare module "buffer" {
1297
1324
  * This function is also available under the `readUint16LE` alias.
1298
1325
  *
1299
1326
  * ```js
1300
- * import { Buffer } from 'buffer';
1327
+ * import { Buffer } from 'node:buffer';
1301
1328
  *
1302
1329
  * const buf = Buffer.from([0x12, 0x34, 0x56]);
1303
1330
  *
@@ -1323,7 +1350,7 @@ declare module "buffer" {
1323
1350
  * This function is also available under the `readUint16BE` alias.
1324
1351
  *
1325
1352
  * ```js
1326
- * import { Buffer } from 'buffer';
1353
+ * import { Buffer } from 'node:buffer';
1327
1354
  *
1328
1355
  * const buf = Buffer.from([0x12, 0x34, 0x56]);
1329
1356
  *
@@ -1347,7 +1374,7 @@ declare module "buffer" {
1347
1374
  * This function is also available under the `readUint32LE` alias.
1348
1375
  *
1349
1376
  * ```js
1350
- * import { Buffer } from 'buffer';
1377
+ * import { Buffer } from 'node:buffer';
1351
1378
  *
1352
1379
  * const buf = Buffer.from([0x12, 0x34, 0x56, 0x78]);
1353
1380
  *
@@ -1371,7 +1398,7 @@ declare module "buffer" {
1371
1398
  * This function is also available under the `readUint32BE` alias.
1372
1399
  *
1373
1400
  * ```js
1374
- * import { Buffer } from 'buffer';
1401
+ * import { Buffer } from 'node:buffer';
1375
1402
  *
1376
1403
  * const buf = Buffer.from([0x12, 0x34, 0x56, 0x78]);
1377
1404
  *
@@ -1393,7 +1420,7 @@ declare module "buffer" {
1393
1420
  * Integers read from a `Buffer` are interpreted as two's complement signed values.
1394
1421
  *
1395
1422
  * ```js
1396
- * import { Buffer } from 'buffer';
1423
+ * import { Buffer } from 'node:buffer';
1397
1424
  *
1398
1425
  * const buf = Buffer.from([-1, 5]);
1399
1426
  *
@@ -1414,7 +1441,7 @@ declare module "buffer" {
1414
1441
  * Integers read from a `Buffer` are interpreted as two's complement signed values.
1415
1442
  *
1416
1443
  * ```js
1417
- * import { Buffer } from 'buffer';
1444
+ * import { Buffer } from 'node:buffer';
1418
1445
  *
1419
1446
  * const buf = Buffer.from([0, 5]);
1420
1447
  *
@@ -1433,7 +1460,7 @@ declare module "buffer" {
1433
1460
  * Integers read from a `Buffer` are interpreted as two's complement signed values.
1434
1461
  *
1435
1462
  * ```js
1436
- * import { Buffer } from 'buffer';
1463
+ * import { Buffer } from 'node:buffer';
1437
1464
  *
1438
1465
  * const buf = Buffer.from([0, 5]);
1439
1466
  *
@@ -1450,7 +1477,7 @@ declare module "buffer" {
1450
1477
  * Integers read from a `Buffer` are interpreted as two's complement signed values.
1451
1478
  *
1452
1479
  * ```js
1453
- * import { Buffer } from 'buffer';
1480
+ * import { Buffer } from 'node:buffer';
1454
1481
  *
1455
1482
  * const buf = Buffer.from([0, 0, 0, 5]);
1456
1483
  *
@@ -1469,7 +1496,7 @@ declare module "buffer" {
1469
1496
  * Integers read from a `Buffer` are interpreted as two's complement signed values.
1470
1497
  *
1471
1498
  * ```js
1472
- * import { Buffer } from 'buffer';
1499
+ * import { Buffer } from 'node:buffer';
1473
1500
  *
1474
1501
  * const buf = Buffer.from([0, 0, 0, 5]);
1475
1502
  *
@@ -1484,7 +1511,7 @@ declare module "buffer" {
1484
1511
  * Reads a 32-bit, little-endian float from `buf` at the specified `offset`.
1485
1512
  *
1486
1513
  * ```js
1487
- * import { Buffer } from 'buffer';
1514
+ * import { Buffer } from 'node:buffer';
1488
1515
  *
1489
1516
  * const buf = Buffer.from([1, 2, 3, 4]);
1490
1517
  *
@@ -1501,7 +1528,7 @@ declare module "buffer" {
1501
1528
  * Reads a 32-bit, big-endian float from `buf` at the specified `offset`.
1502
1529
  *
1503
1530
  * ```js
1504
- * import { Buffer } from 'buffer';
1531
+ * import { Buffer } from 'node:buffer';
1505
1532
  *
1506
1533
  * const buf = Buffer.from([1, 2, 3, 4]);
1507
1534
  *
@@ -1516,7 +1543,7 @@ declare module "buffer" {
1516
1543
  * Reads a 64-bit, little-endian double from `buf` at the specified `offset`.
1517
1544
  *
1518
1545
  * ```js
1519
- * import { Buffer } from 'buffer';
1546
+ * import { Buffer } from 'node:buffer';
1520
1547
  *
1521
1548
  * const buf = Buffer.from([1, 2, 3, 4, 5, 6, 7, 8]);
1522
1549
  *
@@ -1533,7 +1560,7 @@ declare module "buffer" {
1533
1560
  * Reads a 64-bit, big-endian double from `buf` at the specified `offset`.
1534
1561
  *
1535
1562
  * ```js
1536
- * import { Buffer } from 'buffer';
1563
+ * import { Buffer } from 'node:buffer';
1537
1564
  *
1538
1565
  * const buf = Buffer.from([1, 2, 3, 4, 5, 6, 7, 8]);
1539
1566
  *
@@ -1550,7 +1577,7 @@ declare module "buffer" {
1550
1577
  * byte order _in-place_. Throws `ERR_INVALID_BUFFER_SIZE` if `buf.length` is not a multiple of 2.
1551
1578
  *
1552
1579
  * ```js
1553
- * import { Buffer } from 'buffer';
1580
+ * import { Buffer } from 'node:buffer';
1554
1581
  *
1555
1582
  * const buf1 = Buffer.from([0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8]);
1556
1583
  *
@@ -1572,7 +1599,7 @@ declare module "buffer" {
1572
1599
  * between UTF-16 little-endian and UTF-16 big-endian:
1573
1600
  *
1574
1601
  * ```js
1575
- * import { Buffer } from 'buffer';
1602
+ * import { Buffer } from 'node:buffer';
1576
1603
  *
1577
1604
  * const buf = Buffer.from('This is little-endian UTF-16', 'utf16le');
1578
1605
  * buf.swap16(); // Convert to big-endian UTF-16 text.
@@ -1586,7 +1613,7 @@ declare module "buffer" {
1586
1613
  * byte order _in-place_. Throws `ERR_INVALID_BUFFER_SIZE` if `buf.length` is not a multiple of 4.
1587
1614
  *
1588
1615
  * ```js
1589
- * import { Buffer } from 'buffer';
1616
+ * import { Buffer } from 'node:buffer';
1590
1617
  *
1591
1618
  * const buf1 = Buffer.from([0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8]);
1592
1619
  *
@@ -1612,7 +1639,7 @@ declare module "buffer" {
1612
1639
  * Throws `ERR_INVALID_BUFFER_SIZE` if `buf.length` is not a multiple of 8.
1613
1640
  *
1614
1641
  * ```js
1615
- * import { Buffer } from 'buffer';
1642
+ * import { Buffer } from 'node:buffer';
1616
1643
  *
1617
1644
  * const buf1 = Buffer.from([0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8]);
1618
1645
  *
@@ -1641,7 +1668,7 @@ declare module "buffer" {
1641
1668
  * This function is also available under the `writeUint8` alias.
1642
1669
  *
1643
1670
  * ```js
1644
- * import { Buffer } from 'buffer';
1671
+ * import { Buffer } from 'node:buffer';
1645
1672
  *
1646
1673
  * const buf = Buffer.allocUnsafe(4);
1647
1674
  *
@@ -1671,7 +1698,7 @@ declare module "buffer" {
1671
1698
  * This function is also available under the `writeUint16LE` alias.
1672
1699
  *
1673
1700
  * ```js
1674
- * import { Buffer } from 'buffer';
1701
+ * import { Buffer } from 'node:buffer';
1675
1702
  *
1676
1703
  * const buf = Buffer.allocUnsafe(4);
1677
1704
  *
@@ -1699,7 +1726,7 @@ declare module "buffer" {
1699
1726
  * This function is also available under the `writeUint16BE` alias.
1700
1727
  *
1701
1728
  * ```js
1702
- * import { Buffer } from 'buffer';
1729
+ * import { Buffer } from 'node:buffer';
1703
1730
  *
1704
1731
  * const buf = Buffer.allocUnsafe(4);
1705
1732
  *
@@ -1727,7 +1754,7 @@ declare module "buffer" {
1727
1754
  * This function is also available under the `writeUint32LE` alias.
1728
1755
  *
1729
1756
  * ```js
1730
- * import { Buffer } from 'buffer';
1757
+ * import { Buffer } from 'node:buffer';
1731
1758
  *
1732
1759
  * const buf = Buffer.allocUnsafe(4);
1733
1760
  *
@@ -1754,7 +1781,7 @@ declare module "buffer" {
1754
1781
  * This function is also available under the `writeUint32BE` alias.
1755
1782
  *
1756
1783
  * ```js
1757
- * import { Buffer } from 'buffer';
1784
+ * import { Buffer } from 'node:buffer';
1758
1785
  *
1759
1786
  * const buf = Buffer.allocUnsafe(4);
1760
1787
  *
@@ -1782,7 +1809,7 @@ declare module "buffer" {
1782
1809
  * `value` is interpreted and written as a two's complement signed integer.
1783
1810
  *
1784
1811
  * ```js
1785
- * import { Buffer } from 'buffer';
1812
+ * import { Buffer } from 'node:buffer';
1786
1813
  *
1787
1814
  * const buf = Buffer.allocUnsafe(2);
1788
1815
  *
@@ -1805,7 +1832,7 @@ declare module "buffer" {
1805
1832
  * The `value` is interpreted and written as a two's complement signed integer.
1806
1833
  *
1807
1834
  * ```js
1808
- * import { Buffer } from 'buffer';
1835
+ * import { Buffer } from 'node:buffer';
1809
1836
  *
1810
1837
  * const buf = Buffer.allocUnsafe(2);
1811
1838
  *
@@ -1827,7 +1854,7 @@ declare module "buffer" {
1827
1854
  * The `value` is interpreted and written as a two's complement signed integer.
1828
1855
  *
1829
1856
  * ```js
1830
- * import { Buffer } from 'buffer';
1857
+ * import { Buffer } from 'node:buffer';
1831
1858
  *
1832
1859
  * const buf = Buffer.allocUnsafe(2);
1833
1860
  *
@@ -1849,7 +1876,7 @@ declare module "buffer" {
1849
1876
  * The `value` is interpreted and written as a two's complement signed integer.
1850
1877
  *
1851
1878
  * ```js
1852
- * import { Buffer } from 'buffer';
1879
+ * import { Buffer } from 'node:buffer';
1853
1880
  *
1854
1881
  * const buf = Buffer.allocUnsafe(4);
1855
1882
  *
@@ -1871,7 +1898,7 @@ declare module "buffer" {
1871
1898
  * The `value` is interpreted and written as a two's complement signed integer.
1872
1899
  *
1873
1900
  * ```js
1874
- * import { Buffer } from 'buffer';
1901
+ * import { Buffer } from 'node:buffer';
1875
1902
  *
1876
1903
  * const buf = Buffer.allocUnsafe(4);
1877
1904
  *
@@ -1891,7 +1918,7 @@ declare module "buffer" {
1891
1918
  * undefined when `value` is anything other than a JavaScript number.
1892
1919
  *
1893
1920
  * ```js
1894
- * import { Buffer } from 'buffer';
1921
+ * import { Buffer } from 'node:buffer';
1895
1922
  *
1896
1923
  * const buf = Buffer.allocUnsafe(4);
1897
1924
  *
@@ -1911,7 +1938,7 @@ declare module "buffer" {
1911
1938
  * undefined when `value` is anything other than a JavaScript number.
1912
1939
  *
1913
1940
  * ```js
1914
- * import { Buffer } from 'buffer';
1941
+ * import { Buffer } from 'node:buffer';
1915
1942
  *
1916
1943
  * const buf = Buffer.allocUnsafe(4);
1917
1944
  *
@@ -1931,7 +1958,7 @@ declare module "buffer" {
1931
1958
  * other than a JavaScript number.
1932
1959
  *
1933
1960
  * ```js
1934
- * import { Buffer } from 'buffer';
1961
+ * import { Buffer } from 'node:buffer';
1935
1962
  *
1936
1963
  * const buf = Buffer.allocUnsafe(8);
1937
1964
  *
@@ -1951,7 +1978,7 @@ declare module "buffer" {
1951
1978
  * other than a JavaScript number.
1952
1979
  *
1953
1980
  * ```js
1954
- * import { Buffer } from 'buffer';
1981
+ * import { Buffer } from 'node:buffer';
1955
1982
  *
1956
1983
  * const buf = Buffer.allocUnsafe(8);
1957
1984
  *
@@ -1971,7 +1998,7 @@ declare module "buffer" {
1971
1998
  * the entire `buf` will be filled:
1972
1999
  *
1973
2000
  * ```js
1974
- * import { Buffer } from 'buffer';
2001
+ * import { Buffer } from 'node:buffer';
1975
2002
  *
1976
2003
  * // Fill a `Buffer` with the ASCII character 'h'.
1977
2004
  *
@@ -1979,6 +2006,12 @@ declare module "buffer" {
1979
2006
  *
1980
2007
  * console.log(b.toString());
1981
2008
  * // Prints: hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
2009
+ *
2010
+ * // Fill a buffer with empty string
2011
+ * const c = Buffer.allocUnsafe(5).fill('');
2012
+ *
2013
+ * console.log(c.fill(''));
2014
+ * // Prints: <Buffer 00 00 00 00 00>
1982
2015
  * ```
1983
2016
  *
1984
2017
  * `value` is coerced to a `uint32` value if it is not a string, `Buffer`, or
@@ -1989,7 +2022,7 @@ declare module "buffer" {
1989
2022
  * then only the bytes of that character that fit into `buf` are written:
1990
2023
  *
1991
2024
  * ```js
1992
- * import { Buffer } from 'buffer';
2025
+ * import { Buffer } from 'node:buffer';
1993
2026
  *
1994
2027
  * // Fill a `Buffer` with character that takes up two bytes in UTF-8.
1995
2028
  *
@@ -2001,7 +2034,7 @@ declare module "buffer" {
2001
2034
  * fill data remains, an exception is thrown:
2002
2035
  *
2003
2036
  * ```js
2004
- * import { Buffer } from 'buffer';
2037
+ * import { Buffer } from 'node:buffer';
2005
2038
  *
2006
2039
  * const buf = Buffer.allocUnsafe(5);
2007
2040
  *
@@ -2013,7 +2046,7 @@ declare module "buffer" {
2013
2046
  * // Throws an exception.
2014
2047
  * ```
2015
2048
  * @since v0.5.0
2016
- * @param value The value with which to fill `buf`.
2049
+ * @param value The value with which to fill `buf`. Empty value (string, Uint8Array, Buffer) is coerced to `0`.
2017
2050
  * @param [offset=0] Number of bytes to skip before starting to fill `buf`.
2018
2051
  * @param [end=buf.length] Where to stop filling `buf` (not inclusive).
2019
2052
  * @param [encoding='utf8'] The encoding for `value` if `value` is a string.
@@ -2030,7 +2063,7 @@ declare module "buffer" {
2030
2063
  * value between `0` and `255`.
2031
2064
  *
2032
2065
  * ```js
2033
- * import { Buffer } from 'buffer';
2066
+ * import { Buffer } from 'node:buffer';
2034
2067
  *
2035
2068
  * const buf = Buffer.from('this is a buffer');
2036
2069
  *
@@ -2063,7 +2096,7 @@ declare module "buffer" {
2063
2096
  * behavior matches [`String.prototype.indexOf()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/indexOf).
2064
2097
  *
2065
2098
  * ```js
2066
- * import { Buffer } from 'buffer';
2099
+ * import { Buffer } from 'node:buffer';
2067
2100
  *
2068
2101
  * const b = Buffer.from('abcdef');
2069
2102
  *
@@ -2094,7 +2127,7 @@ declare module "buffer" {
2094
2127
  * rather than the first occurrence.
2095
2128
  *
2096
2129
  * ```js
2097
- * import { Buffer } from 'buffer';
2130
+ * import { Buffer } from 'node:buffer';
2098
2131
  *
2099
2132
  * const buf = Buffer.from('this buffer is a buffer');
2100
2133
  *
@@ -2129,7 +2162,7 @@ declare module "buffer" {
2129
2162
  * This behavior matches [`String.prototype.lastIndexOf()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/lastIndexOf).
2130
2163
  *
2131
2164
  * ```js
2132
- * import { Buffer } from 'buffer';
2165
+ * import { Buffer } from 'node:buffer';
2133
2166
  *
2134
2167
  * const b = Buffer.from('abcdef');
2135
2168
  *
@@ -2162,7 +2195,7 @@ declare module "buffer" {
2162
2195
  * of `buf`.
2163
2196
  *
2164
2197
  * ```js
2165
- * import { Buffer } from 'buffer';
2198
+ * import { Buffer } from 'node:buffer';
2166
2199
  *
2167
2200
  * // Log the entire contents of a `Buffer`.
2168
2201
  *
@@ -2186,7 +2219,7 @@ declare module "buffer" {
2186
2219
  * Equivalent to `buf.indexOf() !== -1`.
2187
2220
  *
2188
2221
  * ```js
2189
- * import { Buffer } from 'buffer';
2222
+ * import { Buffer } from 'node:buffer';
2190
2223
  *
2191
2224
  * const buf = Buffer.from('this is a buffer');
2192
2225
  *
@@ -2216,7 +2249,7 @@ declare module "buffer" {
2216
2249
  * Creates and returns an [iterator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols) of `buf` keys (indices).
2217
2250
  *
2218
2251
  * ```js
2219
- * import { Buffer } from 'buffer';
2252
+ * import { Buffer } from 'node:buffer';
2220
2253
  *
2221
2254
  * const buf = Buffer.from('buffer');
2222
2255
  *
@@ -2239,7 +2272,7 @@ declare module "buffer" {
2239
2272
  * called automatically when a `Buffer` is used in a `for..of` statement.
2240
2273
  *
2241
2274
  * ```js
2242
- * import { Buffer } from 'buffer';
2275
+ * import { Buffer } from 'node:buffer';
2243
2276
  *
2244
2277
  * const buf = Buffer.from('buffer');
2245
2278
  *
@@ -2302,7 +2335,6 @@ declare module "buffer" {
2302
2335
  * @param data An ASCII (Latin1) string.
2303
2336
  */
2304
2337
  function btoa(data: string): string;
2305
-
2306
2338
  interface Blob extends __Blob {}
2307
2339
  /**
2308
2340
  * `Blob` class is a global reference for `require('node:buffer').Blob`