fs: fix missing 'error' event in (Read|Write)Stream#destroy
fs.ReadStream / fs.WriteStream destroy([error]) function should emit 'error' event if `error` is set. PR-URL: https://github.com/nodejs/node/pull/19735 Fixes: https://github.com/nodejs/node/issues/19727 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
This commit is contained in:
parent
9c06770443
commit
6e2d5af0e4
@ -2128,7 +2128,7 @@ ReadStream.prototype._destroy = function(err, cb) {
|
||||
return;
|
||||
}
|
||||
|
||||
closeFsStream(this, cb);
|
||||
closeFsStream(this, cb, err);
|
||||
this.fd = null;
|
||||
};
|
||||
|
||||
|
20
test/parallel/test-fs-stream-destroy-emit-error.js
Normal file
20
test/parallel/test-fs-stream-destroy-emit-error.js
Normal file
@ -0,0 +1,20 @@
|
||||
'use strict';
|
||||
const common = require('../common');
|
||||
const assert = require('assert');
|
||||
const fs = require('fs');
|
||||
|
||||
const tmpdir = require('../common/tmpdir');
|
||||
tmpdir.refresh();
|
||||
|
||||
test(fs.createReadStream(__filename));
|
||||
test(fs.createWriteStream(`${tmpdir.path}/dummy`));
|
||||
|
||||
function test(stream) {
|
||||
const err = new Error('DESTROYED');
|
||||
stream.on('open', function() {
|
||||
stream.destroy(err);
|
||||
});
|
||||
stream.on('error', common.mustCall(function(err_) {
|
||||
assert.strictEqual(err_, err);
|
||||
}));
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user