Migration
DEP0158: migrate Buffer.slice
Use subarray for a shared-memory view, or Buffer.from(view) when the result must own a copy. Review mutations when migrating. Tested on Node.js 22.16.0. Example output (one line per entry): ["Xbc ab"].
Formal Syntax & Structure
nodejs syntaxnodejs
buffer.subarray(start, end)Return Value
Migration outcome
Replacement behavior shown by the example.
Working Example
Example Snippetnodejs
const b = Buffer.from('abc');const view = b.subarray(0, 2);const copy = Buffer.from(view);view[0] = 88;console.log(b.toString(), copy.toString());