dataview2
v1.0.0
Published
Efficient DataView for isomorphic libraries
Downloads
56
Readme
dataview2
Efficient DataView for isomorphic libraries
Installation
npm:
npm install dataview2
API
DataView2(buffer: Buffer|ArrayBuffer): BufferDataView|DataView
- node.js: returns an instance of
BufferDataView
- browser: returns an instance of
DataView
- node.js: returns an instance of
Buffer2(n: size): Buffer|ArrayBuufer
- node.js: return an instance of
Buffer
- browser: return an instance of
ArrayBuffer
- node.js: return an instance of
Examples
use Buffer in the Node.js
var buffer = new Buffer2(4); // → Buffer
var view = new DataView2(buffer); // → BufferDataView
// set a "float" in the data view
view.setFloat32(0, 1337.1234, true);
// ensure that the original Buffer was modified
console.log(buffer.readFloatLE(0));
// → 1337.1234130859375
console.log(view.buffer instanceof Buffer);
// → true
use ArrayBuffer in the browser
var buffer new Buffer2(4); // → ArrayBuffer
var view = new DataView2(buffer); // → DataView
// set a "float" in the data view
view.setFloat32(0, 1337.1234, true);
console.log(view.buffer instanceof ArrayBuffer);
// → true
// ensure that the original ArrayBuffer was modified
console.log(new Float32Array(buffer)[0]);
// → 1337.1234130859375
License
MIT