From 84752a495f93d766c7f7c08b812ea6c2e53df09d 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 2d0057544395bc..482c2b6cab17a6 100644 --- a/lib/buffer.js +++ b/lib/buffer.js @@ -1113,7 +1113,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; @@ -1121,6 +1121,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];