Skip to content

Commit 41bb110

Browse files
SheetJSDevrvagg
authored andcommitted
doc: Uint8Array support in Buffer functions
Buffer.from / new Buffer accept Uint8Array Fixes: #14118 Backport-PR-URL: #21590 PR-URL: #19949 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Vse Mozhet Byt <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Gus Caplan <[email protected]>
1 parent cf0577e commit 41bb110

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

doc/api/buffer.md

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@
66
77
Prior to the introduction of [`TypedArray`], the JavaScript language had no
88
mechanism for reading or manipulating streams of binary data. The `Buffer` class
9-
was introduced as part of the Node.js API to make it possible to interact with
10-
octet streams in the context of things like TCP streams and file system
11-
operations.
9+
was introduced as part of the Node.js API to enable interaction with octet
10+
streams in TCP streams, file system operations, and other contexts.
1211

1312
With [`TypedArray`] now available, the `Buffer` class implements the
1413
[`Uint8Array`] API in a manner that is more optimized and suitable for Node.js.
@@ -195,11 +194,11 @@ The character encodings currently supported by Node.js include:
195194
* `'hex'` - Encode each byte as two hexadecimal characters.
196195

197196
*Note*: Today's browsers follow the [WHATWG Encoding Standard][] which aliases
198-
both 'latin1' and ISO-8859-1 to win-1252. This means that while doing something
199-
like `http.get()`, if the returned charset is one of those listed in the WHATWG
200-
specification it is possible that the server actually returned
201-
win-1252-encoded data, and using `'latin1'` encoding may incorrectly decode the
202-
characters.
197+
both `'latin1'` and `'ISO-8859-1'` to `'win-1252'`. This means that while doing
198+
something like `http.get()`, if the returned charset is one of those listed in
199+
the WHATWG specification it is possible that the server actually returned
200+
`'win-1252'`-encoded data, and using `'latin1'` encoding may incorrectly decode
201+
the characters.
203202

204203
## Buffers and TypedArray
205204
<!-- YAML
@@ -338,7 +337,7 @@ Example:
338337
const buf = new Buffer([0x62, 0x75, 0x66, 0x66, 0x65, 0x72]);
339338
```
340339

341-
### new Buffer(arrayBuffer[, byteOffset [, length]])
340+
### new Buffer(arrayBuffer[, byteOffset[, length]])
342341
<!-- YAML
343342
added: v3.0.0
344343
deprecated: v6.0.0
@@ -407,7 +406,8 @@ changes:
407406

408407
> Stability: 0 - Deprecated: Use [`Buffer.from(buffer)`] instead.
409408
410-
* `buffer` {Buffer} An existing `Buffer` to copy data from.
409+
* `buffer` {Buffer|Uint8Array} An existing `Buffer` or [`Uint8Array`] from which
410+
to copy data.
411411

412412
Copies the passed `buffer` data onto a new `Buffer` instance.
413413

@@ -862,7 +862,8 @@ A `TypeError` will be thrown if `arrayBuffer` is not an [`ArrayBuffer`] or a
862862
added: v5.10.0
863863
-->
864864

865-
* `buffer` {Buffer} An existing `Buffer` to copy data from.
865+
* `buffer` {Buffer|Uint8Array} An existing `Buffer` or [`Uint8Array`] from which
866+
to copy data.
866867

867868
Copies the passed `buffer` data onto a new `Buffer` instance.
868869

@@ -1983,7 +1984,7 @@ added: v5.10.0
19831984

19841985
* Returns: {Buffer} A reference to `buf`.
19851986

1986-
Interprets `buf` as an array of unsigned 16-bit integers and swaps the byte-order
1987+
Interprets `buf` as an array of unsigned 16-bit integers and swaps the byte order
19871988
*in-place*. Throws a `RangeError` if [`buf.length`] is not a multiple of 2.
19881989

19891990
Examples:
@@ -2013,7 +2014,7 @@ added: v5.10.0
20132014

20142015
* Returns: {Buffer} A reference to `buf`.
20152016

2016-
Interprets `buf` as an array of unsigned 32-bit integers and swaps the byte-order
2017+
Interprets `buf` as an array of unsigned 32-bit integers and swaps the byte order
20172018
*in-place*. Throws a `RangeError` if [`buf.length`] is not a multiple of 4.
20182019

20192020
Examples:
@@ -2043,7 +2044,7 @@ added: v6.3.0
20432044

20442045
* Returns: {Buffer} A reference to `buf`.
20452046

2046-
Interprets `buf` as an array of 64-bit numbers and swaps the byte-order *in-place*.
2047+
Interprets `buf` as an array of 64-bit numbers and swaps the byte order *in-place*.
20472048
Throws a `RangeError` if [`buf.length`] is not a multiple of 8.
20482049

20492050
Examples:

0 commit comments

Comments
 (0)