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) {
486
486
}
487
487
state . ended = true ;
488
488
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
+ }
494
501
}
495
502
}
496
503
You can’t perform that action at this time.
0 commit comments