@@ -33,9 +33,9 @@ const {
3333const { AbortController } = require ( 'internal/abort_controller' ) ;
3434
3535const {
36+ arrayBufferViewToUint8Array,
3637 from,
3738 fromSync,
38- primitiveToUint8Array,
3939 isSyncIterable,
4040 isAsyncIterable,
4141 isUint8ArrayBatch,
@@ -136,7 +136,7 @@ function* flattenTransformYieldSync(value) {
136136 return ;
137137 }
138138 if ( ArrayBufferIsView ( value ) ) {
139- yield primitiveToUint8Array ( value ) ;
139+ yield arrayBufferViewToUint8Array ( value ) ;
140140 return ;
141141 }
142142 // Must be Iterable<TransformYield>
@@ -170,7 +170,7 @@ async function* flattenTransformYieldAsync(value) {
170170 return ;
171171 }
172172 if ( ArrayBufferIsView ( value ) ) {
173- yield primitiveToUint8Array ( value ) ;
173+ yield arrayBufferViewToUint8Array ( value ) ;
174174 return ;
175175 }
176176 // Check for async iterable first
@@ -180,10 +180,10 @@ async function* flattenTransformYieldAsync(value) {
180180 }
181181 return ;
182182 }
183- // Must be sync Iterable<TransformYield>
183+ // Must be sync Iterable<TransformYield>, no nested async iterables
184184 if ( isSyncIterable ( value ) ) {
185185 for ( const item of value ) {
186- yield * flattenTransformYieldAsync ( item ) ;
186+ yield * flattenTransformYieldSync ( item ) ;
187187 }
188188 return ;
189189 }
@@ -218,7 +218,7 @@ function* processTransformResultSync(result) {
218218 return ;
219219 }
220220 if ( ArrayBufferIsView ( result ) ) {
221- yield [ primitiveToUint8Array ( result ) ] ;
221+ yield [ arrayBufferViewToUint8Array ( result ) ] ;
222222 return ;
223223 }
224224 // Uint8Array[] batch
@@ -278,7 +278,7 @@ async function* processTransformResultAsync(result) {
278278 return ;
279279 }
280280 if ( ArrayBufferIsView ( result ) ) {
281- yield [ primitiveToUint8Array ( result ) ] ;
281+ yield [ arrayBufferViewToUint8Array ( result ) ] ;
282282 return ;
283283 }
284284 // Uint8Array[] batch
@@ -313,7 +313,9 @@ async function* processTransformResultAsync(result) {
313313 ArrayPrototypePush ( batch , item ) ;
314314 continue ;
315315 }
316- for await ( const chunk of flattenTransformYieldAsync ( item ) ) {
316+ // Note: This iteration is synchronous, since async iterables
317+ // may not be nested within sync iterables.
318+ for ( const chunk of flattenTransformYieldSync ( item ) ) {
317319 ArrayPrototypePush ( batch , chunk ) ;
318320 }
319321 }
@@ -366,7 +368,7 @@ function* applyFusedStatelessSyncTransforms(source, run) {
366368 } else if ( isAnyArrayBuffer ( current ) ) {
367369 yield [ new Uint8Array ( current ) ] ;
368370 } else if ( ArrayBufferIsView ( current ) ) {
369- yield [ primitiveToUint8Array ( current ) ] ;
371+ yield [ arrayBufferViewToUint8Array ( current ) ] ;
370372 } else {
371373 yield * processTransformResultSync ( current ) ;
372374 }
@@ -428,7 +430,7 @@ function* createSyncPipeline(source, transforms) {
428430 }
429431 current = applyStatefulSyncTransform ( current , transform . transform ) ;
430432 } else {
431- statelessRun . push ( transform ) ;
433+ ArrayPrototypePush ( statelessRun , transform ) ;
432434 }
433435 }
434436 if ( statelessRun . length > 0 ) {
@@ -490,7 +492,7 @@ async function* applyFusedStatelessAsyncTransforms(source, run, signal) {
490492 } else if ( isAnyArrayBuffer ( current ) ) {
491493 yield [ new Uint8Array ( current ) ] ;
492494 } else if ( ArrayBufferIsView ( current ) ) {
493- yield [ primitiveToUint8Array ( current ) ] ;
495+ yield [ arrayBufferViewToUint8Array ( current ) ] ;
494496 } else {
495497 yield * processTransformResultAsync ( current ) ;
496498 }
@@ -531,9 +533,7 @@ async function* applyFusedStatelessAsyncTransforms(source, run, signal) {
531533 * @yields {Uint8Array[]}
532534 */
533535async function * withFlushAsync ( source ) {
534- for await ( const batch of source ) {
535- yield batch ;
536- }
536+ yield * source ;
537537 yield null ;
538538}
539539
@@ -647,7 +647,7 @@ async function* createAsyncPipeline(source, transforms, signal) {
647647 current , transform . transform , opts ) ;
648648 }
649649 } else {
650- statelessRun . push ( transform ) ;
650+ ArrayPrototypePush ( statelessRun , transform ) ;
651651 }
652652 }
653653 // Flush remaining stateless run
0 commit comments