mirror of https://github.com/nodejs/node.git
fs: use finished over destroy w/ cb
destroy w/ is undocumented API which also will cause a race if the stream is already destroying and potentially invoking the callback too early and withou error. PR-URL: https://github.com/nodejs/node/pull/32809 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Denys Otrishko <shishugi@gmail.com>
This commit is contained in:
parent
3f5142daa8
commit
a495a5ea4a
|
@ -23,7 +23,7 @@ const {
|
|||
copyObject,
|
||||
getOptions,
|
||||
} = require('internal/fs/utils');
|
||||
const { Readable, Writable } = require('stream');
|
||||
const { Readable, Writable, finished } = require('stream');
|
||||
const { toPathIfFileURL } = require('internal/url');
|
||||
const kIoDone = Symbol('kIoDone');
|
||||
const kIsPerformingIO = Symbol('kIsPerformingIO');
|
||||
|
@ -273,7 +273,8 @@ function closeFsStream(stream, cb, err) {
|
|||
}
|
||||
|
||||
ReadStream.prototype.close = function(cb) {
|
||||
this.destroy(null, cb);
|
||||
if (typeof cb === 'function') finished(this, cb);
|
||||
this.destroy();
|
||||
};
|
||||
|
||||
ObjectDefineProperty(ReadStream.prototype, 'pending', {
|
||||
|
|
Loading…
Reference in New Issue