I'm trying to read a binary file then parse it with DataView, but when passing the buffer from fs.readFile
to DataView
, it throws an Error
TypeError: First argument to DataView constructor must be an ArrayBuffer
here is my code:
const fs = require('fs');
const buf = fs.readFileSync('./path/to/file');
const dv = new DataView(buf);
the reason why I want to DataView
instead of methods from Buffer
(buf.readInt8([offset])
) to read data is that I can share logic between node
and browser