From e93286ef70d2e673c341ac08a192cc2abe6fd2eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20M=C3=B6sner?= Date: Tue, 22 Aug 2023 01:49:22 +0200 Subject: [PATCH] fix: deprecation warning for new Buffer (#1905) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Filip Mösner --- src/reader.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/reader.js b/src/reader.js index 1b6ae13f8..b4fbf291e 100644 --- a/src/reader.js +++ b/src/reader.js @@ -312,9 +312,14 @@ Reader.prototype.bytes = function read_bytes() { this.pos += length; if (Array.isArray(this.buf)) // plain array return this.buf.slice(start, end); - return start === end // fix for IE 10/Win8 and others' subarray returning array of size 1 - ? new this.buf.constructor(0) - : this._slice.call(this.buf, start, end); + + if (start === end) { // fix for IE 10/Win8 and others' subarray returning array of size 1 + var nativeBuffer = util.Buffer; + return nativeBuffer + ? nativeBuffer.alloc(0) + : new this.buf.constructor(0); + } + return this._slice.call(this.buf, start, end); }; /**