Skip to content

Commit c3a49d7

Browse files
committed
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.
1 parent 7d5a86c commit c3a49d7

File tree

2 files changed

+3
-15
lines changed

2 files changed

+3
-15
lines changed

lib/internal/fs/streams.js

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,6 @@ function ReadStream(path, options) {
7373
if (options.highWaterMark === undefined)
7474
options.highWaterMark = 64 * 1024;
7575

76-
// For backwards compat do not emit close on destroy.
77-
if (options.emitClose === undefined) {
78-
options.emitClose = false;
79-
}
8076
if (options.autoDestroy === undefined) {
8177
options.autoDestroy = false;
8278
}
@@ -269,12 +265,8 @@ ReadStream.prototype._destroy = function(err, cb) {
269265

270266
function closeFsStream(stream, cb, err) {
271267
stream[kFs].close(stream.fd, (er) => {
272-
er = er || err;
273-
cb(er);
274268
stream.closed = true;
275-
const s = stream._writableState || stream._readableState;
276-
if (!er && !s.emitClose)
277-
stream.emit('close');
269+
cb(er || err);
278270
});
279271

280272
stream.fd = null;
@@ -298,10 +290,6 @@ function WriteStream(path, options) {
298290
// Only buffers are supported.
299291
options.decodeStrings = true;
300292

301-
// For backwards compat do not emit close on destroy.
302-
if (options.emitClose === undefined) {
303-
options.emitClose = false;
304-
}
305293
if (options.autoDestroy === undefined) {
306294
options.autoDestroy = false;
307295
}

test/parallel/test-fs-stream-destroy-emit-error.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ tmpdir.refresh();
88

99
{
1010
const stream = fs.createReadStream(__filename);
11-
stream.on('close', common.mustNotCall());
11+
stream.on('close', common.mustCall());
1212
test(stream);
1313
}
1414

1515
{
1616
const stream = fs.createWriteStream(`${tmpdir.path}/dummy`);
17-
stream.on('close', common.mustNotCall());
17+
stream.on('close', common.mustCall());
1818
test(stream);
1919
}
2020

0 commit comments

Comments
 (0)