buffer.slice([start], [end])
const originalBuffer = Buffer.from("Hello, world!"); const subsetBuffer = originalBuffer.slice(7, 12); console.log(subsetBuffer.toString()); // outputs "world"
const originalBuffer = Buffer.from([1, 2, 3, 4, 5]); const copiedBuffer = Buffer.alloc(3); originalBuffer.slice(1, 4).copy(copiedBuffer); console.log(copiedBuffer); // outputsIn this example, we create a new buffer that contains only the values 2, 3, and 4 from the original buffer, and then copy that new buffer into another buffer. The buffer slice method is part of the Node.js Buffer module, which is a built-in library in Node.js.