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 <luigipinca@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
Jackson Tian 2018-05-07 01:16:09 +08:00 committed by Anna Henningsen
parent 34ca9f3b91
commit 37461878d0
No known key found for this signature in database
GPG Key ID: 9C63F3A6CD2AD8F9

View File

@ -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) => {