I wanted to simplify the various .read{Type} or .write{Type} by using a DataView implementation and
found out that is not possible to use the Buffer's ArrayBuffer if the buffer was sliced from the pool.
const assert = require('assert');
const SlowBuffer = require('buffer').SlowBuffer;
const buffer = new Buffer(4).fill(0);
new DataView(buffer.buffer).setFloat32(0, 1, true);
console.log(buffer.buffer.byteLength);
console.log(buffer);
const slowBuffer = new SlowBuffer(4).fill(0);
new DataView(slowBuffer.buffer).setFloat32(0, 1, true);
console.log(slowBuffer.buffer.byteLength);
console.log(slowBuffer);
assert.deepEqual(buffer, slowBuffer);
results into
8192
<Buffer 00 00 00 00>
4
<Buffer 00 00 80 3f>
AssertionError: <Buffer 00 00 00 00> deepEqual <Buffer 00 00 80 3f>
The problem is the underlying ArrayBuffer for the new sliced TypedArray does not change.
I wanted to simplify the various .read{Type} or .write{Type} by using a DataView implementation and
found out that is not possible to use the Buffer's ArrayBuffer if the buffer was sliced from the pool.
results into
The problem is the underlying ArrayBuffer for the new sliced TypedArray does not change.