bit-buffer
bit-buffer copied to clipboard
new BitView() fails with byteOffset specified
If the BitView constructor is invoked with (non-zero) byteOffset and no byteLength, it fails with Uncaught RangeError: Invalid typed array length
error.
To replicate:
$ node
> BitView = require('bit-buffer').BitView;
> array = new ArrayBuffer(8);
> bv = new BitView(array, 4);
Uncaught RangeError: Invalid typed array length: 8
at new Uint8Array (<anonymous>)
at new BitView (.../node_modules/bit-buffer/bit-buffer.js:22:15)
I think the solution would be to change line 20 to
byteLength = byteLength || source.byteLength-byteOffset /* ArrayBuffer */ || source.length-byteOffset /* Buffer */;