diff --git a/lib/internal/streams/end-of-stream.js b/lib/internal/streams/end-of-stream.js index 949ab638148d24..585a52ae2f2382 100644 --- a/lib/internal/streams/end-of-stream.js +++ b/lib/internal/streams/end-of-stream.js @@ -59,9 +59,9 @@ function eos(stream, opts, callback) { }; } - let readable = opts.readable || + const readable = opts.readable || (opts.readable !== false && isReadable(stream)); - let writable = opts.writable || + const writable = opts.writable || (opts.writable !== false && isWritable(stream)); const onlegacyfinish = () => { @@ -69,15 +69,13 @@ function eos(stream, opts, callback) { }; const onfinish = () => { - writable = false; writableFinished = true; - if (!readable) callback.call(stream); + if (!readable || readableEnded) callback.call(stream); }; const onend = () => { - readable = false; readableEnded = true; - if (!writable) callback.call(stream); + if (!writable || writableFinished) callback.call(stream); }; const onclose = () => {