Method description:
Perform copy and replace operations between different buffers.
Copy data from the source buffer and replace it to the specified location of the target buffer.
grammar:
The code copy is as follows:
buffer.copy(targetBuffer, [targetStart], [sourceStart], [sourceEnd])
Receive parameters:
targetBuffer target buffer, perform copy-replaced buffer
targetStart start position of the target buffer data replacement
sourceStart The starting location of source buffer data replication
sourceEnd The end position of source buffer data copy
example:
In this example, data between buf1 16 and 20 is extracted, the data is copied into buf2, and the replacement starts from position 8 of buf2.
The code copy is as follows:
buf1 = new Buffer(26);
buf2 = new Buffer(26);
for (var i = 0 ; i < 26 ; i++) {
buf1[i] = i + 97; // 97 is ASCII a
buf2[i] = 33; // ASCII!
}
buf1.copy(buf2, 8, 16, 20);
console.log(buf2.toString('ascii', 0, 25));