File tree Expand file tree Collapse file tree 1 file changed +12
-5
lines changed
Expand file tree Collapse file tree 1 file changed +12
-5
lines changed Original file line number Diff line number Diff line change @@ -486,11 +486,18 @@ function onEofChunk(stream, state) {
486486 }
487487 state . ended = true ;
488488
489- // emit 'readable' now to make sure it gets picked up.
490- state . needReadable = false ;
491- if ( ! state . emittedReadable ) {
492- state . emittedReadable = true ;
493- emitReadable_ ( stream ) ;
489+ if ( state . sync && state . length ) {
490+ // if we are sync and have data in the buffer, wait until next tick
491+ // to emit the data. otherwise we risk emitting data in the flow()
492+ // the readable code triggers during a read() call
493+ emitReadable ( stream ) ;
494+ } else {
495+ // emit 'readable' now to make sure it gets picked up.
496+ state . needReadable = false ;
497+ if ( ! state . emittedReadable ) {
498+ state . emittedReadable = true ;
499+ emitReadable_ ( stream ) ;
500+ }
494501 }
495502}
496503
You can’t perform that action at this time.
0 commit comments