Buffer
Buffer.copy()
Copies bytes into a destination buffer. Unlike subarray, the destination does not share the copied region when separately allocated. Tested on Node.js 22.16.0. Example output (one line per entry): ["2 oo", "book"].
Formal Syntax & Structure
nodejs syntaxnodejs
source.copy(target[, targetStart[, sourceStart[, sourceEnd]]])Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| target | Buffer | Uint8Array | Destination. |
| targetStart | number | Destination offset. |
| sourceStart | number | Source offset. |
| sourceEnd | number | Exclusive source end. |
Return Value
number
Bytes copied.
Working Example
Example Snippetnodejs
const a = Buffer.from('book'), b = Buffer.alloc(2);console.log(a.copy(b, 0, 1, 3), b.toString());b[0] = 88;console.log(a.toString());