summaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorJackson Tian <shyvo1987@gmail.com>2016-02-16 11:08:49 +0800
committerJames M Snell <jasnell@gmail.com>2016-03-27 09:19:39 -0700
commit293fd0453591ef0d87437a265ff515916d35d715 (patch)
tree5194f284fa4e16829890c5355c2d2eabd6351af0 /doc
parentafd821a91d14a13becdf989184adf721ae7365eb (diff)
downloadandroid-node-v8-293fd0453591ef0d87437a265ff515916d35d715.tar.gz
android-node-v8-293fd0453591ef0d87437a265ff515916d35d715.tar.bz2
android-node-v8-293fd0453591ef0d87437a265ff515916d35d715.zip
buffer: make byteLength work with ArrayBuffer & DataView
Convert anything to string, but Buffer, TypedArray and ArrayBuffer ``` var uint8 = new Uint8Array([0xf0, 0x9f, 0x90]); Buffer.byteLength(uint8); // should be 3, but returns 11 Buffer.byteLength(uint8.buffer); // should be 3, but return 20 ``` PR-URL: https://github.com/nodejs/node/pull/5255 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Trevor Norris <trev.norris@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'doc')
-rw-r--r--doc/api/buffer.markdown9
1 files changed, 8 insertions, 1 deletions
diff --git a/doc/api/buffer.markdown b/doc/api/buffer.markdown
index a2462e1bc4..21ebf8df15 100644
--- a/doc/api/buffer.markdown
+++ b/doc/api/buffer.markdown
@@ -468,7 +468,7 @@ additional performance that `Buffer.allocUnsafe(size)` provides.
### Class Method: Buffer.byteLength(string[, encoding])
-* `string` {String}
+* `string` {String | Buffer | TypedArray | DataView | ArrayBuffer}
* `encoding` {String} Default: `'utf8'`
* Return: {Number}
@@ -487,6 +487,11 @@ console.log(`${str}: ${str.length} characters, ` +
// ½ + ¼ = ¾: 9 characters, 12 bytes
```
+When `string` is a `Buffer`/[`DataView`][]/[`TypedArray`][]/`ArrayBuffer`,
+returns the actual byte length.
+
+Otherwise, converts to `String` and returns the byte length of string.
+
### Class Method: Buffer.compare(buf1, buf2)
* `buf1` {Buffer}
@@ -1765,3 +1770,5 @@ console.log(buf);
[buffer_allocunsafe]: #buffer_class_method_buffer_allocraw_size
[buffer_alloc]: #buffer_class_method_buffer_alloc_size_fill_encoding
[`TypedArray.from()`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/from
+[`DataView`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView
+[`TypedArray`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray