From a3c8463ef0e245b59c2529a96acfd95eaf883796 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20M=C3=B6sner?= Date: Tue, 27 Jun 2023 11:24:44 +0200 Subject: [PATCH] fix: deprecation warning for new Buffer (#1905) --- 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); }; /**