From 1070153cf6da6eb95644799008240825432b07e3 Mon Sep 17 00:00:00 2001 From: Luigi Pinca Date: Sun, 20 Oct 2019 13:36:49 +0200 Subject: [PATCH] stream: simplify uint8ArrayToBuffer helper The fallback code is no longer used when exporting to readable-stream. Refs: https://github.com/nodejs/node/pull/29514 PR-URL: https://github.com/nodejs/node/pull/30041 Fixes: https://github.com/nodejs/node/issues/30040 Reviewed-By: Yongsheng Zhang Reviewed-By: David Carlier Reviewed-By: Anna Henningsen Reviewed-By: Richard Lau Reviewed-By: Colin Ihrig Reviewed-By: Jiawen Geng Reviewed-By: Trivikram Kamat Reviewed-By: Matteo Collina --- lib/stream.js | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/lib/stream.js b/lib/stream.js index ff8838f4251594..725038ba9c0d1c 100644 --- a/lib/stream.js +++ b/lib/stream.js @@ -21,9 +21,9 @@ 'use strict'; -const { Buffer } = require('buffer'); const pipeline = require('internal/streams/pipeline'); const eos = require('internal/streams/end-of-stream'); +const internalBuffer = require('internal/buffer'); // Note: export Stream before Readable/Writable/Duplex/... // to avoid a cross-reference(require) issues @@ -42,19 +42,8 @@ Stream.finished = eos; Stream.Stream = Stream; Stream._isUint8Array = require('internal/util/types').isUint8Array; - -try { - const internalBuffer = require('internal/buffer'); - Stream._uint8ArrayToBuffer = function _uint8ArrayToBuffer(chunk) { - return new internalBuffer.FastBuffer(chunk.buffer, - chunk.byteOffset, - chunk.byteLength); - }; -} catch (e) { // eslint-disable-line no-unused-vars -} - -if (!Stream._uint8ArrayToBuffer) { - Stream._uint8ArrayToBuffer = function _uint8ArrayToBuffer(chunk) { - return Buffer.prototype.slice.call(chunk); - }; -} +Stream._uint8ArrayToBuffer = function _uint8ArrayToBuffer(chunk) { + return new internalBuffer.FastBuffer(chunk.buffer, + chunk.byteOffset, + chunk.byteLength); +};