mirror of
https://github.com/nodejs/node.git
synced 2025-05-17 00:33:26 +00:00
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:
parent
dcba12895a
commit
f0d2df41f8
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user