start{integer} 新Buffer开始的位置。默认值:0。end{integer} 新Buffer结束的位置(不包含)。默认值: [buf.length]。- 返回: {Buffer}
返回一个新的 Buffer,它引用与原始的 Buffer 相同的内存,但是由 start 和 end 索引进行偏移和裁剪。
这与 buf.subarray() 的行为相同。
此方法与 Uint8Array.prototype.slice() 不兼容,后者是 Buffer 的超类。
若要复制切片,则使用 Uint8Array.prototype.slice()。
const buf = Buffer.from('buffer');const copiedBuf = Uint8Array.prototype.slice.call(buf);copiedBuf[0]++;console.log(copiedBuf.toString());// 打印: cufferconsole.log(buf.toString());// 打印: buffer
