I have the following typed array: Uint16Array(2) [ 60891, 11722 ] which I would like to save to a (binary) file. I would then like to read it back into another Uint16Array with the order of the elements preserved.
I tried using the fs module but when I go to read the file I'm not getting the same integers:
//console.log(buffer) : Uint16Array(2) [ 60891, 11722 ]
fs.writeFileSync(bufferPath, buffer, 'binary')
const loadedBuffer = fs.readFileSync(bufferPath)
//console.log(new Uint16Array(loadedBuffer)) : Uint16Array(4) [ 219, 237, 202, 45 ]