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
@@ -968,9 +968,8 @@ console.log(`${str}: ${str.length} characters, ` +
968
968
// Prints: ½ + ¼ = ¾: 9 characters, 12 bytes
969
969
```
970
970
971
- When ` string ` is a ` Buffer ` /[ ` DataView ` ] [ ] /[ ` TypedArray ` ] [ ] /[ ` ArrayBuffer ` ] [ ] /
972
- [ ` SharedArrayBuffer ` ] [ ] , the byte length as reported by ` .byteLength `
973
- is returned.
971
+ When ` string ` is a {Buffer|DataView|TypedArray|ArrayBuffer|SharedArrayBuffer},
972
+ the byte length as reported by ` .byteLength ` is returned.
974
973
975
974
### Static method: ` Buffer.compare(buf1, buf2) `
976
975
@@ -1025,7 +1024,7 @@ changes:
1025
1024
description: The elements of `list` can now be `Uint8Array`s.
1026
1025
-->
1027
1026
1028
- * ` list ` {Buffer\[ ] | Uint8Array\[ ] } List of ` Buffer ` or [ ` Uint8Array ` ] [ ]
1027
+ * ` list ` {Buffer\[ ] | Uint8Array\[ ] } List of ` Buffer ` or { Uint8Array}
1029
1028
instances to concatenate.
1030
1029
* ` totalLength ` {integer} Total length of the ` Buffer ` instances in ` list `
1031
1030
when concatenated.
@@ -1159,18 +1158,18 @@ appropriate for `Buffer.from()` variants.
1159
1158
added: v5.10.0
1160
1159
-->
1161
1160
1162
- * ` arrayBuffer ` {ArrayBuffer|SharedArrayBuffer} An [ ` ArrayBuffer ` ] [ ] ,
1163
- [ ` SharedArrayBuffer ` ] [ ] , for example the ` .buffer ` property of a
1164
- [ ` TypedArray ` ] [ ] .
1161
+ * ` arrayBuffer ` {ArrayBuffer|SharedArrayBuffer} An { ArrayBuffer} ,
1162
+ { SharedArrayBuffer} , for example the ` .buffer ` property of a
1163
+ { TypedArray} .
1165
1164
* ` byteOffset ` {integer} Index of first byte to expose. ** Default:** ` 0 ` .
1166
1165
* ` length ` {integer} Number of bytes to expose.
1167
1166
** Default:** ` arrayBuffer.byteLength - byteOffset ` .
1168
1167
* Returns: {Buffer}
1169
1168
1170
- This creates a view of the [ ` ArrayBuffer ` ] [ ] without copying the underlying
1169
+ This creates a view of the { ArrayBuffer} without copying the underlying
1171
1170
memory. For example, when passed a reference to the ` .buffer ` property of a
1172
- [ ` TypedArray ` ] [ ] instance, the newly created ` Buffer ` will share the same
1173
- allocated memory as the [ ` TypedArray ` ] [ ] 's underlying ` ArrayBuffer ` .
1171
+ { TypedArray} instance, the newly created ` Buffer ` will share the same
1172
+ allocated memory as the { TypedArray} 's underlying ` ArrayBuffer ` .
1174
1173
1175
1174
``` mjs
1176
1175
import { Buffer } from ' node:buffer' ;
@@ -1237,8 +1236,8 @@ console.log(buf.length);
1237
1236
// Prints: 2
1238
1237
```
1239
1238
1240
- A ` TypeError ` will be thrown if ` arrayBuffer ` is not an [ ` ArrayBuffer ` ] [ ] or a
1241
- [ ` SharedArrayBuffer ` ] [ ] or another type appropriate for ` Buffer.from() `
1239
+ A ` TypeError ` will be thrown if ` arrayBuffer ` is not an { ArrayBuffer} or a
1240
+ { SharedArrayBuffer} or another type appropriate for ` Buffer.from() `
1242
1241
variants.
1243
1242
1244
1243
It is important to remember that a backing ` ArrayBuffer ` can cover a range
@@ -1276,7 +1275,7 @@ console.log(buf);
1276
1275
added: v5.10.0
1277
1276
-->
1278
1277
1279
- * ` buffer ` {Buffer|Uint8Array} An existing ` Buffer ` or [ ` Uint8Array ` ] [ ] from
1278
+ * ` buffer ` {Buffer|Uint8Array} An existing ` Buffer ` or { Uint8Array} from
1280
1279
which to copy data.
1281
1280
* Returns: {Buffer}
1282
1281
@@ -1636,7 +1635,7 @@ changes:
1636
1635
description: Additional parameters for specifying offsets are supported now.
1637
1636
-->
1638
1637
1639
- * ` target ` {Buffer|Uint8Array} A ` Buffer ` or [ ` Uint8Array ` ] [ ] with which to
1638
+ * ` target ` {Buffer|Uint8Array} A ` Buffer ` or { Uint8Array} with which to
1640
1639
compare ` buf ` .
1641
1640
* ` targetStart ` {integer} The offset within ` target ` at which to begin
1642
1641
comparison. ** Default:** ` 0 ` .
@@ -1741,7 +1740,7 @@ console.log(buf1.compare(buf2, 5, 6, 5));
1741
1740
added: v0.1.90
1742
1741
-->
1743
1742
1744
- * ` target ` {Buffer|Uint8Array} A ` Buffer ` or [ ` Uint8Array ` ] [ ] to copy into.
1743
+ * ` target ` {Buffer|Uint8Array} A ` Buffer ` or { Uint8Array} to copy into.
1745
1744
* ` targetStart ` {integer} The offset within ` target ` at which to begin
1746
1745
writing. ** Default:** ` 0 ` .
1747
1746
* ` sourceStart ` {integer} The offset within ` buf ` from which to begin copying.
@@ -1896,7 +1895,7 @@ changes:
1896
1895
description: The arguments can now be `Uint8Array`s.
1897
1896
-->
1898
1897
1899
- * ` otherBuffer ` {Buffer|Uint8Array} A ` Buffer ` or [ ` Uint8Array ` ] [ ] with which to
1898
+ * ` otherBuffer ` {Buffer|Uint8Array} A ` Buffer ` or { Uint8Array} with which to
1900
1899
compare ` buf ` .
1901
1900
* Returns: {boolean}
1902
1901
@@ -2141,7 +2140,7 @@ If `value` is:
2141
2140
2142
2141
* a string, ` value ` is interpreted according to the character encoding in
2143
2142
` encoding ` .
2144
- * a ` Buffer ` or [ ` Uint8Array ` ] [ ] , ` value ` will be used in its entirety.
2143
+ * a ` Buffer ` or { Uint8Array} , ` value ` will be used in its entirety.
2145
2144
To compare a partial ` Buffer ` , use [ ` buf.subarray ` ] [ ] .
2146
2145
* a number, ` value ` will be interpreted as an unsigned 8-bit integer
2147
2146
value between ` 0 ` and ` 255 ` .
@@ -5010,8 +5009,8 @@ changes:
5010
5009
> [ ` Buffer.from(arrayBuffer[, byteOffset[, length]]) ` ] [ `Buffer.from(arrayBuf)` ]
5011
5010
> instead.
5012
5011
5013
- * ` arrayBuffer ` {ArrayBuffer|SharedArrayBuffer} An [ ` ArrayBuffer ` ] [ ] ,
5014
- [ ` SharedArrayBuffer ` ] [ ] or the ` .buffer ` property of a [ ` TypedArray ` ] [ ] .
5012
+ * ` arrayBuffer ` {ArrayBuffer|SharedArrayBuffer} An { ArrayBuffer} ,
5013
+ { SharedArrayBuffer} or the ` .buffer ` property of a { TypedArray} .
5015
5014
* ` byteOffset ` {integer} Index of first byte to expose. ** Default:** ` 0 ` .
5016
5015
* ` length ` {integer} Number of bytes to expose.
5017
5016
** Default:** ` arrayBuffer.byteLength - byteOffset ` .
@@ -5038,7 +5037,7 @@ changes:
5038
5037
5039
5038
> Stability: 0 - Deprecated: Use [ ` Buffer.from(buffer) ` ] [ ] instead.
5040
5039
5041
- * ` buffer ` {Buffer|Uint8Array} An existing ` Buffer ` or [ ` Uint8Array ` ] [ ] from
5040
+ * ` buffer ` {Buffer|Uint8Array} An existing ` Buffer ` or { Uint8Array} from
5042
5041
which to copy data.
5043
5042
5044
5043
See [ ` Buffer.from(buffer) ` ] [ ] .
@@ -5114,7 +5113,7 @@ changes:
5114
5113
5115
5114
* Extends: {Blob}
5116
5115
5117
- A [ ` File ` ] [ ] provides information about files.
5116
+ A { File} provides information about files.
5118
5117
5119
5118
### ` new buffer.File(sources, fileName[, options]) `
5120
5119
@@ -5431,7 +5430,7 @@ differently based on what arguments are provided:
5431
5430
Buffer(num)` return a ` Buffer` with initialized memory.
5432
5431
* Passing a string, array, or ` Buffer ` as the first argument copies the
5433
5432
passed object's data into the ` Buffer ` .
5434
- * Passing an [ ` ArrayBuffer ` ] [ ] or a [ ` SharedArrayBuffer ` ] [ ] returns a ` Buffer `
5433
+ * Passing an { ArrayBuffer} or a { SharedArrayBuffer} returns a ` Buffer `
5435
5434
that shares allocated memory with the given array buffer.
5436
5435
5437
5436
Because the behavior of ` new Buffer() ` is different depending on the type of the
@@ -5465,7 +5464,7 @@ to one of these new APIs._
5465
5464
provided octets.
5466
5465
* [ ` Buffer.from(arrayBuffer[, byteOffset[, length]]) ` ] [ `Buffer.from(arrayBuf)` ]
5467
5466
returns a new ` Buffer ` that _ shares the same allocated memory_ as the given
5468
- [ ` ArrayBuffer ` ] [ ] .
5467
+ { ArrayBuffer} .
5469
5468
* [ ` Buffer.from(buffer) ` ] [ ] returns a new ` Buffer ` that _ contains a copy_ of the
5470
5469
contents of the given ` Buffer ` .
5471
5470
* [ ` Buffer.from(string[, encoding]) ` ] [ `Buffer.from(string)` ] returns a new
@@ -5527,7 +5526,6 @@ introducing security vulnerabilities into an application.
5527
5526
[ UTF-16 ] : https://en.wikipedia.org/wiki/UTF-16
5528
5527
[ UTF-8 ] : https://en.wikipedia.org/wiki/UTF-8
5529
5528
[ WHATWG Encoding Standard ] : https://encoding.spec.whatwg.org/
5530
- [ `ArrayBuffer` ] : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer
5531
5529
[ `Blob` ] : https://developer.mozilla.org/en-US/docs/Web/API/Blob
5532
5530
[ `Buffer.alloc()` ] : #static-method-bufferallocsize-fill-encoding
5533
5531
[ `Buffer.allocUnsafe()` ] : #static-method-bufferallocunsafesize
@@ -5539,21 +5537,16 @@ introducing security vulnerabilities into an application.
5539
5537
[ `Buffer.from(buffer)` ] : #static-method-bufferfrombuffer
5540
5538
[ `Buffer.from(string)` ] : #static-method-bufferfromstring-encoding
5541
5539
[ `Buffer.poolSize` ] : #class-property-bufferpoolsize
5542
- [ `DataView` ] : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView
5543
5540
[ `ERR_INVALID_BUFFER_SIZE` ] : errors.md#err_invalid_buffer_size
5544
5541
[ `ERR_OUT_OF_RANGE` ] : errors.md#err_out_of_range
5545
- [ `File` ] : https://developer.mozilla.org/en-US/docs/Web/API/File
5546
5542
[ `JSON.stringify()` ] : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify
5547
- [ `SharedArrayBuffer` ] : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer
5548
5543
[ `String.prototype.indexOf()` ] : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/indexOf
5549
5544
[ `String.prototype.lastIndexOf()` ] : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/lastIndexOf
5550
5545
[ `String.prototype.length` ] : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/length
5551
5546
[ `TypedArray.from()` ] : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/from
5552
5547
[ `TypedArray.prototype.set()` ] : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/set
5553
5548
[ `TypedArray.prototype.slice()` ] : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/slice
5554
5549
[ `TypedArray.prototype.subarray()` ] : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/subarray
5555
- [ `TypedArray` ] : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray
5556
- [ `Uint8Array` ] : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array
5557
5550
[ `buf.buffer` ] : #bufbuffer
5558
5551
[ `buf.compare()` ] : #bufcomparetarget-targetstart-targetend-sourcestart-sourceend
5559
5552
[ `buf.entries()` ] : #bufentries
0 commit comments