1 |
3a515b92
|
cagy
|
# to-arraybuffer [![Build Status](https://travis-ci.org/jhiesey/to-arraybuffer.svg?branch=master)](https://travis-ci.org/jhiesey/to-arraybuffer)
|
2 |
|
|
|
3 |
|
|
[![Sauce Test Status](https://saucelabs.com/browser-matrix/to-arraybuffer.svg)](https://saucelabs.com/u/to-arraybuffer)
|
4 |
|
|
|
5 |
|
|
Convert from a Buffer to an ArrayBuffer as fast as possible.
|
6 |
|
|
|
7 |
|
|
Note that in some cases the returned ArrayBuffer is backed by the same memory as the original
|
8 |
|
|
Buffer (but in other cases it is a copy), so **modifying the ArrayBuffer is not recommended**.
|
9 |
|
|
|
10 |
|
|
This module is designed to work both in node.js and in all browsers with ArrayBuffer support
|
11 |
|
|
when using [the Buffer implementation provided by Browserify](https://www.npmjs.com/package/buffer).
|
12 |
|
|
|
13 |
|
|
## Usage
|
14 |
|
|
|
15 |
|
|
``` js
|
16 |
|
|
var toArrayBuffer = require('to-arraybuffer')
|
17 |
|
|
|
18 |
|
|
var buffer = new Buffer(100)
|
19 |
|
|
// Fill the buffer with some data
|
20 |
|
|
|
21 |
|
|
var ab = toArrayBuffer(buffer)
|
22 |
|
|
// `ab` now contains the same data as `buffer`
|
23 |
|
|
```
|
24 |
|
|
|
25 |
|
|
## License
|
26 |
|
|
|
27 |
|
|
MIT
|