mirror of
https://github.com/zebrajr/node.git
synced 2026-01-15 12:15:26 +00:00
stream: eos make const state const
writable & readable is based on type and is not actual state, treat them as such. PR-URL: https://github.com/nodejs/node/pull/32031 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
This commit is contained in:
@@ -56,9 +56,9 @@ function eos(stream, opts, callback) {
|
||||
|
||||
callback = once(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 wState = stream._writableState;
|
||||
@@ -71,17 +71,15 @@ function eos(stream, opts, callback) {
|
||||
let writableFinished = stream.writableFinished ||
|
||||
(wState && wState.finished);
|
||||
const onfinish = () => {
|
||||
writable = false;
|
||||
writableFinished = true;
|
||||
if (!readable) callback.call(stream);
|
||||
if (!readable || readableEnded) callback.call(stream);
|
||||
};
|
||||
|
||||
let readableEnded = stream.readableEnded ||
|
||||
(rState && rState.endEmitted);
|
||||
const onend = () => {
|
||||
readable = false;
|
||||
readableEnded = true;
|
||||
if (!writable) callback.call(stream);
|
||||
if (!writable || writableFinished) callback.call(stream);
|
||||
};
|
||||
|
||||
const onerror = (err) => {
|
||||
@@ -89,17 +87,15 @@ function eos(stream, opts, callback) {
|
||||
};
|
||||
|
||||
const onclose = () => {
|
||||
let err;
|
||||
if (readable && !readableEnded) {
|
||||
if (!isReadableEnded(stream))
|
||||
err = new ERR_STREAM_PREMATURE_CLOSE();
|
||||
return callback.call(stream, err);
|
||||
return callback.call(stream, new ERR_STREAM_PREMATURE_CLOSE());
|
||||
}
|
||||
if (writable && !writableFinished) {
|
||||
if (!isWritableFinished(stream))
|
||||
err = new ERR_STREAM_PREMATURE_CLOSE();
|
||||
return callback.call(stream, err);
|
||||
return callback.call(stream, new ERR_STREAM_PREMATURE_CLOSE());
|
||||
}
|
||||
callback.call(stream);
|
||||
};
|
||||
|
||||
const onrequest = () => {
|
||||
|
||||
@@ -181,7 +181,7 @@ const { promisify } = require('util');
|
||||
const streamLike = new EE();
|
||||
streamLike.readableEnded = true;
|
||||
streamLike.readable = true;
|
||||
finished(streamLike, common.mustCall);
|
||||
finished(streamLike, common.mustCall());
|
||||
streamLike.emit('close');
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user