From 8df6907592265c6d8b205f0c99717749c8aa35ac Mon Sep 17 00:00:00 2001 From: Matteo Collina Date: Mon, 5 Jun 2017 16:46:55 +0200 Subject: [PATCH] fs: replace a bind() with a top-level function https://github.com/nodejs/node/pull/11225 introduce an unnecessary bind() when closing a stream. This PR replaces that bind() with a top-level function. PR-URL: https://github.com/nodejs/node/pull/13474 Reviewed-By: Refael Ackermann Reviewed-By: Luigi Pinca Reviewed-By: James M Snell Reviewed-By: Colin Ihrig Reviewed-By: Brian White Reviewed-By: Evan Lucas --- lib/fs.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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);