You are on page 1of 1

<integer> 

The byteOffset of the Buffers underlying ArrayBuffer object.


When setting byteOffset in Buffer.from(ArrayBuffer, byteOffset, length), or sometimes when
allocating a Buffer smaller than Buffer.poolSize, the buffer does not start from a zero offset on
the underlying ArrayBuffer.
This can cause problems when accessing the underlying ArrayBuffer directly using buf.buffer, as
other parts of the ArrayBuffer may be unrelated to the Buffer object itself.
A common issue when creating a TypedArray object that shares its memory with a Buffer is that
in this case one needs to specify the byteOffset correctly:
// Create a buffer smaller than `Buffer.poolSize`.
const nodeBuffer = new Buffer.from([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]);

// When casting the Node.js Buffer to an Int8Array, use the byteOffset


// to refer only to the part of `nodeBuffer.buffer` that contains the memory
// for `nodeBuffer`.
new Int8Array(nodeBuffer.buffer, nodeBuffer.byteOffset, nodeBuffer.length);

buf.compare(target[, targetStart[, targetEnd[, sourceStart[, sourceEnd]]]])#


target <Buffer> | <Uint8Array> A Buffer or Uint8Array with which to compare buf.
targetStart <integer> The offset within target at which to begin comparison. Default: 0.
targetEnd <integer> The offset within target at which to end comparison (not
inclusive). Default: target.length.
sourceStart <integer> The offset within buf at which to begin comparison. Default: 0.
sourceEnd <integer> The offset within buf at which to end comparison (not
inclusive). Default: buf.length.
Returns: <integer>

You might also like