File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -204,12 +204,12 @@ module.exports = function compose(...streams) {
204204 try {
205205 const { value, done } = await reader . read ( ) ;
206206
207- if ( ! d . push ( value ) ) {
207+ if ( done ) {
208+ d . push ( null ) ;
208209 return ;
209210 }
210211
211- if ( done ) {
212- d . push ( null ) ;
212+ if ( ! d . push ( value ) ) {
213213 return ;
214214 }
215215 } catch {
Original file line number Diff line number Diff line change @@ -537,3 +537,24 @@ const assert = require('assert');
537537 assert . strictEqual ( duplex . destroyed , true ) ;
538538
539539}
540+
541+ // Regression test: compose with a web TransformStream tail must always emit
542+ // null (EOF) when the source finishes. The done check must precede the
543+ // backpressure check in the reader.read() loop; otherwise push(null) can be
544+ // skipped if canPushMore() returns false on the final done:true read.
545+ {
546+ const { TransformStream } = globalThis ;
547+ const { Readable } = require ( 'stream' ) ;
548+
549+ // A web TransformStream as the tail exercises the isWebStream code path
550+ // in compose that loops over reader.read() results.
551+ const ts = new TransformStream ( ) ;
552+ const src = Readable . from ( [ 'hello' , ' ' , 'world' ] ) ;
553+ const composed = compose ( src , ts ) ;
554+
555+ let result = '' ;
556+ composed . on ( 'data' , ( chunk ) => { result += Buffer . from ( chunk ) . toString ( ) ; } ) ;
557+ composed . on ( 'end' , common . mustCall ( ( ) => {
558+ assert . strictEqual ( result , 'hello world' ) ;
559+ } ) ) ;
560+ }
You can’t perform that action at this time.
0 commit comments