Skip to content

Commit 5644dd7

Browse files
mcollinajasnell
authored andcommitted
fs: replace a bind() with a top-level function
#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]>
1 parent ba817d3 commit 5644dd7

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

lib/fs.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -2016,7 +2016,7 @@ ReadStream.prototype.close = function(cb) {
20162016

20172017
if (this.closed || typeof this.fd !== 'number') {
20182018
if (typeof this.fd !== 'number') {
2019-
this.once('open', this.close.bind(this, null));
2019+
this.once('open', closeOnOpen);
20202020
return;
20212021
}
20222022
return process.nextTick(() => this.emit('close'));
@@ -2034,6 +2034,11 @@ ReadStream.prototype.close = function(cb) {
20342034
this.fd = null;
20352035
};
20362036

2037+
// needed because as it will be called with arguments
2038+
// that does not match this.close() signature
2039+
function closeOnOpen(fd) {
2040+
this.close();
2041+
}
20372042

20382043
fs.createWriteStream = function(path, options) {
20392044
return new WriteStream(path, options);

0 commit comments

Comments
 (0)