From abdbe64508af6a82fec5dc5c85ca7567b33b0b9f Mon Sep 17 00:00:00 2001 From: Thomas den Hollander Date: Wed, 20 Sep 2017 11:53:29 +0200 Subject: [PATCH 1/4] add SharedArrayBuffer to Buffer documentation --- doc/api/buffer.md | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/doc/api/buffer.md b/doc/api/buffer.md index 0b01370f90f7ab..0893c90b3ec5f6 100644 --- a/doc/api/buffer.md +++ b/doc/api/buffer.md @@ -66,8 +66,8 @@ differently based on what arguments are provided: memory. * Passing a string, array, or `Buffer` as the first argument copies the passed object's data into the `Buffer`. -* Passing an [`ArrayBuffer`] returns a `Buffer` that shares allocated memory with - the given [`ArrayBuffer`]. +* Passing an [`ArrayBuffer`] or a [`SharedArrayBuffer`] returns a `Buffer` that + shares allocated memory with the given array buffer. Because the behavior of `new Buffer()` changes significantly based on the type of value passed as the first argument, applications that do not properly @@ -361,16 +361,16 @@ changes: > [`Buffer.from(arrayBuffer[, byteOffset [, length]])`][`Buffer.from(arrayBuffer)`] > instead. -* `arrayBuffer` {ArrayBuffer} An [`ArrayBuffer`] or the `.buffer` property of a - [`TypedArray`]. +* `arrayBuffer` {ArrayBuffer} An [`ArrayBuffer`], [`SharedArrayBuffer`] or the + `.buffer` property of a [`TypedArray`]. * `byteOffset` {integer} Index of first byte to expose. **Default:** `0` * `length` {integer} Number of bytes to expose. **Default:** `arrayBuffer.length - byteOffset` -This creates a view of the [`ArrayBuffer`] without copying the underlying -memory. For example, when passed a reference to the `.buffer` property of a -[`TypedArray`] instance, the newly created `Buffer` will share the same -allocated memory as the [`TypedArray`]. +This creates a view of the [`ArrayBuffer`] or [`SharedArrayBuffer`] without +copying the underlying memory. For example, when passed a reference to the +`.buffer` property of a [`TypedArray`] instance, the newly created `Buffer` will +share the same allocated memory as the [`TypedArray`]. The optional `byteOffset` and `length` arguments specify a memory range within the `arrayBuffer` that will be shared by the `Buffer`. @@ -703,8 +703,8 @@ console.log(`${str}: ${str.length} characters, ` + `${Buffer.byteLength(str, 'utf8')} bytes`); ``` -When `string` is a `Buffer`/[`DataView`]/[`TypedArray`]/[`ArrayBuffer`], the -actual byte length is returned. +When `string` is a `Buffer`/[`DataView`]/[`TypedArray`]/[`ArrayBuffer`]/ +[`SharedArrayBuffer`], the actual byte length is returned. ### Class Method: Buffer.compare(buf1, buf2) -* `arrayBuffer` {ArrayBuffer} An [`ArrayBuffer`] or the `.buffer` property of a - [`TypedArray`]. +* `arrayBuffer` {ArrayBuffer} An [`ArrayBuffer`], [`SharedArrayBuffer`], or the + `.buffer` property of a [`TypedArray`]. * `byteOffset` {integer} Index of first byte to expose. **Default:** `0` * `length` {integer} Number of bytes to expose. **Default:** `arrayBuffer.length - byteOffset` @@ -852,7 +852,8 @@ const buf = Buffer.from(ab, 0, 2); console.log(buf.length); ``` -A `TypeError` will be thrown if `arrayBuffer` is not an [`ArrayBuffer`]. +A `TypeError` will be thrown if `arrayBuffer` is not an [`ArrayBuffer`] or a +[`SharedArrayBuffer`]. ### Class Method: Buffer.from(buffer) -* `string` {string|Buffer|TypedArray|DataView|ArrayBuffer} A value to +* `string` {string|Buffer|TypedArray|DataView|ArrayBuffer|SharedArrayBuffer} A value to calculate the length of * `encoding` {string} If `string` is a string, this is its encoding. **Default:** `'utf8'` @@ -807,7 +807,7 @@ A `TypeError` will be thrown if `array` is not an `Array`. added: v5.10.0 --> -* `arrayBuffer` {ArrayBuffer} An [`ArrayBuffer`], [`SharedArrayBuffer`], or the +* `arrayBuffer` {ArrayBuffer|SharedArrayBuffer} An [`ArrayBuffer`], [`SharedArrayBuffer`], or the `.buffer` property of a [`TypedArray`]. * `byteOffset` {integer} Index of first byte to expose. **Default:** `0` * `length` {integer} Number of bytes to expose. From beb25240cb0626656886b14cbeb0a982e3227215 Mon Sep 17 00:00:00 2001 From: Thomas den Hollander Date: Wed, 4 Oct 2017 12:13:35 +0200 Subject: [PATCH 4/4] Wrap long lines --- doc/api/buffer.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/doc/api/buffer.md b/doc/api/buffer.md index 8ca16c780d3f08..c713bef878bac6 100644 --- a/doc/api/buffer.md +++ b/doc/api/buffer.md @@ -361,8 +361,8 @@ changes: > [`Buffer.from(arrayBuffer[, byteOffset [, length]])`][`Buffer.from(arrayBuffer)`] > instead. -* `arrayBuffer` {ArrayBuffer|SharedArrayBuffer} An [`ArrayBuffer`], [`SharedArrayBuffer`] or the - `.buffer` property of a [`TypedArray`]. +* `arrayBuffer` {ArrayBuffer|SharedArrayBuffer} An [`ArrayBuffer`], + [`SharedArrayBuffer`] or the `.buffer` property of a [`TypedArray`]. * `byteOffset` {integer} Index of first byte to expose. **Default:** `0` * `length` {integer} Number of bytes to expose. **Default:** `arrayBuffer.length - byteOffset` @@ -679,8 +679,8 @@ changes: or `ArrayBuffer`. --> -* `string` {string|Buffer|TypedArray|DataView|ArrayBuffer|SharedArrayBuffer} A value to - calculate the length of +* `string` {string|Buffer|TypedArray|DataView|ArrayBuffer|SharedArrayBuffer} A + value to calculate the length of * `encoding` {string} If `string` is a string, this is its encoding. **Default:** `'utf8'` * Returns: {integer} The number of bytes contained within `string` @@ -807,8 +807,8 @@ A `TypeError` will be thrown if `array` is not an `Array`. added: v5.10.0 --> -* `arrayBuffer` {ArrayBuffer|SharedArrayBuffer} An [`ArrayBuffer`], [`SharedArrayBuffer`], or the - `.buffer` property of a [`TypedArray`]. +* `arrayBuffer` {ArrayBuffer|SharedArrayBuffer} An [`ArrayBuffer`], + [`SharedArrayBuffer`], or the `.buffer` property of a [`TypedArray`]. * `byteOffset` {integer} Index of first byte to expose. **Default:** `0` * `length` {integer} Number of bytes to expose. **Default:** `arrayBuffer.length - byteOffset`