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 <zyszys98@gmail.com>
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
pull/30069/head
Luigi Pinca 2019-10-20 13:36:49 +02:00 committed by Rich Trott
parent 94230d15bd
commit 1070153cf6
1 changed files with 6 additions and 17 deletions

View File

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