Skip to content

Commit 9214d64

Browse files
SheetJSDevjasnell
authored andcommitted
doc: Uint8Array support in Buffer functions
Buffer.from / new Buffer accept Uint8Array Fixes: #14118 PR-URL: #19949 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Gus Caplan <me@gus.host>
1 parent 9495d94 commit 9214d64

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

doc/api/buffer.md

Lines changed: 13 additions & 13 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.
@@ -193,8 +192,8 @@ Modern Web browsers follow the [WHATWG Encoding Standard][] which aliases
193192
both `'latin1'` and `'ISO-8859-1'` to `'win-1252'`. This means that while doing
194193
something like `http.get()`, if the returned charset is one of those listed in
195194
the WHATWG specification it is possible that the server actually returned
196-
win-1252-encoded data, and using `'latin1'` encoding may incorrectly decode the
197-
characters.
195+
`'win-1252'`-encoded data, and using `'latin1'` encoding may incorrectly decode
196+
the characters.
198197

199198
## Buffers and TypedArray
200199
<!-- YAML
@@ -326,7 +325,7 @@ Allocates a new `Buffer` using an `array` of octets.
326325
const buf = new Buffer([0x62, 0x75, 0x66, 0x66, 0x65, 0x72]);
327326
```
328327

329-
### new Buffer(arrayBuffer[, byteOffset [, length]])
328+
### new Buffer(arrayBuffer[, byteOffset[, length]])
330329
<!-- YAML
331330
added: v3.0.0
332331
deprecated: v6.0.0
@@ -401,7 +400,8 @@ changes:
401400

402401
> Stability: 0 - Deprecated: Use [`Buffer.from(buffer)`] instead.
403402
404-
* `buffer` {Buffer} An existing `Buffer` to copy data from.
403+
* `buffer` {Buffer|Uint8Array} An existing `Buffer` or [`Uint8Array`] from which
404+
to copy data.
405405

406406
Copies the passed `buffer` data onto a new `Buffer` instance.
407407

@@ -841,7 +841,8 @@ A `TypeError` will be thrown if `arrayBuffer` is not an [`ArrayBuffer`] or a
841841
added: v5.10.0
842842
-->
843843

844-
* `buffer` {Buffer} An existing `Buffer` to copy data from.
844+
* `buffer` {Buffer|Uint8Array} An existing `Buffer` or [`Uint8Array`] from which
845+
to copy data.
845846

846847
Copies the passed `buffer` data onto a new `Buffer` instance.
847848

@@ -1886,7 +1887,7 @@ added: v5.10.0
18861887
* Returns: {Buffer} A reference to `buf`.
18871888

18881889
Interprets `buf` as an array of unsigned 16-bit integers and swaps the
1889-
byte-order *in-place*. Throws [`ERR_INVALID_BUFFER_SIZE`] if [`buf.length`] is
1890+
byte order *in-place*. Throws [`ERR_INVALID_BUFFER_SIZE`] if [`buf.length`] is
18901891
not a multiple of 2.
18911892

18921893
```js
@@ -1914,7 +1915,7 @@ added: v5.10.0
19141915
* Returns: {Buffer} A reference to `buf`.
19151916

19161917
Interprets `buf` as an array of unsigned 32-bit integers and swaps the
1917-
byte-order *in-place*. Throws [`ERR_INVALID_BUFFER_SIZE`] if [`buf.length`] is
1918+
byte order *in-place*. Throws [`ERR_INVALID_BUFFER_SIZE`] if [`buf.length`] is
19181919
not a multiple of 4.
19191920

19201921
```js
@@ -1941,9 +1942,8 @@ added: v6.3.0
19411942

19421943
* Returns: {Buffer} A reference to `buf`.
19431944

1944-
Interprets `buf` as an array of 64-bit numbers and swaps the byte-order
1945-
*in-place*. Throws [`ERR_INVALID_BUFFER_SIZE`] if [`buf.length`] is not a
1946-
multiple of 8.
1945+
Interprets `buf` as an array of 64-bit numbers and swaps byte order *in-place*.
1946+
Throws [`ERR_INVALID_BUFFER_SIZE`] if [`buf.length`] is not a multiple of 8.
19471947

19481948
```js
19491949
const buf1 = Buffer.from([0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8]);

0 commit comments

Comments
 (0)