bit-buffer icon indicating copy to clipboard operation
bit-buffer copied to clipboard

new BitView() fails with byteOffset specified

Open chrisveness opened this issue 4 years ago • 0 comments

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 */;

chrisveness avatar Dec 10 '20 18:12 chrisveness