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 <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Brian White <[email protected]>
Reviewed-By: Evan Lucas <[email protected]>
  • Loading branch information
mcollina committed Jun 7, 2017
1 parent 2db2857 commit 07ca288
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 07ca288

Please sign in to comment.