Skip to content

Commit

Permalink
stream: simplify uint8ArrayToBuffer helper
Browse files Browse the repository at this point in the history
The fallback code is no longer used when exporting to readable-stream.

Refs: #29514

PR-URL: #30041
Fixes: #30040
Reviewed-By: Yongsheng Zhang <[email protected]>
Reviewed-By: David Carlier <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Richard Lau <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Jiawen Geng <[email protected]>
Reviewed-By: Trivikram Kamat <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
  • Loading branch information
lpinca authored and targos committed Nov 11, 2019
1 parent ae39039 commit 21a43bd
Showing 1 changed file with 6 additions and 17 deletions.
23 changes: 6 additions & 17 deletions lib/stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
};

0 comments on commit 21a43bd

Please sign in to comment.