Skip to main content
Skip to main content

copyBytesFrom

BufferConstructor.copyBytesFrom

**copyBytesFrom**(view, offset?, length?): [Buffer](/references/product/variables/Buffer-1)

Copies the underlying memory of view into a new Buffer.

const u16 = new Uint16Array([0, 0xffff]);
const buf = Buffer.copyBytesFrom(u16, 1, 1);
u16[1] = 0;
console.log(buf.length); // 2
console.log(buf[0]); // 255
console.log(buf[1]); // 255

Parameters

viewTypedArrayRequired
The {TypedArray} to copy.
offsetnumber
The starting offset within view.
lengthnumber
The number of elements from view to copy.

Returns

Buffer

BufferBufferRequired

Since

v19.8.0

Was this section helpful?