diff --git a/lib/stream.js b/lib/stream.js index 826f0e6d9adb6c..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,24 +42,8 @@ Stream.finished = eos; Stream.Stream = Stream; Stream._isUint8Array = require('internal/util/types').isUint8Array; - -const version = process.version.substr(1).split('.'); -if (version[0] === 0 && version[1] < 12) { - Stream._uint8ArrayToBuffer = Buffer; -} else { - 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); +};