Skip to content

Commit

Permalink
fs: replace a bind() with a top-level function
Browse files Browse the repository at this point in the history
#11225 introduce an unnecessary
bind() when closing a stream. This PR replaces that bind() with a
top-level function.

PR-URL: #13474
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Brian White <mscdex@mscdex.net>
Reviewed-By: Evan Lucas <evanlucas@me.com>
  • Loading branch information
mcollina authored and jasnell committed Jun 7, 2017
1 parent ba817d3 commit 5644dd7
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand All @@ -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);
Expand Down

0 comments on commit 5644dd7

Please sign in to comment.