why is this:
var myArrayBuffer = fs.readFileSync(file, null)
returning an uInt8 array instead of a just a arrayBuffer? why does this seem to work?
var myArrayBuffer = fs.readFileSync(file, null).buffer;
var myAArray = new Uint16Array( myArrayBuffer.slice(266,(sizeofArray*sizeOfArrayElement));
Why would the fs.readFile parse my file into a uInt8 array? Makes no sense, the file has a bunch of different datatypes that are not 1 byte long.
Because since v3.0.0 Buffer class inherits from Uint8Array class. Quoting the doc:
Bufferinstances are alsoUint8Arrayinstances. However, there are subtle incompatibilities with theTypedArrayspecification in ECMAScript 2015. For example, whileArrayBuffer#slice()creates a copy of the slice, the implementation ofBuffer#slice()creates a view over the existingBufferwithout copying, makingBuffer#slice()far more efficient. [...]It is possible to create a new
Bufferthat shares the same allocated memory as aTypedArrayinstance by using theTypeArrayobject's.bufferproperty.
... which is exactly what's done in your example.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With