Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion lib/internal/streams/iter/consumers.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
// ondrain() - backpressure drain utility

const {
ArrayBufferIsView,
ArrayBufferPrototypeGetByteLength,
ArrayBufferPrototypeSlice,
ArrayPrototypeMap,
Expand Down Expand Up @@ -51,9 +52,12 @@ const {

const {
drainableProtocol,
toAsyncStreamable,
toStreamable,
} = require('internal/streams/iter/types');

const {
isAnyArrayBuffer,
isSharedArrayBuffer,
} = require('internal/util/types');

Expand All @@ -65,8 +69,12 @@ function isMergeOptions(value) {
return (
value !== null &&
typeof value === 'object' &&
!ArrayBufferIsView(value) &&
typeof value[toStreamable] !== 'function' &&
typeof value[toAsyncStreamable] !== 'function' &&
!isAsyncIterable(value) &&
!isSyncIterable(value)
!isSyncIterable(value) &&
!isAnyArrayBuffer(value)
);
}

Expand Down
24 changes: 24 additions & 0 deletions test/parallel/test-stream-iter-consumers-merge.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ const {
push,
merge,
text,
toAsyncStreamable,
toStreamable,
} = require('stream/iter');

// =============================================================================
Expand Down Expand Up @@ -162,6 +164,27 @@ async function testMergeStringSources() {
assert.ok(combined.includes('world'));
}

// merge() accepts object-like sources that are normalized via from()
async function testMergeObjectLikeSources() {
const arrayBuffer = new TextEncoder().encode('abc').buffer;
const dataView = new DataView(new TextEncoder().encode('def').buffer);
const streamable = {
[toStreamable]() {
return 'ghi';
},
};
const asyncStreamable = {
[toAsyncStreamable]() {
return Promise.resolve('jkl');
},
};

assert.strictEqual(await text(merge(arrayBuffer)), 'abc');
assert.strictEqual(await text(merge(dataView)), 'def');
assert.strictEqual(await text(merge(streamable)), 'ghi');
assert.strictEqual(await text(merge(asyncStreamable)), 'jkl');
}

Promise.all([
testMergeTwoSources(),
testMergeSingleSource(),
Expand All @@ -172,4 +195,5 @@ Promise.all([
testMergeConsumerBreak(),
testMergeSignalMidIteration(),
testMergeStringSources(),
testMergeObjectLikeSources(),
]).then(common.mustCall());
Loading