Skip to main content
BufferConstructor.copyBytesFrom - node__buffer.d.ts - Node documentation
method BufferConstructor.copyBytesFrom

Usage in Deno

```typescript import { type BufferConstructor } from "node:node__buffer.d.ts"; ```
BufferConstructor.copyBytesFrom(
view: TypedArray,
offset?: number,
length?: number,
): Buffer
Copies the underlying memory of `view` into a new `Buffer`. ```js 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

view: TypedArray
The {TypedArray} to copy.
optional
offset: number = 0
The starting offset within `view`.
optional
length: number = view.length - offset
The number of elements from `view` to copy.

Return Type