Copy the bytes in the specified range [sourceStart, sourceEnd) of the buffer object to the range [target,] of the target buffer object,
Ensure that the memory space of the target buffer object is sufficient.
Optional
dstStart: numberIndicates the target start position. The default value is 0.
Optional
start: numberIndicates the start position of the source. The default value is 0.
Optional
end: numberSource end position. The default value is the size of the source buffer object.
import * as buffer from 'buffer';
let source = buffer.from("1234567890");
let target = buffer.empty();
target.alloc(3);
source.copy(target, 0, 5, 8);
console.log(target.toString()); // 678
Check whether two buffer objects are equal. The comparison principle is to compare the two buffer objects by byte array.
From a slice interval [start, end) of the Buffer object, and returns a new Buffer object. Note that the new Buffer object shares the underlying byte array memory with the original Buffer object.
Optional
start: numberStart position. The default value is 0.
Optional
end: numberEnd position. The default value is the size of the original buffer.
import * as buffer from 'buffer';
let buf = buffer.from("1234567890");
let slice = buf.slice(5, 8);
console.log(buf.toString()); // 1234567890
console.log(slice.toString()); // 678
slice.set(1, 65);
console.log(buf.toString()); // 123456A890
console.log(slice.toString()); // 6A8
Converts the buffer object byte array to a character string.
Optional
encoding: EncodingCharacter string encoding format. The default value is utf8.
Buffer binary buffer manager