THE WORLD'S LARGEST WEB DEVELOPER SITE

Node.js buffer copy() Method

❮ Buffer Module


Example

Copy one buffer into parts of another buffer:

var buf1 = Buffer.from('abcdefghijkl');
var buf2 = Buffer.from('HELLO');

buf2.copy(buf1, 2);

console.log(buf1.toString());
Run example »

Definition and Usage

The copy() method copies data from one buffer object into another buffer object.


Syntax

buffer.copy(target, targetStart, sourceStart, sourceEnd);

Parameter Values

Parameter Description
target Required. The array of buffers to concat
targetStart Optional. A number specifying where to begin copying to. Default 0
sourceStart Optional. A number specifying where to begin copying from. Default 0
sourceEnd Optional. A number specifying where to stop copying from. Default end of buffer

Technical Details

Return Value: A number specifying the number of bytes copied
Node.js Version: 0.1.90

More Examples

Example

Copy parts of a buffer into parts of another buffer:

var buf1 = Buffer.from('abcdefghijkl');
var buf2 = Buffer.from('HELLO');

buf2.copy(buf1, 2, 0, 2);

console.log(buf1.toString());
Run example »

❮ Buffer Module