• start {integer} 新 Buffer 开始的位置。默认值: 0
    • end {integer} 新 Buffer 结束的位置(不包含)。默认值: [buf.length]。
    • 返回: {Buffer}

    返回一个新的 Buffer,它引用与原始的 Buffer 相同的内存,但是由 startend 索引进行偏移和裁剪。

    这与 buf.subarray() 的行为相同。

    此方法与 Uint8Array.prototype.slice() 不兼容,后者是 Buffer 的超类。 若要复制切片,则使用 Uint8Array.prototype.slice()

    1. const buf = Buffer.from('buffer');
    2. const copiedBuf = Uint8Array.prototype.slice.call(buf);
    3. copiedBuf[0]++;
    4. console.log(copiedBuf.toString());
    5. // 打印: cuffer
    6. console.log(buf.toString());
    7. // 打印: buffer