9
9
` Buffer ` objects are used to represent a fixed-length sequence of bytes. Many
10
10
Node.js APIs support ` Buffer ` s.
11
11
12
- The ` Buffer ` class is a subclass of JavaScript's [ ` Uint8Array ` ] [ ] class and
12
+ The ` Buffer ` class is a subclass of JavaScript's { Uint8Array} class and
13
13
extends it with methods that cover additional use cases. Node.js APIs accept
14
- plain [ ` Uint8Array ` ] [ ] s wherever ` Buffer ` s are supported as well.
14
+ plain { Uint8Array} s wherever ` Buffer ` s are supported as well.
15
15
16
16
While the ` Buffer ` class is available within the global scope, it is still
17
17
recommended to explicitly reference it via an import or require statement.
@@ -242,10 +242,10 @@ changes:
242
242
description: The `Buffer`s class now inherits from `Uint8Array`.
243
243
-->
244
244
245
- ` Buffer ` instances are also JavaScript [ ` Uint8Array ` ] [ ] and [ ` TypedArray ` ] [ ]
246
- instances. All [ ` TypedArray ` ] [ ] methods are available on ` Buffer ` s. There are,
245
+ ` Buffer ` instances are also JavaScript { Uint8Array} and { TypedArray}
246
+ instances. All { TypedArray} methods are available on ` Buffer ` s. There are,
247
247
however, subtle incompatibilities between the ` Buffer ` API and the
248
- [ ` TypedArray ` ] [ ] API.
248
+ { TypedArray} API.
249
249
250
250
In particular:
251
251
@@ -258,9 +258,9 @@ In particular:
258
258
* [ ` buf.toString() ` ] [ ] is incompatible with its ` TypedArray ` equivalent.
259
259
* A number of methods, e.g. [ ` buf.indexOf() ` ] [ ] , support additional arguments.
260
260
261
- There are two ways to create new [ ` TypedArray ` ] [ ] instances from a ` Buffer ` :
261
+ There are two ways to create new { TypedArray} instances from a ` Buffer ` :
262
262
263
- * Passing a ` Buffer ` to a [ ` TypedArray ` ] [ ] constructor will copy the ` Buffer ` s
263
+ * Passing a ` Buffer ` to a { TypedArray} constructor will copy the ` Buffer ` s
264
264
contents, interpreted as an array of integers, and not as a byte sequence
265
265
of the target type.
266
266
@@ -286,8 +286,8 @@ console.log(uint32array);
286
286
// Prints: Uint32Array(4) [ 1, 2, 3, 4 ]
287
287
```
288
288
289
- * Passing the ` Buffer ` s underlying [ ` ArrayBuffer ` ] [ ] will create a
290
- [ ` TypedArray ` ] [ ] that shares its memory with the ` Buffer ` .
289
+ * Passing the ` Buffer ` s underlying { ArrayBuffer} will create a
290
+ { TypedArray} that shares its memory with the ` Buffer ` .
291
291
292
292
``` mjs
293
293
import { Buffer } from ' node:buffer' ;
@@ -318,7 +318,7 @@ console.log(uint16array);
318
318
```
319
319
320
320
It is possible to create a new ` Buffer ` that shares the same allocated
321
- memory as a [ ` TypedArray ` ] [ ] instance by using the ` TypedArray ` object's
321
+ memory as a { TypedArray} instance by using the ` TypedArray ` object's
322
322
` .buffer ` property in the same way. [ ` Buffer.from() ` ] [ `Buffer.from(arrayBuf)` ]
323
323
behaves like ` new Uint8Array() ` in this context.
324
324
@@ -376,8 +376,8 @@ console.log(buf2);
376
376
// Prints: <Buffer 88 13 70 17>
377
377
```
378
378
379
- When creating a ` Buffer ` using a [ ` TypedArray ` ] [ ] 's ` .buffer ` , it is
380
- possible to use only a portion of the underlying [ ` ArrayBuffer ` ] [ ] by passing in
379
+ When creating a ` Buffer ` using a { TypedArray} 's ` .buffer ` , it is
380
+ possible to use only a portion of the underlying { ArrayBuffer} by passing in
381
381
` byteOffset ` and ` length ` parameters.
382
382
383
383
``` mjs
@@ -401,7 +401,7 @@ console.log(buf.length);
401
401
```
402
402
403
403
The ` Buffer.from() ` and [ ` TypedArray.from() ` ] [ ] have different signatures and
404
- implementations. Specifically, the [ ` TypedArray ` ] [ ] variants accept a second
404
+ implementations. Specifically, the { TypedArray} variants accept a second
405
405
argument that is a mapping function that is invoked on every element of the
406
406
typed array:
407
407
@@ -967,9 +967,8 @@ console.log(`${str}: ${str.length} characters, ` +
967
967
// Prints: ½ + ¼ = ¾: 9 characters, 12 bytes
968
968
```
969
969
970
- When ` string ` is a ` Buffer ` /[ ` DataView ` ] [ ] /[ ` TypedArray ` ] [ ] /[ ` ArrayBuffer ` ] [ ] /
971
- [ ` SharedArrayBuffer ` ] [ ] , the byte length as reported by ` .byteLength `
972
- is returned.
970
+ When ` string ` is a {Buffer|DataView|TypedArray|ArrayBuffer|SharedArrayBuffer},
971
+ the byte length as reported by ` .byteLength ` is returned.
973
972
974
973
### Static method: ` Buffer.compare(buf1, buf2) `
975
974
@@ -1024,7 +1023,7 @@ changes:
1024
1023
description: The elements of `list` can now be `Uint8Array`s.
1025
1024
-->
1026
1025
1027
- * ` list ` {Buffer\[ ] | Uint8Array\[ ] } List of ` Buffer ` or [ ` Uint8Array ` ] [ ]
1026
+ * ` list ` {Buffer\[ ] | Uint8Array\[ ] } List of ` Buffer ` or { Uint8Array}
1028
1027
instances to concatenate.
1029
1028
* ` totalLength ` {integer} Total length of the ` Buffer ` instances in ` list `
1030
1029
when concatenated.
@@ -1158,18 +1157,18 @@ appropriate for `Buffer.from()` variants.
1158
1157
added: v5.10.0
1159
1158
-->
1160
1159
1161
- * ` arrayBuffer ` {ArrayBuffer|SharedArrayBuffer} An [ ` ArrayBuffer ` ] [ ] ,
1162
- [ ` SharedArrayBuffer ` ] [ ] , for example the ` .buffer ` property of a
1163
- [ ` TypedArray ` ] [ ] .
1160
+ * ` arrayBuffer ` {ArrayBuffer|SharedArrayBuffer} An { ArrayBuffer} ,
1161
+ { SharedArrayBuffer} , for example the ` .buffer ` property of a
1162
+ { TypedArray} .
1164
1163
* ` byteOffset ` {integer} Index of first byte to expose. ** Default:** ` 0 ` .
1165
1164
* ` length ` {integer} Number of bytes to expose.
1166
1165
** Default:** ` arrayBuffer.byteLength - byteOffset ` .
1167
1166
* Returns: {Buffer}
1168
1167
1169
- This creates a view of the [ ` ArrayBuffer ` ] [ ] without copying the underlying
1168
+ This creates a view of the { ArrayBuffer} without copying the underlying
1170
1169
memory. For example, when passed a reference to the ` .buffer ` property of a
1171
- [ ` TypedArray ` ] [ ] instance, the newly created ` Buffer ` will share the same
1172
- allocated memory as the [ ` TypedArray ` ] [ ] 's underlying ` ArrayBuffer ` .
1170
+ { TypedArray} instance, the newly created ` Buffer ` will share the same
1171
+ allocated memory as the { TypedArray} 's underlying ` ArrayBuffer ` .
1173
1172
1174
1173
``` mjs
1175
1174
import { Buffer } from ' node:buffer' ;
@@ -1236,8 +1235,8 @@ console.log(buf.length);
1236
1235
// Prints: 2
1237
1236
```
1238
1237
1239
- A ` TypeError ` will be thrown if ` arrayBuffer ` is not an [ ` ArrayBuffer ` ] [ ] or a
1240
- [ ` SharedArrayBuffer ` ] [ ] or another type appropriate for ` Buffer.from() `
1238
+ A ` TypeError ` will be thrown if ` arrayBuffer ` is not an { ArrayBuffer} or a
1239
+ { SharedArrayBuffer} or another type appropriate for ` Buffer.from() `
1241
1240
variants.
1242
1241
1243
1242
It is important to remember that a backing ` ArrayBuffer ` can cover a range
@@ -1275,7 +1274,7 @@ console.log(buf);
1275
1274
added: v5.10.0
1276
1275
-->
1277
1276
1278
- * ` buffer ` {Buffer|Uint8Array} An existing ` Buffer ` or [ ` Uint8Array ` ] [ ] from
1277
+ * ` buffer ` {Buffer|Uint8Array} An existing ` Buffer ` or { Uint8Array} from
1279
1278
which to copy data.
1280
1279
* Returns: {Buffer}
1281
1280
@@ -1635,7 +1634,7 @@ changes:
1635
1634
description: Additional parameters for specifying offsets are supported now.
1636
1635
-->
1637
1636
1638
- * ` target ` {Buffer|Uint8Array} A ` Buffer ` or [ ` Uint8Array ` ] [ ] with which to
1637
+ * ` target ` {Buffer|Uint8Array} A ` Buffer ` or { Uint8Array} with which to
1639
1638
compare ` buf ` .
1640
1639
* ` targetStart ` {integer} The offset within ` target ` at which to begin
1641
1640
comparison. ** Default:** ` 0 ` .
@@ -1740,7 +1739,7 @@ console.log(buf1.compare(buf2, 5, 6, 5));
1740
1739
added: v0.1.90
1741
1740
-->
1742
1741
1743
- * ` target ` {Buffer|Uint8Array} A ` Buffer ` or [ ` Uint8Array ` ] [ ] to copy into.
1742
+ * ` target ` {Buffer|Uint8Array} A ` Buffer ` or { Uint8Array} to copy into.
1744
1743
* ` targetStart ` {integer} The offset within ` target ` at which to begin
1745
1744
writing. ** Default:** ` 0 ` .
1746
1745
* ` sourceStart ` {integer} The offset within ` buf ` from which to begin copying.
@@ -1895,7 +1894,7 @@ changes:
1895
1894
description: The arguments can now be `Uint8Array`s.
1896
1895
-->
1897
1896
1898
- * ` otherBuffer ` {Buffer|Uint8Array} A ` Buffer ` or [ ` Uint8Array ` ] [ ] with which to
1897
+ * ` otherBuffer ` {Buffer|Uint8Array} A ` Buffer ` or { Uint8Array} with which to
1899
1898
compare ` buf ` .
1900
1899
* Returns: {boolean}
1901
1900
@@ -2140,7 +2139,7 @@ If `value` is:
2140
2139
2141
2140
* a string, ` value ` is interpreted according to the character encoding in
2142
2141
` encoding ` .
2143
- * a ` Buffer ` or [ ` Uint8Array ` ] [ ] , ` value ` will be used in its entirety.
2142
+ * a ` Buffer ` or { Uint8Array} , ` value ` will be used in its entirety.
2144
2143
To compare a partial ` Buffer ` , use [ ` buf.subarray ` ] [ ] .
2145
2144
* a number, ` value ` will be interpreted as an unsigned 8-bit integer
2146
2145
value between ` 0 ` and ` 255 ` .
@@ -5009,8 +5008,8 @@ changes:
5009
5008
> [ ` Buffer.from(arrayBuffer[, byteOffset[, length]]) ` ] [ `Buffer.from(arrayBuf)` ]
5010
5009
> instead.
5011
5010
5012
- * ` arrayBuffer ` {ArrayBuffer|SharedArrayBuffer} An [ ` ArrayBuffer ` ] [ ] ,
5013
- [ ` SharedArrayBuffer ` ] [ ] or the ` .buffer ` property of a [ ` TypedArray ` ] [ ] .
5011
+ * ` arrayBuffer ` {ArrayBuffer|SharedArrayBuffer} An { ArrayBuffer} ,
5012
+ { SharedArrayBuffer} or the ` .buffer ` property of a { TypedArray} .
5014
5013
* ` byteOffset ` {integer} Index of first byte to expose. ** Default:** ` 0 ` .
5015
5014
* ` length ` {integer} Number of bytes to expose.
5016
5015
** Default:** ` arrayBuffer.byteLength - byteOffset ` .
@@ -5037,7 +5036,7 @@ changes:
5037
5036
5038
5037
> Stability: 0 - Deprecated: Use [ ` Buffer.from(buffer) ` ] [ ] instead.
5039
5038
5040
- * ` buffer ` {Buffer|Uint8Array} An existing ` Buffer ` or [ ` Uint8Array ` ] [ ] from
5039
+ * ` buffer ` {Buffer|Uint8Array} An existing ` Buffer ` or { Uint8Array} from
5041
5040
which to copy data.
5042
5041
5043
5042
See [ ` Buffer.from(buffer) ` ] [ ] .
@@ -5110,7 +5109,7 @@ changes:
5110
5109
5111
5110
* Extends: {Blob}
5112
5111
5113
- A [ ` File ` ] [ ] provides information about files.
5112
+ A { File} provides information about files.
5114
5113
5115
5114
### ` new buffer.File(sources, fileName[, options]) `
5116
5115
@@ -5427,7 +5426,7 @@ differently based on what arguments are provided:
5427
5426
Buffer(num)` return a ` Buffer` with initialized memory.
5428
5427
* Passing a string, array, or ` Buffer ` as the first argument copies the
5429
5428
passed object's data into the ` Buffer ` .
5430
- * Passing an [ ` ArrayBuffer ` ] [ ] or a [ ` SharedArrayBuffer ` ] [ ] returns a ` Buffer `
5429
+ * Passing an { ArrayBuffer} or a { SharedArrayBuffer} returns a ` Buffer `
5431
5430
that shares allocated memory with the given array buffer.
5432
5431
5433
5432
Because the behavior of ` new Buffer() ` is different depending on the type of the
@@ -5461,7 +5460,7 @@ to one of these new APIs._
5461
5460
provided octets.
5462
5461
* [ ` Buffer.from(arrayBuffer[, byteOffset[, length]]) ` ] [ `Buffer.from(arrayBuf)` ]
5463
5462
returns a new ` Buffer ` that _ shares the same allocated memory_ as the given
5464
- [ ` ArrayBuffer ` ] [ ] .
5463
+ { ArrayBuffer} .
5465
5464
* [ ` Buffer.from(buffer) ` ] [ ] returns a new ` Buffer ` that _ contains a copy_ of the
5466
5465
contents of the given ` Buffer ` .
5467
5466
* [ ` Buffer.from(string[, encoding]) ` ] [ `Buffer.from(string)` ] returns a new
@@ -5523,7 +5522,6 @@ introducing security vulnerabilities into an application.
5523
5522
[ UTF-16 ] : https://en.wikipedia.org/wiki/UTF-16
5524
5523
[ UTF-8 ] : https://en.wikipedia.org/wiki/UTF-8
5525
5524
[ WHATWG Encoding Standard ] : https://encoding.spec.whatwg.org/
5526
- [ `ArrayBuffer` ] : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer
5527
5525
[ `Blob` ] : https://developer.mozilla.org/en-US/docs/Web/API/Blob
5528
5526
[ `Buffer.alloc()` ] : #static-method-bufferallocsize-fill-encoding
5529
5527
[ `Buffer.allocUnsafe()` ] : #static-method-bufferallocunsafesize
@@ -5535,21 +5533,16 @@ introducing security vulnerabilities into an application.
5535
5533
[ `Buffer.from(buffer)` ] : #static-method-bufferfrombuffer
5536
5534
[ `Buffer.from(string)` ] : #static-method-bufferfromstring-encoding
5537
5535
[ `Buffer.poolSize` ] : #class-property-bufferpoolsize
5538
- [ `DataView` ] : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView
5539
5536
[ `ERR_INVALID_BUFFER_SIZE` ] : errors.md#err_invalid_buffer_size
5540
5537
[ `ERR_OUT_OF_RANGE` ] : errors.md#err_out_of_range
5541
- [ `File` ] : https://developer.mozilla.org/en-US/docs/Web/API/File
5542
5538
[ `JSON.stringify()` ] : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify
5543
- [ `SharedArrayBuffer` ] : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer
5544
5539
[ `String.prototype.indexOf()` ] : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/indexOf
5545
5540
[ `String.prototype.lastIndexOf()` ] : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/lastIndexOf
5546
5541
[ `String.prototype.length` ] : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/length
5547
5542
[ `TypedArray.from()` ] : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/from
5548
5543
[ `TypedArray.prototype.set()` ] : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/set
5549
5544
[ `TypedArray.prototype.slice()` ] : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/slice
5550
5545
[ `TypedArray.prototype.subarray()` ] : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/subarray
5551
- [ `TypedArray` ] : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray
5552
- [ `Uint8Array` ] : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array
5553
5546
[ `buf.buffer` ] : #bufbuffer
5554
5547
[ `buf.compare()` ] : #bufcomparetarget-targetstart-targetend-sourcestart-sourceend
5555
5548
[ `buf.entries()` ] : #bufentries
0 commit comments