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); +};