I have encountered a very weird behavior I do not understand after trying to debug my application for half a day. Have a look at the following snippet:
const buffer = Buffer.from([12, 34, 56, 78, 90]);
const dataView = new DataView(buffer.buffer);
console.log('buffer byteLength:', buffer.byteLength);
console.log('dataView byteLength:', dataView.byteLength);
console.log('first uint8 in buffer:', buffer.readUInt8(0));
console.log('first uint8 in dataView:', dataView.getUint8(0));
For me, the output of this script is:
buffer byteLength: 5
dataView byteLength: 8192
first uint8 in buffer: 12
first uint8 in dataView: 99
The Node.js version I used is 8.6.0.