summaryrefslogtreecommitdiff
path: root/lib/internal/fs/streams.js
diff options
context:
space:
mode:
authorRobert Nagy <ronagy@icloud.com>2019-10-11 12:12:18 +0200
committerRich Trott <rtrott@gmail.com>2019-10-13 16:22:23 -0700
commitba45367830f6a5c73c20e64ee71265d3aa4af719 (patch)
treed45d5045080a0853452971b583e96a1c90024fe8 /lib/internal/fs/streams.js
parent6f814013f45698a9178203331b62e3fe07fdb7d5 (diff)
downloadandroid-node-v8-ba45367830f6a5c73c20e64ee71265d3aa4af719.tar.gz
android-node-v8-ba45367830f6a5c73c20e64ee71265d3aa4af719.tar.bz2
android-node-v8-ba45367830f6a5c73c20e64ee71265d3aa4af719.zip
fs: do not emit 'finish' before 'open' on write empty file
'finish' could previously be emitted before the file has been created when ending a write stream without having written any data. Refs: https://github.com/expressjs/multer/issues/238 PR-URL: https://github.com/nodejs/node/pull/29930 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Diffstat (limited to 'lib/internal/fs/streams.js')
-rw-r--r--lib/internal/fs/streams.js6
1 files changed, 6 insertions, 0 deletions
diff --git a/lib/internal/fs/streams.js b/lib/internal/fs/streams.js
index 3674a71f92..673dab34fb 100644
--- a/lib/internal/fs/streams.js
+++ b/lib/internal/fs/streams.js
@@ -284,6 +284,12 @@ Object.setPrototypeOf(WriteStream.prototype, Writable.prototype);
Object.setPrototypeOf(WriteStream, Writable);
WriteStream.prototype._final = function(callback) {
+ if (typeof this.fd !== 'number') {
+ return this.once('open', function() {
+ this._final(callback);
+ });
+ }
+
if (this.autoClose) {
this.destroy();
}