diff --git a/lib/fs.js b/lib/fs.js index 04c685e0c7f..8a5ee87fbaa 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -2214,17 +2214,17 @@ function WriteStream(path, options) { if (typeof this.fd !== 'number') this.open(); - - // dispose on finish. - this.once('finish', function() { - if (this.autoClose) { - this.destroy(); - } - }); } fs.FileWriteStream = fs.WriteStream; // support the legacy name +WriteStream.prototype._final = function(callback) { + if (this.autoClose) { + this.destroy(); + } + + callback(); +}; WriteStream.prototype.open = function() { fs.open(this.path, this.flags, this.mode, (er, fd) => {