Permalink
Browse files

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.
  • Loading branch information...
1 parent 7716828 commit bb867c0fa6c245e95009f18742997b4cf372d6e3 @trevnorris trevnorris committed with TooTallNate Nov 22, 2012
Showing with 17 additions and 0 deletions.
  1. +17 −0 doc/api/buffer.markdown
View
@@ -40,6 +40,23 @@ encoding method. Here are the different string encodings.
* `'hex'` - Encode each byte as two hexadecimal characters.
+`Buffer` can also be used with Typed Array Views and DataViews.
+
+ var buff = new Buffer(4);
+ var ui16 = new Uint16Array(buff);
+ var view = new DataView(buff);
+
+ ui16[0] = 1;
+ ui16[1] = 2;
+ console.log(buff);
+
+ view.setInt16(0, 1); // set big-endian int16 at byte offset 0
+ view.setInt16(2, 2, true); // set little-endian int16 at byte offset 2
+ console.log(buff);
+
+ // <Buffer 01 00 02 00>
+ // <Buffer 00 01 02 00>
+
## Class: Buffer
The Buffer class is a global type for dealing with binary data directly.

0 comments on commit bb867c0

Please sign in to comment.