Skip to main content
Module

std/node/buffer.ts>Buffer#slice

Deno standard library
Go to Latest
method Buffer.prototype.slice
import { Buffer } from "https://deno.land/std@0.167.0/node/buffer.ts";

Returns a new Buffer that references the same memory as the original, but offset and cropped by the start and end indices.

This is the same behavior as buf.subarray().

This method is not compatible with the Uint8Array.prototype.slice(), which is a superclass of Buffer. To copy the slice, useUint8Array.prototype.slice().

import { Buffer } from 'buffer';

const buf = Buffer.from('buffer');

const copiedBuf = Uint8Array.prototype.slice.call(buf);
copiedBuf[0]++;
console.log(copiedBuf.toString());
// Prints: cuffer

console.log(buf.toString());
// Prints: buffer

Parameters

optional
start: number

Where the new Buffer will start.

optional
end: number

Where the new Buffer will end (not inclusive).