diff options
author | Anna Henningsen <anna@addaleax.net> | 2016-12-10 22:28:37 +0100 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2016-12-21 07:48:14 +0100 |
commit | beca3244e2792bc4257f480b138c1b603de3781c (patch) | |
tree | f298c9f0deef44b2003f4bc4da1098fef0347d76 /doc/api/buffer.md | |
parent | 6cb33c0764f307e33d29655cd1bac2916656352a (diff) | |
download | android-node-v8-beca3244e2792bc4257f480b138c1b603de3781c.tar.gz android-node-v8-beca3244e2792bc4257f480b138c1b603de3781c.tar.bz2 android-node-v8-beca3244e2792bc4257f480b138c1b603de3781c.zip |
buffer: allow Uint8Array input to methods
Allow all methods on `buffer` and `Buffer` to take `Uint8Array`
arguments where it makes sense. On the native side, there is
effectively no difference, and as a bonus the `isUint8Array`
check is faster than `instanceof Buffer`.
PR-URL: https://github.com/nodejs/node/pull/10236
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com>
Diffstat (limited to 'doc/api/buffer.md')
-rw-r--r-- | doc/api/buffer.md | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/doc/api/buffer.md b/doc/api/buffer.md index b9f8369335..33da664c27 100644 --- a/doc/api/buffer.md +++ b/doc/api/buffer.md @@ -635,8 +635,8 @@ actual byte length is returned. added: v0.11.13 --> -* `buf1` {Buffer} -* `buf2` {Buffer} +* `buf1` {Buffer|Uint8Array} +* `buf2` {Buffer|Uint8Array} * Returns: {Integer} Compares `buf1` to `buf2` typically for the purpose of sorting arrays of @@ -660,7 +660,7 @@ console.log(arr.sort(Buffer.compare)); added: v0.7.11 --> -* `list` {Array} List of `Buffer` instances to concat +* `list` {Array} List of `Buffer` or [`Uint8Array`] instances to concat * `totalLength` {Integer} Total length of the `Buffer` instances in `list` when concatenated * Returns: {Buffer} @@ -882,7 +882,7 @@ console.log(buf.toString('ascii')); added: v0.11.13 --> -* `target` {Buffer} A `Buffer` to compare to +* `target` {Buffer|Uint8Array} A `Buffer` or [`Uint8Array`] to compare to * `targetStart` {Integer} The offset within `target` at which to begin comparison. **Default:** `0` * `targetEnd` {Integer} The offset with `target` at which to end comparison @@ -1037,7 +1037,7 @@ for (const pair of buf.entries()) { added: v0.11.13 --> -* `otherBuffer` {Buffer} A `Buffer` to compare to +* `otherBuffer` {Buffer} A `Buffer` or [`Uint8Array`] to compare to * Returns: {Boolean} Returns `true` if both `buf` and `otherBuffer` have exactly the same bytes, @@ -1099,7 +1099,7 @@ console.log(Buffer.allocUnsafe(3).fill('\u0222')); added: v1.5.0 --> -* `value` {String | Buffer | Integer} What to search for +* `value` {String | Buffer | Uint8Array | Integer} What to search for * `byteOffset` {Integer} Where to begin searching in `buf`. **Default:** `0` * `encoding` {String} If `value` is a string, this is its encoding. **Default:** `'utf8'` @@ -1110,8 +1110,8 @@ If `value` is: * a string, `value` is interpreted according to the character encoding in `encoding`. - * a `Buffer`, `value` will be used in its entirety. To compare a partial - `Buffer` use [`buf.slice()`]. + * a `Buffer` or [`Uint8Array`], `value` will be used in its entirety. + To compare a partial `Buffer`, use [`buf.slice()`]. * a number, `value` will be interpreted as an unsigned 8-bit integer value between `0` and `255`. @@ -1221,7 +1221,7 @@ for (const key of buf.keys()) { added: v6.0.0 --> -* `value` {String | Buffer | Integer} What to search for +* `value` {String | Buffer | Uint8Array | Integer} What to search for * `byteOffset` {Integer} Where to begin searching in `buf`. **Default:** [`buf.length`]` - 1` * `encoding` {String} If `value` is a string, this is its encoding. @@ -2313,12 +2313,12 @@ Note that this is a property on the `buffer` module returned by added: v7.1.0 --> -* `source` {Buffer} A `Buffer` instance +* `source` {Buffer|Uint8Array} A `Buffer` or `Uint8Array` instance * `fromEnc` {String} The current encoding * `toEnc` {String} To target encoding -Re-encodes the given `Buffer` instance from one character encoding to another. -Returns a new `Buffer` instance. +Re-encodes the given `Buffer` or `Uint8Array` instance from one character +encoding to another. Returns a new `Buffer` instance. Throws if the `fromEnc` or `toEnc` specify invalid character encodings or if conversion from `fromEnc` to `toEnc` is not permitted. |