4
4
5
5
> Stability: 2 - Stable
6
6
7
- Prior to the introduction of [ ` TypedArray ` ] , the JavaScript language had no
7
+ Prior to the introduction of [ ` TypedArray ` ] [ ] , the JavaScript language had no
8
8
mechanism for reading or manipulating streams of binary data. The ` Buffer ` class
9
9
was introduced as part of the Node.js API to enable interaction with octet
10
10
streams in TCP streams, file system operations, and other contexts.
11
11
12
- With [ ` TypedArray ` ] now available, the ` Buffer ` class implements the
13
- [ ` Uint8Array ` ] API in a manner that is more optimized and suitable for Node.js.
12
+ With [ ` TypedArray ` ] [ ] now available, the ` Buffer ` class implements the
13
+ [ ` Uint8Array ` ] [ ] API in a manner that is more optimized and suitable for
14
+ Node.js.
14
15
15
16
Instances of the ` Buffer ` class are similar to arrays of integers from ` 0 ` to
16
17
` 255 ` (other integers are coerced to this range by ` & 255 ` operation) but
@@ -62,8 +63,8 @@ differently based on what arguments are provided:
62
63
` new Buffer(num) ` will return a ` Buffer ` with initialized memory.
63
64
* Passing a string, array, or ` Buffer ` as the first argument copies the
64
65
passed object's data into the ` Buffer ` .
65
- * Passing an [ ` ArrayBuffer ` ] or a [ ` SharedArrayBuffer ` ] returns a ` Buffer ` that
66
- shares allocated memory with the given array buffer.
66
+ * Passing an [ ` ArrayBuffer ` ] [ ] or a [ ` SharedArrayBuffer ` ] [ ] returns a ` Buffer `
67
+ that shares allocated memory with the given array buffer.
67
68
68
69
Because the behavior of ` new Buffer() ` is different depending on the type of the
69
70
first argument, security and reliability issues can be inadvertently introduced
@@ -72,18 +73,18 @@ performed.
72
73
73
74
To make the creation of ` Buffer ` instances more reliable and less error-prone,
74
75
the various forms of the ` new Buffer() ` constructor have been ** deprecated**
75
- and replaced by separate ` Buffer.from() ` , [ ` Buffer.alloc() ` ] , and
76
- [ ` Buffer.allocUnsafe() ` ] methods.
76
+ and replaced by separate ` Buffer.from() ` , [ ` Buffer.alloc() ` ] [ ] , and
77
+ [ ` Buffer.allocUnsafe() ` ] [ ] methods.
77
78
78
79
* Developers should migrate all existing uses of the ` new Buffer() ` constructors
79
80
to one of these new APIs.*
80
81
81
- * [ ` Buffer.from(array) ` ] returns a new ` Buffer ` that * contains a copy* of the
82
+ * [ ` Buffer.from(array) ` ] [ ] returns a new ` Buffer ` that * contains a copy* of the
82
83
provided octets.
83
84
* [ ` Buffer.from(arrayBuffer[, byteOffset[, length]]) ` ] [ `Buffer.from(arrayBuf)` ]
84
85
returns a new ` Buffer ` that * shares the same allocated memory* as the given
85
- [ ` ArrayBuffer ` ] .
86
- * [ ` Buffer.from(buffer) ` ] returns a new ` Buffer ` that * contains a copy* of the
86
+ [ ` ArrayBuffer ` ] [ ] .
87
+ * [ ` Buffer.from(buffer) ` ] [ ] returns a new ` Buffer ` that * contains a copy* of the
87
88
contents of the given ` Buffer ` .
88
89
* [ ` Buffer.from(string[, encoding]) ` ] [ `Buffer.from(string)` ] returns a new
89
90
` Buffer ` that * contains a copy* of the provided string.
@@ -98,10 +99,10 @@ to one of these new APIs.*
98
99
uninitialized, the allocated segment of memory might contain old data that is
99
100
potentially sensitive.
100
101
101
- ` Buffer ` instances returned by [ ` Buffer.allocUnsafe() ` ] * may* be allocated off
102
+ ` Buffer ` instances returned by [ ` Buffer.allocUnsafe() ` ] [ ] * may* be allocated off
102
103
a shared internal memory pool if ` size ` is less than or equal to half
103
- [ ` Buffer.poolSize ` ] . Instances returned by [ ` Buffer.allocUnsafeSlow() ` ] * never *
104
- use the shared internal memory pool.
104
+ [ ` Buffer.poolSize ` ] [ ] . Instances returned by [ ` Buffer.allocUnsafeSlow() ` ] [ ]
105
+ * never * use the shared internal memory pool.
105
106
106
107
### The ` --zero-fill-buffers ` command line option
107
108
<!-- YAML
@@ -111,7 +112,7 @@ added: v5.10.0
111
112
Node.js can be started using the ` --zero-fill-buffers ` command line option to
112
113
cause all newly allocated ` Buffer ` instances to be zero-filled upon creation by
113
114
default, including buffers returned by ` new Buffer(size) ` ,
114
- [ ` Buffer.allocUnsafe() ` ] , [ ` Buffer.allocUnsafeSlow() ` ] , and `new
115
+ [ ` Buffer.allocUnsafe() ` ] [ ] , [ ` Buffer.allocUnsafeSlow() ` ] [ ] , and `new
115
116
SlowBuffer(size)`. Use of this flag can have a significant negative impact on
116
117
performance. Use of the ` --zero-fill-buffers ` option is recommended only when
117
118
necessary to enforce that newly allocated ` Buffer ` instances cannot contain old
@@ -125,16 +126,16 @@ $ node --zero-fill-buffers
125
126
126
127
### What makes ` Buffer.allocUnsafe() ` and ` Buffer.allocUnsafeSlow() ` "unsafe"?
127
128
128
- When calling [ ` Buffer.allocUnsafe() ` ] and [ ` Buffer.allocUnsafeSlow() ` ] , the
129
+ When calling [ ` Buffer.allocUnsafe() ` ] [ ] and [ ` Buffer.allocUnsafeSlow() ` ] [ ] , the
129
130
segment of allocated memory is * uninitialized* (it is not zeroed-out). While
130
131
this design makes the allocation of memory quite fast, the allocated segment of
131
132
memory might contain old data that is potentially sensitive. Using a ` Buffer `
132
- created by [ ` Buffer.allocUnsafe() ` ] without * completely* overwriting the memory
133
- can allow this old data to be leaked when the ` Buffer ` memory is read.
133
+ created by [ ` Buffer.allocUnsafe() ` ] [ ] without * completely* overwriting the
134
+ memory can allow this old data to be leaked when the ` Buffer ` memory is read.
134
135
135
- While there are clear performance advantages to using [ ` Buffer.allocUnsafe() ` ] ,
136
- extra care * must* be taken in order to avoid introducing security
137
- vulnerabilities into an application.
136
+ While there are clear performance advantages to using
137
+ [ ` Buffer.allocUnsafe() ` ] [ ] , extra care * must* be taken in order to avoid
138
+ introducing security vulnerabilities into an application.
138
139
139
140
## Buffers and Character Encodings
140
141
<!-- YAML
@@ -179,10 +180,10 @@ The character encodings currently supported by Node.js include:
179
180
180
181
* ` 'base64' ` - Base64 encoding. When creating a ` Buffer ` from a string,
181
182
this encoding will also correctly accept "URL and Filename Safe Alphabet" as
182
- specified in [ RFC 4648, Section 5] .
183
+ specified in [ RFC 4648, Section 5] [ ] .
183
184
184
185
* ` 'latin1' ` - A way of encoding the ` Buffer ` into a one-byte encoded string
185
- (as defined by the IANA in [ RFC 1345] ,
186
+ (as defined by the IANA in [ RFC 1345] [ ] ,
186
187
page 63, to be the Latin-1 supplement block and C0/C1 control codes).
187
188
188
189
* ` 'binary' ` - Alias for ` 'latin1' ` .
@@ -204,25 +205,26 @@ changes:
204
205
description: The `Buffer`s class now inherits from `Uint8Array`.
205
206
-->
206
207
207
- ` Buffer ` instances are also [ ` Uint8Array ` ] instances. However, there are subtle
208
- incompatibilities with [ ` TypedArray ` ] . For example, while
209
- [ ` ArrayBuffer#slice() ` ] creates a copy of the slice, the implementation of
208
+ ` Buffer ` instances are also [ ` Uint8Array ` ] [ ] instances. However, there are
209
+ subtle incompatibilities with [ ` TypedArray ` ] [ ] . For example, while
210
+ [ ` ArrayBuffer#slice() ` ] [ ] creates a copy of the slice, the implementation of
210
211
[ ` Buffer#slice() ` ] [ `buf.slice()` ] creates a view over the existing ` Buffer `
211
212
without copying, making [ ` Buffer#slice() ` ] [ `buf.slice()` ] far more efficient.
212
213
213
- It is also possible to create new [ ` TypedArray ` ] instances from a ` Buffer ` with
214
- the following caveats:
214
+ It is also possible to create new [ ` TypedArray ` ] [ ] instances from a ` Buffer `
215
+ with the following caveats:
215
216
216
- 1 . The ` Buffer ` object's memory is copied to the [ ` TypedArray ` ] , not shared.
217
+ 1 . The ` Buffer ` object's memory is copied to the [ ` TypedArray ` ] [ ] , not shared.
217
218
218
219
2 . The ` Buffer ` object's memory is interpreted as an array of distinct
219
220
elements, and not as a byte array of the target type. That is,
220
- ` new Uint32Array(Buffer.from([1, 2, 3, 4])) ` creates a 4-element [ ` Uint32Array ` ]
221
- with elements ` [1, 2, 3, 4] ` , not a [ ` Uint32Array ` ] with a single element
222
- ` [0x1020304] ` or ` [0x4030201] ` .
221
+ ` new Uint32Array(Buffer.from([1, 2, 3, 4])) ` creates a 4-element
222
+ [ ` Uint32Array ` ] [ ] with elements ` [1, 2, 3, 4] ` , not a [ ` Uint32Array ` ] [ ] with a
223
+ single element ` [0x1020304] ` or ` [0x4030201] ` .
223
224
224
225
It is possible to create a new ` Buffer ` that shares the same allocated memory as
225
- a [ ` TypedArray ` ] instance by using the ` TypedArray ` object's ` .buffer ` property.
226
+ a [ ` TypedArray ` ] [ ] instance by using the ` TypedArray ` object's ` .buffer `
227
+ property.
226
228
227
229
``` js
228
230
const arr = new Uint16Array (2 );
@@ -248,8 +250,8 @@ console.log(buf2);
248
250
// Prints: <Buffer 88 13 70 17>
249
251
```
250
252
251
- Note that when creating a ` Buffer ` using a [ ` TypedArray ` ] 's ` .buffer ` , it is
252
- possible to use only a portion of the underlying [ ` ArrayBuffer ` ] by passing in
253
+ Note that when creating a ` Buffer ` using a [ ` TypedArray ` ] [ ] 's ` .buffer ` , it is
254
+ possible to use only a portion of the underlying [ ` ArrayBuffer ` ] [ ] by passing in
253
255
` byteOffset ` and ` length ` parameters.
254
256
255
257
``` js
@@ -260,8 +262,8 @@ console.log(buf.length);
260
262
// Prints: 16
261
263
```
262
264
263
- The ` Buffer.from() ` and [ ` TypedArray.from() ` ] have different signatures and
264
- implementations. Specifically, the [ ` TypedArray ` ] variants accept a second
265
+ The ` Buffer.from() ` and [ ` TypedArray.from() ` ] [ ] have different signatures and
266
+ implementations. Specifically, the [ ` TypedArray ` ] [ ] variants accept a second
265
267
argument that is a mapping function that is invoked on every element of the
266
268
typed array:
267
269
@@ -270,8 +272,8 @@ typed array:
270
272
The ` Buffer.from() ` method, however, does not support the use of a mapping
271
273
function:
272
274
273
- * [ ` Buffer.from(array) ` ]
274
- * [ ` Buffer.from(buffer) ` ]
275
+ * [ ` Buffer.from(array) ` ] [ ]
276
+ * [ ` Buffer.from(buffer) ` ] [ ]
275
277
* [ ` Buffer.from(arrayBuffer[, byteOffset[, length]]) ` ] [ `Buffer.from(arrayBuf)` ]
276
278
* [ ` Buffer.from(string[, encoding]) ` ] [ `Buffer.from(string)` ]
277
279
@@ -291,8 +293,8 @@ for (const b of buf) {
291
293
// 3
292
294
```
293
295
294
- Additionally, the [ ` buf.values() ` ] , [ ` buf.keys() ` ] , and
295
- [ ` buf.entries() ` ] methods can be used to create iterators.
296
+ Additionally, the [ ` buf.values() ` ] [ ] , [ ` buf.keys() ` ] [ ] , and
297
+ [ ` buf.entries() ` ] [ ] methods can be used to create iterators.
296
298
297
299
## Class: Buffer
298
300
@@ -315,7 +317,7 @@ changes:
315
317
description: Calling this constructor emits a deprecation warning now.
316
318
-->
317
319
318
- > Stability: 0 - Deprecated: Use [ ` Buffer.from(array) ` ] instead.
320
+ > Stability: 0 - Deprecated: Use [ ` Buffer.from(array) ` ] [ ] instead.
319
321
320
322
* ` array ` {integer[ ] } An array of bytes to copy from.
321
323
@@ -350,16 +352,16 @@ changes:
350
352
> [ ` Buffer.from(arrayBuffer[, byteOffset[, length]]) ` ] [ `Buffer.from(arrayBuf)` ]
351
353
> instead.
352
354
353
- * ` arrayBuffer ` {ArrayBuffer|SharedArrayBuffer} An [ ` ArrayBuffer ` ] ,
354
- [ ` SharedArrayBuffer ` ] or the ` .buffer ` property of a [ ` TypedArray ` ] .
355
+ * ` arrayBuffer ` {ArrayBuffer|SharedArrayBuffer} An [ ` ArrayBuffer ` ] [ ] ,
356
+ [ ` SharedArrayBuffer ` ] [ ] or the ` .buffer ` property of a [ ` TypedArray ` ] [ ] .
355
357
* ` byteOffset ` {integer} Index of first byte to expose. ** Default:** ` 0 ` .
356
358
* ` length ` {integer} Number of bytes to expose.
357
359
** Default:** ` arrayBuffer.length - byteOffset ` .
358
360
359
- This creates a view of the [ ` ArrayBuffer ` ] or [ ` SharedArrayBuffer ` ] without
361
+ This creates a view of the [ ` ArrayBuffer ` ] [ ] or [ ` SharedArrayBuffer ` ] [ ] without
360
362
copying the underlying memory. For example, when passed a reference to the
361
- ` .buffer ` property of a [ ` TypedArray ` ] instance, the newly created ` Buffer ` will
362
- share the same allocated memory as the [ ` TypedArray ` ] .
363
+ ` .buffer ` property of a [ ` TypedArray ` ] [ ] instance, the newly created ` Buffer `
364
+ will share the same allocated memory as the [ ` TypedArray ` ] [ ] .
363
365
364
366
The optional ` byteOffset ` and ` length ` arguments specify a memory range within
365
367
the ` arrayBuffer ` that will be shared by the ` Buffer ` .
@@ -399,10 +401,10 @@ changes:
399
401
description: Calling this constructor emits a deprecation warning now.
400
402
-->
401
403
402
- > Stability: 0 - Deprecated: Use [ ` Buffer.from(buffer) ` ] instead.
404
+ > Stability: 0 - Deprecated: Use [ ` Buffer.from(buffer) ` ] [ ] instead.
403
405
404
- * ` buffer ` {Buffer|Uint8Array} An existing ` Buffer ` or [ ` Uint8Array ` ] from which
405
- to copy data.
406
+ * ` buffer ` {Buffer|Uint8Array} An existing ` Buffer ` or [ ` Uint8Array ` ] [ ] from
407
+ which to copy data.
406
408
407
409
Copies the passed ` buffer ` data onto a new ` Buffer ` instance.
408
410
@@ -438,14 +440,14 @@ changes:
438
440
description: Calling this constructor emits a deprecation warning now.
439
441
-->
440
442
441
- > Stability: 0 - Deprecated: Use [ ` Buffer.alloc() ` ] instead (also see
442
- > [ ` Buffer.allocUnsafe() ` ] ).
443
+ > Stability: 0 - Deprecated: Use [ ` Buffer.alloc() ` ] [ ] instead (also see
444
+ > [ ` Buffer.allocUnsafe() ` ] [ ] ).
443
445
444
446
* ` size ` {integer} The desired length of the new ` Buffer ` .
445
447
446
448
Allocates a new ` Buffer ` of ` size ` bytes. If ` size ` is larger than
447
- [ ` buffer.constants.MAX_LENGTH ` ] or smaller than 0, [ ` ERR_INVALID_OPT_VALUE ` ] is
448
- thrown. A zero-length ` Buffer ` is created if ` size ` is 0.
449
+ [ ` buffer.constants.MAX_LENGTH ` ] [ ] or smaller than 0, [ ` ERR_INVALID_OPT_VALUE ` ] [ ]
450
+ is thrown. A zero-length ` Buffer ` is created if ` size ` is 0.
449
451
450
452
Prior to Node.js 8.0.0, the underlying memory for ` Buffer ` instances
451
453
created in this way is * not initialized* . The contents of a newly created
@@ -532,8 +534,8 @@ console.log(buf);
532
534
```
533
535
534
536
If ` size ` is larger than
535
- [ ` buffer.constants.MAX_LENGTH ` ] or smaller than 0, [ ` ERR_INVALID_OPT_VALUE ` ] is
536
- thrown. A zero-length ` Buffer ` is created if ` size ` is 0.
537
+ [ ` buffer.constants.MAX_LENGTH ` ] [ ] or smaller than 0, [ ` ERR_INVALID_OPT_VALUE ` ] [ ]
538
+ is thrown. A zero-length ` Buffer ` is created if ` size ` is 0.
537
539
538
540
If ` fill ` is specified, the allocated ` Buffer ` will be initialized by calling
539
541
[ ` buf.fill(fill) ` ] [ `buf.fill()` ] .
@@ -555,8 +557,8 @@ console.log(buf);
555
557
// Prints: <Buffer 68 65 6c 6c 6f 20 77 6f 72 6c 64>
556
558
```
557
559
558
- Calling [ ` Buffer.alloc() ` ] can be significantly slower than the alternative
559
- [ ` Buffer.allocUnsafe() ` ] but ensures that the newly created ` Buffer ` instance
560
+ Calling [ ` Buffer.alloc() ` ] [ ] can be significantly slower than the alternative
561
+ [ ` Buffer.allocUnsafe() ` ] [ ] but ensures that the newly created ` Buffer ` instance
560
562
contents will * never contain sensitive data* .
561
563
562
564
A ` TypeError ` will be thrown if ` size ` is not a number.
@@ -573,12 +575,12 @@ changes:
573
575
* ` size ` {integer} The desired length of the new ` Buffer ` .
574
576
575
577
Allocates a new ` Buffer ` of ` size ` bytes. If ` size ` is larger than
576
- [ ` buffer.constants.MAX_LENGTH ` ] or smaller than 0, [ ` ERR_INVALID_OPT_VALUE ` ] is
577
- thrown. A zero-length ` Buffer ` is created if ` size ` is 0.
578
+ [ ` buffer.constants.MAX_LENGTH ` ] [ ] or smaller than 0, [ ` ERR_INVALID_OPT_VALUE ` ] [ ]
579
+ is thrown. A zero-length ` Buffer ` is created if ` size ` is 0.
578
580
579
581
The underlying memory for ` Buffer ` instances created in this way is * not
580
582
initialized* . The contents of the newly created ` Buffer ` are unknown and
581
- * may contain sensitive data* . Use [ ` Buffer.alloc() ` ] instead to initialize
583
+ * may contain sensitive data* . Use [ ` Buffer.alloc() ` ] [ ] instead to initialize
582
584
` Buffer ` instances with zeroes.
583
585
584
586
``` js
@@ -596,18 +598,18 @@ console.log(buf);
596
598
A ` TypeError ` will be thrown if ` size ` is not a number.
597
599
598
600
Note that the ` Buffer ` module pre-allocates an internal ` Buffer ` instance of
599
- size [ ` Buffer.poolSize ` ] that is used as a pool for the fast allocation of new
600
- ` Buffer ` instances created using [ ` Buffer.allocUnsafe() ` ] and the deprecated
601
+ size [ ` Buffer.poolSize ` ] [ ] that is used as a pool for the fast allocation of new
602
+ ` Buffer ` instances created using [ ` Buffer.allocUnsafe() ` ] [ ] and the deprecated
601
603
` new Buffer(size) ` constructor only when ` size ` is less than or equal to
602
- ` Buffer.poolSize >> 1 ` (floor of [ ` Buffer.poolSize ` ] divided by two).
604
+ ` Buffer.poolSize >> 1 ` (floor of [ ` Buffer.poolSize ` ] [ ] divided by two).
603
605
604
606
Use of this pre-allocated internal memory pool is a key difference between
605
607
calling ` Buffer.alloc(size, fill) ` vs. ` Buffer.allocUnsafe(size).fill(fill) ` .
606
608
Specifically, ` Buffer.alloc(size, fill) ` will * never* use the internal ` Buffer `
607
609
pool, while ` Buffer.allocUnsafe(size).fill(fill) ` * will* use the internal
608
- ` Buffer ` pool if ` size ` is less than or equal to half [ ` Buffer.poolSize ` ] . The
610
+ ` Buffer ` pool if ` size ` is less than or equal to half [ ` Buffer.poolSize ` ] [ ] . The
609
611
difference is subtle but can be important when an application requires the
610
- additional performance that [ ` Buffer.allocUnsafe() ` ] provides.
612
+ additional performance that [ ` Buffer.allocUnsafe() ` ] [ ] provides.
611
613
612
614
### Class Method: Buffer.allocUnsafeSlow(size)
613
615
<!-- YAML
@@ -617,15 +619,15 @@ added: v5.12.0
617
619
* ` size ` {integer} The desired length of the new ` Buffer ` .
618
620
619
621
Allocates a new ` Buffer ` of ` size ` bytes. If ` size ` is larger than
620
- [ ` buffer.constants.MAX_LENGTH ` ] or smaller than 0, [ ` ERR_INVALID_OPT_VALUE ` ] is
621
- thrown. A zero-length ` Buffer ` is created if ` size ` is 0.
622
+ [ ` buffer.constants.MAX_LENGTH ` ] [ ] or smaller than 0, [ ` ERR_INVALID_OPT_VALUE ` ] [ ]
623
+ is thrown. A zero-length ` Buffer ` is created if ` size ` is 0.
622
624
623
625
The underlying memory for ` Buffer ` instances created in this way is * not
624
626
initialized* . The contents of the newly created ` Buffer ` are unknown and
625
627
* may contain sensitive data* . Use [ ` buf.fill(0) ` ] [ `buf.fill()` ] to initialize
626
628
such ` Buffer ` instances with zeroes.
627
629
628
- When using [ ` Buffer.allocUnsafe() ` ] to allocate new ` Buffer ` instances,
630
+ When using [ ` Buffer.allocUnsafe() ` ] [ ] to allocate new ` Buffer ` instances,
629
631
allocations under 4KB are sliced from a single pre-allocated ` Buffer ` . This
630
632
allows applications to avoid the garbage collection overhead of creating many
631
633
individually allocated ` Buffer ` instances. This approach improves both
@@ -680,7 +682,7 @@ changes:
680
682
* Returns: {integer} The number of bytes contained within ` string ` .
681
683
682
684
Returns the actual byte length of a string. This is not the same as
683
- [ ` String.prototype.length ` ] since that returns the number of * characters* in
685
+ [ ` String.prototype.length ` ] [ ] since that returns the number of * characters* in
684
686
a string.
685
687
686
688
For ` 'base64' ` and ` 'hex' ` , this function assumes valid input. For strings that
@@ -695,8 +697,8 @@ console.log(`${str}: ${str.length} characters, ` +
695
697
// Prints: ½ + ¼ = ¾: 9 characters, 12 bytes
696
698
```
697
699
698
- When ` string ` is a ` Buffer ` /[ ` DataView ` ] /[ ` TypedArray ` ] /[ ` ArrayBuffer ` ] /
699
- [ ` SharedArrayBuffer ` ] , the actual byte length is returned.
700
+ When ` string ` is a ` Buffer ` /[ ` DataView ` ] [ ] /[ ` TypedArray ` ] [ ] /[ ` ArrayBuffer ` ] [ ] /
701
+ [ ` SharedArrayBuffer ` ] [ ] , the actual byte length is returned.
700
702
701
703
### Class Method: Buffer.compare(buf1, buf2)
702
704
<!-- YAML
@@ -734,8 +736,8 @@ changes:
734
736
description: The elements of `list` can now be `Uint8Array`s.
735
737
-->
736
738
737
- * ` list ` {Buffer[ ] | Uint8Array[ ] } List of ` Buffer ` or [ ` Uint8Array ` ] instances
738
- to concat.
739
+ * ` list ` {Buffer[ ] | Uint8Array[ ] } List of ` Buffer ` or [ ` Uint8Array ` ] [ ]
740
+ instances to concat.
739
741
* ` totalLength ` {integer} Total length of the ` Buffer ` instances in ` list `
740
742
when concatenated.
741
743
* Returns: {Buffer}
@@ -796,16 +798,16 @@ appropriate for `Buffer.from()` variants.
796
798
added: v5.10.0
797
799
-->
798
800
799
- * ` arrayBuffer ` {ArrayBuffer|SharedArrayBuffer} An [ ` ArrayBuffer ` ] ,
800
- [ ` SharedArrayBuffer ` ] , or the ` .buffer ` property of a [ ` TypedArray ` ] .
801
+ * ` arrayBuffer ` {ArrayBuffer|SharedArrayBuffer} An [ ` ArrayBuffer ` ] [ ] ,
802
+ [ ` SharedArrayBuffer ` ] [ ] , or the ` .buffer ` property of a [ ` TypedArray ` ] [ ] .
801
803
* ` byteOffset ` {integer} Index of first byte to expose. ** Default:** ` 0 ` .
802
804
* ` length ` {integer} Number of bytes to expose.
803
805
** Default:** ` arrayBuffer.length - byteOffset ` .
804
806
805
- This creates a view of the [ ` ArrayBuffer ` ] without copying the underlying
807
+ This creates a view of the [ ` ArrayBuffer ` ] [ ] without copying the underlying
806
808
memory. For example, when passed a reference to the ` .buffer ` property of a
807
- [ ` TypedArray ` ] instance, the newly created ` Buffer ` will share the same
808
- allocated memory as the [ ` TypedArray ` ] .
809
+ [ ` TypedArray ` ] [ ] instance, the newly created ` Buffer ` will share the same
810
+ allocated memory as the [ ` TypedArray ` ] [ ] .
809
811
810
812
``` js
811
813
const arr = new Uint16Array (2 );
@@ -837,16 +839,16 @@ console.log(buf.length);
837
839
// Prints: 2
838
840
```
839
841
840
- A ` TypeError ` will be thrown if ` arrayBuffer ` is not an [ ` ArrayBuffer ` ] or a
841
- [ ` SharedArrayBuffer ` ] or other type appropriate for ` Buffer.from() ` variants.
842
+ A ` TypeError ` will be thrown if ` arrayBuffer ` is not an [ ` ArrayBuffer ` ] [ ] or a
843
+ [ ` SharedArrayBuffer ` ] [ ] or other type appropriate for ` Buffer.from() ` variants.
842
844
843
845
### Class Method: Buffer.from(buffer)
844
846
<!-- YAML
845
847
added: v5.10.0
846
848
-->
847
849
848
- * ` buffer ` {Buffer|Uint8Array} An existing ` Buffer ` or [ ` Uint8Array ` ] from which
849
- to copy data.
850
+ * ` buffer ` {Buffer|Uint8Array} An existing ` Buffer ` or [ ` Uint8Array ` ] [ ] from
851
+ which to copy data.
850
852
851
853
Copies the passed ` buffer ` data onto a new ` Buffer ` instance.
852
854
@@ -1039,7 +1041,7 @@ changes:
1039
1041
description: Additional parameters for specifying offsets are supported now.
1040
1042
-->
1041
1043
1042
- * ` target ` {Buffer|Uint8Array} A ` Buffer ` or [ ` Uint8Array ` ] with which to
1044
+ * ` target ` {Buffer|Uint8Array} A ` Buffer ` or [ ` Uint8Array ` ] [ ] with which to
1043
1045
compare ` buf ` .
1044
1046
* ` targetStart ` {integer} The offset within ` target ` at which to begin
1045
1047
comparison. ** Default:** ` 0 ` .
@@ -1048,7 +1050,7 @@ changes:
1048
1050
* ` sourceStart ` {integer} The offset within ` buf ` at which to begin comparison.
1049
1051
** Default:** ` 0 ` .
1050
1052
* ` sourceEnd ` {integer} The offset within ` buf ` at which to end comparison
1051
- (not inclusive). ** Default:** [ ` buf.length ` ] .
1053
+ (not inclusive). ** Default:** [ ` buf.length ` ] [ ] .
1052
1054
* Returns: {integer}
1053
1055
1054
1056
Compares ` buf ` with ` target ` and returns a number indicating whether ` buf `
@@ -1095,21 +1097,21 @@ console.log(buf1.compare(buf2, 5, 6, 5));
1095
1097
// Prints: 1
1096
1098
```
1097
1099
1098
- [ ` ERR_OUT_OF_RANGE ` ] is thrown if ` targetStart < 0 ` , ` sourceStart < 0 ` ,
1100
+ [ ` ERR_OUT_OF_RANGE ` ] [ ] is thrown if ` targetStart < 0 ` , ` sourceStart < 0 ` ,
1099
1101
` targetEnd > target.byteLength ` , or ` sourceEnd > source.byteLength ` .
1100
1102
1101
1103
### buf.copy(target[ , targetStart[ , sourceStart[ , sourceEnd]]] )
1102
1104
<!-- YAML
1103
1105
added: v0.1.90
1104
1106
-->
1105
1107
1106
- * ` target ` {Buffer|Uint8Array} A ` Buffer ` or [ ` Uint8Array ` ] to copy into.
1108
+ * ` target ` {Buffer|Uint8Array} A ` Buffer ` or [ ` Uint8Array ` ] [ ] to copy into.
1107
1109
* ` targetStart ` {integer} The offset within ` target ` at which to begin
1108
1110
writing. ** Default:** ` 0 ` .
1109
1111
* ` sourceStart ` {integer} The offset within ` buf ` from which to begin copying.
1110
1112
** Default:** ` 0 ` .
1111
1113
* ` sourceEnd ` {integer} The offset within ` buf ` at which to stop copying (not
1112
- inclusive). ** Default:** [ ` buf.length ` ] .
1114
+ inclusive). ** Default:** [ ` buf.length ` ] [ ] .
1113
1115
* Returns: {integer} The number of bytes copied.
1114
1116
1115
1117
Copies data from a region of ` buf ` to a region in ` target ` even if the ` target `
@@ -1156,8 +1158,8 @@ added: v1.1.0
1156
1158
1157
1159
* Returns: {Iterator}
1158
1160
1159
- Creates and returns an [ iterator] of ` [index, byte] ` pairs from the contents of
1160
- ` buf ` .
1161
+ Creates and returns an [ iterator] [ ] of ` [index, byte] ` pairs from the contents
1162
+ of ` buf ` .
1161
1163
1162
1164
``` js
1163
1165
// Log the entire contents of a `Buffer`.
@@ -1185,7 +1187,7 @@ changes:
1185
1187
description: The arguments can now be `Uint8Array`s.
1186
1188
-->
1187
1189
1188
- * ` otherBuffer ` {Buffer|Uint8Array} A ` Buffer ` or [ ` Uint8Array ` ] with which to
1190
+ * ` otherBuffer ` {Buffer|Uint8Array} A ` Buffer ` or [ ` Uint8Array ` ] [ ] with which to
1189
1191
compare ` buf ` .
1190
1192
* Returns: {boolean}
1191
1193
@@ -1230,7 +1232,7 @@ changes:
1230
1232
* ` offset ` {integer} Number of bytes to skip before starting to fill ` buf ` .
1231
1233
** Default:** ` 0 ` .
1232
1234
* ` end ` {integer} Where to stop filling ` buf ` (not inclusive). ** Default:**
1233
- [ ` buf.length ` ] .
1235
+ [ ` buf.length ` ] [ ] .
1234
1236
* ` encoding ` {string} The encoding for ` value ` if ` value ` is a string.
1235
1237
** Default:** ` 'utf8' ` .
1236
1238
* Returns: {Buffer} A reference to ` buf ` .
@@ -1334,8 +1336,8 @@ If `value` is:
1334
1336
1335
1337
* a string, ` value ` is interpreted according to the character encoding in
1336
1338
` encoding ` .
1337
- * a ` Buffer ` or [ ` Uint8Array ` ] , ` value ` will be used in its entirety.
1338
- To compare a partial ` Buffer ` , use [ ` buf.slice() ` ] .
1339
+ * a ` Buffer ` or [ ` Uint8Array ` ] [ ] , ` value ` will be used in its entirety.
1340
+ To compare a partial ` Buffer ` , use [ ` buf.slice() ` ] [ ] .
1339
1341
* a number, ` value ` will be interpreted as an unsigned 8-bit integer
1340
1342
value between ` 0 ` and ` 255 ` .
1341
1343
@@ -1369,7 +1371,7 @@ an integer between 0 and 255.
1369
1371
1370
1372
If ` byteOffset ` is not a number, it will be coerced to a number. If the result
1371
1373
of coercion is ` NaN ` or ` 0 ` , then the entire buffer will be searched. This
1372
- behavior matches [ ` String#indexOf() ` ] .
1374
+ behavior matches [ ` String#indexOf() ` ] [ ] .
1373
1375
1374
1376
``` js
1375
1377
const b = Buffer .from (' abcdef' );
@@ -1398,7 +1400,7 @@ added: v1.1.0
1398
1400
1399
1401
* Returns: {Iterator}
1400
1402
1401
- Creates and returns an [ iterator] of ` buf ` keys (indices).
1403
+ Creates and returns an [ iterator] [ ] of ` buf ` keys (indices).
1402
1404
1403
1405
``` js
1404
1406
const buf = Buffer .from (' buffer' );
@@ -1427,14 +1429,14 @@ changes:
1427
1429
* ` value ` {string|Buffer|Uint8Array|integer} What to search for.
1428
1430
* ` byteOffset ` {integer} Where to begin searching in ` buf ` . If negative, then
1429
1431
offset is calculated from the end of ` buf ` . ** Default:**
1430
- [ ` buf.length ` ] ` - 1 ` .
1432
+ [ ` buf.length ` ] [ ] ` - 1 ` .
1431
1433
* ` encoding ` {string} If ` value ` is a string, this is the encoding used to
1432
1434
determine the binary representation of the string that will be searched for in
1433
1435
` buf ` . ** Default:** ` 'utf8' ` .
1434
1436
* Returns: {integer} The index of the last occurrence of ` value ` in ` buf ` , or
1435
1437
` -1 ` if ` buf ` does not contain ` value ` .
1436
1438
1437
- Identical to [ ` buf.indexOf() ` ] , except the last occurrence of ` value ` is found
1439
+ Identical to [ ` buf.indexOf() ` ] [ ] , except the last occurrence of ` value ` is found
1438
1440
rather than the first occurrence.
1439
1441
1440
1442
``` js
@@ -1469,7 +1471,7 @@ an integer between 0 and 255.
1469
1471
1470
1472
If ` byteOffset ` is not a number, it will be coerced to a number. Any arguments
1471
1473
that coerce to ` NaN ` , like ` {} ` or ` undefined ` , will search the whole buffer.
1472
- This behavior matches [ ` String#lastIndexOf() ` ] .
1474
+ This behavior matches [ ` String#lastIndexOf() ` ] [ ] .
1473
1475
1474
1476
``` js
1475
1477
const b = Buffer .from (' abcdef' );
@@ -1519,7 +1521,7 @@ console.log(buf.length);
1519
1521
While the ` length ` property is not immutable, changing the value of ` length `
1520
1522
can result in undefined and inconsistent behavior. Applications that wish to
1521
1523
modify the length of a ` Buffer ` should therefore treat ` length ` as read-only and
1522
- use [ ` buf.slice() ` ] to create a new ` Buffer ` .
1524
+ use [ ` buf.slice() ` ] [ ] to create a new ` Buffer ` .
1523
1525
1524
1526
``` js
1525
1527
let buf = Buffer .allocUnsafe (10 );
@@ -1540,7 +1542,7 @@ console.log(buf.length);
1540
1542
deprecated: v8.0.0
1541
1543
-->
1542
1544
1543
- > Stability: 0 - Deprecated: Use [ ` buf.buffer ` ] instead.
1545
+ > Stability: 0 - Deprecated: Use [ ` buf.buffer ` ] [ ] instead.
1544
1546
1545
1547
The ` buf.parent ` property is a deprecated alias for ` buf.buffer ` .
1546
1548
@@ -1870,14 +1872,14 @@ changes:
1870
1872
1871
1873
* ` start ` {integer} Where the new ` Buffer ` will start. ** Default:** ` 0 ` .
1872
1874
* ` end ` {integer} Where the new ` Buffer ` will end (not inclusive).
1873
- ** Default:** [ ` buf.length ` ] .
1875
+ ** Default:** [ ` buf.length ` ] [ ] .
1874
1876
* Returns: {Buffer}
1875
1877
1876
1878
Returns a new ` Buffer ` that references the same memory as the original, but
1877
1879
offset and cropped by the ` start ` and ` end ` indices.
1878
1880
1879
- Specifying ` end ` greater than [ ` buf.length ` ] will return the same result as
1880
- that of ` end ` equal to [ ` buf.length ` ] .
1881
+ Specifying ` end ` greater than [ ` buf.length ` ] [ ] will return the same result as
1882
+ that of ` end ` equal to [ ` buf.length ` ] [ ] .
1881
1883
1882
1884
Modifying the new ` Buffer ` slice will modify the memory in the original ` Buffer `
1883
1885
because the allocated memory of the two objects overlap.
@@ -1931,8 +1933,8 @@ added: v5.10.0
1931
1933
* Returns: {Buffer} A reference to ` buf ` .
1932
1934
1933
1935
Interprets ` buf ` as an array of unsigned 16-bit integers and swaps the
1934
- byte order * in-place* . Throws [ ` ERR_INVALID_BUFFER_SIZE ` ] if [ ` buf.length ` ] is
1935
- not a multiple of 2.
1936
+ byte order * in-place* . Throws [ ` ERR_INVALID_BUFFER_SIZE ` ] [ ] if [ ` buf.length ` ] [ ]
1937
+ is not a multiple of 2.
1936
1938
1937
1939
``` js
1938
1940
const buf1 = Buffer .from ([0x1 , 0x2 , 0x3 , 0x4 , 0x5 , 0x6 , 0x7 , 0x8 ]);
@@ -1967,8 +1969,8 @@ added: v5.10.0
1967
1969
* Returns: {Buffer} A reference to ` buf ` .
1968
1970
1969
1971
Interprets ` buf ` as an array of unsigned 32-bit integers and swaps the
1970
- byte order * in-place* . Throws [ ` ERR_INVALID_BUFFER_SIZE ` ] if [ ` buf.length ` ] is
1971
- not a multiple of 4.
1972
+ byte order * in-place* . Throws [ ` ERR_INVALID_BUFFER_SIZE ` ] [ ] if [ ` buf.length ` ] [ ]
1973
+ is not a multiple of 4.
1972
1974
1973
1975
``` js
1974
1976
const buf1 = Buffer .from ([0x1 , 0x2 , 0x3 , 0x4 , 0x5 , 0x6 , 0x7 , 0x8 ]);
@@ -1995,7 +1997,7 @@ added: v6.3.0
1995
1997
* Returns: {Buffer} A reference to ` buf ` .
1996
1998
1997
1999
Interprets ` buf ` as an array of 64-bit numbers and swaps byte order * in-place* .
1998
- Throws [ ` ERR_INVALID_BUFFER_SIZE ` ] if [ ` buf.length ` ] is not a multiple of 8.
2000
+ Throws [ ` ERR_INVALID_BUFFER_SIZE ` ] [ ] if [ ` buf.length ` ] [ ] is not a multiple of 8.
1999
2001
2000
2002
``` js
2001
2003
const buf1 = Buffer .from ([0x1 , 0x2 , 0x3 , 0x4 , 0x5 , 0x6 , 0x7 , 0x8 ]);
@@ -2024,7 +2026,7 @@ added: v0.9.2
2024
2026
2025
2027
* Returns: {Object}
2026
2028
2027
- Returns a JSON representation of ` buf ` . [ ` JSON.stringify() ` ] implicitly calls
2029
+ Returns a JSON representation of ` buf ` . [ ` JSON.stringify() ` ] [ ] implicitly calls
2028
2030
this function when stringifying a ` Buffer ` instance.
2029
2031
2030
2032
``` js
@@ -2052,7 +2054,7 @@ added: v0.1.90
2052
2054
* ` encoding ` {string} The character encoding to use. ** Default:** ` 'utf8' ` .
2053
2055
* ` start ` {integer} The byte offset to start decoding at. ** Default:** ` 0 ` .
2054
2056
* ` end ` {integer} The byte offset to stop decoding at (not inclusive).
2055
- ** Default:** [ ` buf.length ` ] .
2057
+ ** Default:** [ ` buf.length ` ] [ ] .
2056
2058
* Returns: {string}
2057
2059
2058
2060
Decodes ` buf ` to a string according to the specified character encoding in
@@ -2091,7 +2093,7 @@ added: v1.1.0
2091
2093
2092
2094
* Returns: {Iterator}
2093
2095
2094
- Creates and returns an [ iterator] for ` buf ` values (bytes). This function is
2096
+ Creates and returns an [ iterator] [ ] for ` buf ` values (bytes). This function is
2095
2097
called automatically when a ` Buffer ` is used in a ` for..of ` statement.
2096
2098
2097
2099
``` js
@@ -2498,7 +2500,7 @@ added: v0.5.4
2498
2500
2499
2501
Returns the maximum number of bytes that will be returned when
2500
2502
` buf.inspect() ` is called. This can be overridden by user modules. See
2501
- [ ` util.inspect() ` ] for more details on ` buf.inspect() ` behavior.
2503
+ [ ` util.inspect() ` ] [ ] for more details on ` buf.inspect() ` behavior.
2502
2504
2503
2505
Note that this is a property on the ` buffer ` module returned by
2504
2506
` require('buffer') ` , not on the ` Buffer ` global or a ` Buffer ` instance.
@@ -2560,7 +2562,7 @@ Note that this is a property on the `buffer` module returned by
2560
2562
deprecated: v6.0.0
2561
2563
-->
2562
2564
2563
- > Stability: 0 - Deprecated: Use [ ` Buffer.allocUnsafeSlow() ` ] instead.
2565
+ > Stability: 0 - Deprecated: Use [ ` Buffer.allocUnsafeSlow() ` ] [ ] instead.
2564
2566
2565
2567
Returns an un-pooled ` Buffer ` .
2566
2568
@@ -2598,13 +2600,13 @@ has observed undue memory retention in their applications.
2598
2600
deprecated: v6.0.0
2599
2601
-->
2600
2602
2601
- > Stability: 0 - Deprecated: Use [ ` Buffer.allocUnsafeSlow() ` ] instead.
2603
+ > Stability: 0 - Deprecated: Use [ ` Buffer.allocUnsafeSlow() ` ] [ ] instead.
2602
2604
2603
2605
* ` size ` {integer} The desired length of the new ` SlowBuffer ` .
2604
2606
2605
2607
Allocates a new ` Buffer ` of ` size ` bytes. If ` size ` is larger than
2606
- [ ` buffer.constants.MAX_LENGTH ` ] or smaller than 0, [ ` ERR_INVALID_OPT_VALUE ` ] is
2607
- thrown. A zero-length ` Buffer ` is created if ` size ` is 0.
2608
+ [ ` buffer.constants.MAX_LENGTH ` ] [ ] or smaller than 0, [ ` ERR_INVALID_OPT_VALUE ` ] [ ]
2609
+ is thrown. A zero-length ` Buffer ` is created if ` size ` is 0.
2608
2610
2609
2611
The underlying memory for ` SlowBuffer ` instances is * not initialized* . The
2610
2612
contents of a newly created ` SlowBuffer ` are unknown and may contain sensitive
0 commit comments