| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent d57bd2b commit 537455e
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -8,6 +8,7 @@ | |||
| 8 | 8 | // ondrain() - backpressure drain utility | |
| 9 | 9 | ||
| 10 | 10 | const { | |
| 11 | + ArrayBufferIsView, | ||
| 11 | 12 | ArrayBufferPrototypeGetByteLength, | |
| 12 | 13 | ArrayBufferPrototypeSlice, | |
| 13 | 14 | ArrayPrototypeMap, | |
@@ -51,9 +52,12 @@ const { | |||
| 51 | 52 | ||
| 52 | 53 | const { | |
| 53 | 54 | drainableProtocol, | |
| 55 | + toAsyncStreamable, | ||
| 56 | + toStreamable, | ||
| 54 | 57 | } = require('internal/streams/iter/types'); | |
| 55 | 58 | ||
| 56 | 59 | const { | |
| 60 | + isAnyArrayBuffer, | ||
| 57 | 61 | isSharedArrayBuffer, | |
| 58 | 62 | } = require('internal/util/types'); | |
| 59 | 63 | ||
@@ -65,8 +69,12 @@ function isMergeOptions(value) { | |||
| 65 | 69 | return ( | |
| 66 | 70 | value !== null && | |
| 67 | 71 | typeof value === 'object' && | |
| 72 | + !ArrayBufferIsView(value) && | ||
| 73 | + typeof value[toStreamable] !== 'function' && | ||
| 74 | + typeof value[toAsyncStreamable] !== 'function' && | ||
| 68 | 75 | !isAsyncIterable(value) && | |
| 69 | - !isSyncIterable(value) | ||
| 76 | + !isSyncIterable(value) && | ||
| 77 | + !isAnyArrayBuffer(value) | ||
| 70 | 78 | ); | |
| 71 | 79 | } | |
| 72 | 80 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -9,6 +9,8 @@ const { | |||
| 9 | 9 | push, | |
| 10 | 10 | merge, | |
| 11 | 11 | text, | |
| 12 | + toAsyncStreamable, | ||
| 13 | + toStreamable, | ||
| 12 | 14 | } = require('stream/iter'); | |
| 13 | 15 | ||
| 14 | 16 | // ============================================================================= | |
@@ -162,6 +164,27 @@ async function testMergeStringSources() { | |||
| 162 | 164 | assert.ok(combined.includes('world')); | |
| 163 | 165 | } | |
| 164 | 166 | ||
| 167 | + // merge() accepts object-like sources that are normalized via from() | ||
| 168 | + async function testMergeObjectLikeSources() { | ||
| 169 | + const arrayBuffer = new TextEncoder().encode('abc').buffer; | ||
| 170 | + const dataView = new DataView(new TextEncoder().encode('def').buffer); | ||
| 171 | + const streamable = { | ||
| 172 | + [toStreamable]() { | ||
| 173 | + return 'ghi'; | ||
| 174 | + }, | ||
| 175 | + }; | ||
| 176 | + const asyncStreamable = { | ||
| 177 | + [toAsyncStreamable]() { | ||
| 178 | + return Promise.resolve('jkl'); | ||
| 179 | + }, | ||
| 180 | + }; | ||
| 181 | + | ||
| 182 | + assert.strictEqual(await text(merge(arrayBuffer)), 'abc'); | ||
| 183 | + assert.strictEqual(await text(merge(dataView)), 'def'); | ||
| 184 | + assert.strictEqual(await text(merge(streamable)), 'ghi'); | ||
| 185 | + assert.strictEqual(await text(merge(asyncStreamable)), 'jkl'); | ||
| 186 | + } | ||
| 187 | + | ||
| 165 | 188 | Promise.all([ | |
| 166 | 189 | testMergeTwoSources(), | |
| 167 | 190 | testMergeSingleSource(), | |
@@ -172,4 +195,5 @@ Promise.all([ | |||
| 172 | 195 | testMergeConsumerBreak(), | |
| 173 | 196 | testMergeSignalMidIteration(), | |
| 174 | 197 | testMergeStringSources(), | |
| 198 | + testMergeObjectLikeSources(), | ||
| 175 | 199 | ]).then(common.mustCall()); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments