Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc: Uint8Array support in Buffer functions #19949

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions doc/api/buffer.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@

Prior to the introduction of [`TypedArray`], the JavaScript language had no
mechanism for reading or manipulating streams of binary data. The `Buffer` class
was introduced as part of the Node.js API to make it possible to interact with
octet streams in the context of things like TCP streams and file system
operations.
was introduced as part of the Node.js API to enable interaction with octet
streams in TCP streams, file system operations, and other contexts.

With [`TypedArray`] now available, the `Buffer` class implements the
[`Uint8Array`] API in a manner that is more optimized and suitable for Node.js.
Expand Down Expand Up @@ -193,8 +192,8 @@ Modern Web browsers follow the [WHATWG Encoding Standard][] which aliases
both `'latin1'` and `'ISO-8859-1'` to `'win-1252'`. This means that while doing
something like `http.get()`, if the returned charset is one of those listed in
the WHATWG specification it is possible that the server actually returned
win-1252-encoded data, and using `'latin1'` encoding may incorrectly decode the
characters.
`'win-1252'`-encoded data, and using `'latin1'` encoding may incorrectly decode
the characters.

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

### new Buffer(arrayBuffer[, byteOffset [, length]])
### new Buffer(arrayBuffer[, byteOffset[, length]])
<!-- YAML
added: v3.0.0
deprecated: v6.0.0
Expand Down Expand Up @@ -401,7 +400,8 @@ changes:

> Stability: 0 - Deprecated: Use [`Buffer.from(buffer)`] instead.

* `buffer` {Buffer} An existing `Buffer` to copy data from.
* `buffer` {Buffer|Uint8Array} An existing `Buffer` or [`Uint8Array`] from which
to copy data.

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

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

* `buffer` {Buffer} An existing `Buffer` to copy data from.
* `buffer` {Buffer|Uint8Array} An existing `Buffer` or [`Uint8Array`] from which
to copy data.

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

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

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

```js
Expand Down Expand Up @@ -1914,7 +1915,7 @@ added: v5.10.0
* Returns: {Buffer} A reference to `buf`.

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

```js
Expand All @@ -1941,9 +1942,8 @@ added: v6.3.0

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

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

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