fs: change streams to always emit close by default

Previously due to compat reasons 'close' was only emitted if no 'error'.
This removes the compat behavior in order to properly follow expected
streams behavior.

PR-URL: https://github.com/nodejs/node/pull/31408
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Rich Trott <rtrott@gmail.com>
This commit is contained in:
Robert Nagy 2020-01-18 14:56:59 +01:00 committed by Rich Trott
parent dcba12895a
commit f0d2df41f8
2 changed files with 3 additions and 15 deletions

View File

@ -73,10 +73,6 @@ function ReadStream(path, options) {
if (options.highWaterMark === undefined)
options.highWaterMark = 64 * 1024;
// For backwards compat do not emit close on destroy.
if (options.emitClose === undefined) {
options.emitClose = false;
}
if (options.autoDestroy === undefined) {
options.autoDestroy = false;
}
@ -269,12 +265,8 @@ ReadStream.prototype._destroy = function(err, cb) {
function closeFsStream(stream, cb, err) {
stream[kFs].close(stream.fd, (er) => {
er = er || err;
cb(er);
stream.closed = true;
const s = stream._writableState || stream._readableState;
if (!er && !s.emitClose)
stream.emit('close');
cb(er || err);
});
stream.fd = null;
@ -298,10 +290,6 @@ function WriteStream(path, options) {
// Only buffers are supported.
options.decodeStrings = true;
// For backwards compat do not emit close on destroy.
if (options.emitClose === undefined) {
options.emitClose = false;
}
if (options.autoDestroy === undefined) {
options.autoDestroy = false;
}

View File

@ -8,13 +8,13 @@ tmpdir.refresh();
{
const stream = fs.createReadStream(__filename);
stream.on('close', common.mustNotCall());
stream.on('close', common.mustCall());
test(stream);
}
{
const stream = fs.createWriteStream(`${tmpdir.path}/dummy`);
stream.on('close', common.mustNotCall());
stream.on('close', common.mustCall());
test(stream);
}