Home > Web Front-end > JS Tutorial > body text

Instructions for using the buffer.copy method in node.js_node.js

WBOY
Release: 2016-05-16 16:27:15
Original
1764 people have browsed it

Method description:

Perform copy and replacement operations between different buffers.

Copy data from the source buffer and replace it at the specified location in the target buffer.

Grammar:

Copy code The code is as follows:

buffer.copy(targetBuffer, [targetStart], [sourceStart], [sourceEnd])

Receive parameters:

targetBuffer Target buffer, buffer to perform copy replacement

targetStart The starting position of target buffer data replacement

sourceStart The starting position of source buffer data copy

sourceEnd The end position of source buffer data copy

Example:

In this example, the data between 16 and 20 of buf1 is extracted, the data is copied to buf2, and replacement starts from position 8 of buf2.

Copy code The code 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));
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!