diff --git a/lib/fs.js b/lib/fs.js index 7469875d71cc12..5242c909253efe 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -2016,7 +2016,7 @@ ReadStream.prototype.close = function(cb) { if (this.closed || typeof this.fd !== 'number') { if (typeof this.fd !== 'number') { - this.once('open', this.close.bind(this, null)); + this.once('open', closeOnOpen); return; } return process.nextTick(() => this.emit('close')); @@ -2034,6 +2034,11 @@ ReadStream.prototype.close = function(cb) { this.fd = null; }; +// needed because as it will be called with arguments +// that does not match this.close() signature +function closeOnOpen(fd) { + this.close(); +} fs.createWriteStream = function(path, options) { return new WriteStream(path, options);