npm install @op.c/bytesA storage-agnostic implementation of Node core's buffer API.
Usable with Buffer, Uint8Array, and Array; or anything else that behaves like them.
The Web APIs around working with binary data are inadequate.
Annoyance 1: DataView defaults to big-endian, while most platforms (and file formats) use little-endian,
and thus basically always requires the more verbose littleEndian argument,
e.g: .getUint16( offset, true ).
Annoyance 2: A new DataView needs to be constructed for every ArrayBuffer you want
to operate on, needlessly thrashing the heap. Sad performance face.
Annoyance 3: var dataView = new DataView( buffer ); dataView.getUint32( offset, true )
because not-invented-here and we-dont-want-to-copy-node buffer.readUInt32LE( offset ).
Annoyance 4: The boolean littleEndian argument in DataView methods (.getUint16( offset, littleEndian ))
is limiting (middle-endian / mixed-endian anyone?), Node's Buffer API would be easily extended to cover
that case through its use of suffixes (e.g. .readUInt32ME())
``console`
$ npm install --save @op.c/bytes
`js`
var bytes = require( '@op.c/bytes' )
To be as unrestrictive as possible, this library does not type-guard the buffers it operates on;
its methods will work on anything that looks and behaves like an Array or TypedArray.
Be aware of what you are doing, and what your inputs are.
Beware of (re-)using ArrayBuffers from TypedArrays that have an element size larger than a byte
(i.e. everything other than U/Int8Array & U/Int8ClampedArray`);
their contents are platform byte-order dependent.