Skip to content

Commit bb867c0

Browse files
trevnorrisTooTallNate
authored andcommitted
doc: Add lines about additonal uses of Buffer
That Buffers can be used with Typed Array Views and DataViews. Included are a couple simple examples. Closes #4257.
1 parent 7716828 commit bb867c0

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

doc/api/buffer.markdown

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,23 @@ encoding method. Here are the different string encodings.
4040

4141
* `'hex'` - Encode each byte as two hexadecimal characters.
4242

43+
`Buffer` can also be used with Typed Array Views and DataViews.
44+
45+
var buff = new Buffer(4);
46+
var ui16 = new Uint16Array(buff);
47+
var view = new DataView(buff);
48+
49+
ui16[0] = 1;
50+
ui16[1] = 2;
51+
console.log(buff);
52+
53+
view.setInt16(0, 1); // set big-endian int16 at byte offset 0
54+
view.setInt16(2, 2, true); // set little-endian int16 at byte offset 2
55+
console.log(buff);
56+
57+
// <Buffer 01 00 02 00>
58+
// <Buffer 00 01 02 00>
59+
4360
## Class: Buffer
4461

4562
The Buffer class is a global type for dealing with binary data directly.

0 commit comments

Comments
 (0)