From 3d23d62373c0136428739893cc3c11d55dcd1490 Mon Sep 17 00:00:00 2001 From: Benjamin Gruenbaum Date: Wed, 19 Jan 2022 20:31:49 +0200 Subject: [PATCH] buffer: alias `subarray` and `slice` PR-URL: https://github.com/nodejs/node/pull/41596 Reviewed-By: James M Snell Reviewed-By: Matteo Collina Reviewed-By: Anna Henningsen Reviewed-By: Antoine du Hamel --- lib/buffer.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/buffer.js b/lib/buffer.js index 1f4f0a2e89deb8..a2ded906f8ebc4 100644 --- a/lib/buffer.js +++ b/lib/buffer.js @@ -1112,7 +1112,7 @@ function adjustOffset(offset, length) { return NumberIsNaN(offset) ? 0 : length; } -Buffer.prototype.slice = function slice(start, end) { +Buffer.prototype.subarray = function subarray(start, end) { const srcLength = this.length; start = adjustOffset(start, srcLength); end = end !== undefined ? adjustOffset(end, srcLength) : srcLength; @@ -1120,6 +1120,10 @@ Buffer.prototype.slice = function slice(start, end) { return new FastBuffer(this.buffer, this.byteOffset + start, newLength); }; +Buffer.prototype.slice = function slice(start, end) { + return this.subarray(start, end); +}; + function swap(b, n, m) { const i = b[n]; b[n] = b[m];