From 37461878d0d29a987bb4ec8c7cbdfc8d1464f36d Mon Sep 17 00:00:00 2001 From: Jackson Tian Date: Mon, 7 May 2018 01:16:09 +0800 Subject: [PATCH] fs: use _final() for fs.WriteStream use _final() method instead of once 'finish' event. PR-URL: https://github.com/nodejs/node/pull/20562 Reviewed-By: Luigi Pinca Reviewed-By: Anna Henningsen Reviewed-By: Trivikram Kamat Reviewed-By: James M Snell --- lib/fs.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) 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) => {