From 9e0fd77799a0fcf16b8eb2f767358ef8bb834ec8 Mon Sep 17 00:00:00 2001 From: Luigi Pinca Date: Mon, 12 Dec 2022 11:18:17 +0100 Subject: [PATCH] [minor] Use `Buffer#subarray()` instead of `Buffer#slice()` `Buffer.prototype.slice()` is deprecated. --- lib/buffer-util.js | 2 +- lib/permessage-deflate.js | 2 +- lib/receiver.js | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/buffer-util.js b/lib/buffer-util.js index df7595546..eb27486ed 100644 --- a/lib/buffer-util.js +++ b/lib/buffer-util.js @@ -23,7 +23,7 @@ function concat(list, totalLength) { offset += buf.length; } - if (offset < totalLength) return target.slice(0, offset); + if (offset < totalLength) return target.subarray(0, offset); return target; } diff --git a/lib/permessage-deflate.js b/lib/permessage-deflate.js index 94603c98d..b03355805 100644 --- a/lib/permessage-deflate.js +++ b/lib/permessage-deflate.js @@ -437,7 +437,7 @@ class PerMessageDeflate { this._deflate[kTotalLength] ); - if (fin) data = data.slice(0, data.length - 4); + if (fin) data = data.subarray(0, data.length - 4); // // Ensure that the callback will not be called again in diff --git a/lib/receiver.js b/lib/receiver.js index d9a54543c..5adc208d9 100644 --- a/lib/receiver.js +++ b/lib/receiver.js @@ -97,8 +97,8 @@ class Receiver extends Writable { if (n < this._buffers[0].length) { const buf = this._buffers[0]; - this._buffers[0] = buf.slice(n); - return buf.slice(0, n); + this._buffers[0] = buf.subarray(n); + return buf.subarray(0, n); } const dst = Buffer.allocUnsafe(n); @@ -111,7 +111,7 @@ class Receiver extends Writable { dst.set(this._buffers.shift(), offset); } else { dst.set(new Uint8Array(buf.buffer, buf.byteOffset, n), offset); - this._buffers[0] = buf.slice(n); + this._buffers[0] = buf.subarray(n); } n -= buf.length; @@ -562,7 +562,7 @@ class Receiver extends Writable { ); } - const buf = data.slice(2); + const buf = data.subarray(2); if (!this._skipUTF8Validation && !isValidUTF8(buf)) { return error(