Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 7ebaf83

Browse filesBrowse files
starkwangMylesBorins
authored andcommitted
fs: use arrow functions instead of .bind and self
PR-URL: #17137 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 1a3aadb commit 7ebaf83
Copy full SHA for 7ebaf83

File tree

Expand file treeCollapse file tree

1 file changed

+18
-22
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+18
-22
lines changed
Open diff view settings
Collapse file

‎lib/fs.js‎

Copy file name to clipboardExpand all lines: lib/fs.js
+18-22Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2091,30 +2091,27 @@ ReadStream.prototype._read = function(n) {
20912091
return this.push(null);
20922092

20932093
// the actual read.
2094-
var self = this;
2095-
fs.read(this.fd, pool, pool.used, toRead, this.pos, onread);
2096-
2097-
// move the pool positions, and internal position for reading.
2098-
if (this.pos !== undefined)
2099-
this.pos += toRead;
2100-
pool.used += toRead;
2101-
2102-
function onread(er, bytesRead) {
2094+
fs.read(this.fd, pool, pool.used, toRead, this.pos, (er, bytesRead) => {
21032095
if (er) {
2104-
if (self.autoClose) {
2105-
self.destroy();
2096+
if (this.autoClose) {
2097+
this.destroy();
21062098
}
2107-
self.emit('error', er);
2099+
this.emit('error', er);
21082100
} else {
21092101
var b = null;
21102102
if (bytesRead > 0) {
2111-
self.bytesRead += bytesRead;
2103+
this.bytesRead += bytesRead;
21122104
b = thisPool.slice(start, start + bytesRead);
21132105
}
21142106

2115-
self.push(b);
2107+
this.push(b);
21162108
}
2117-
}
2109+
});
2110+
2111+
// move the pool positions, and internal position for reading.
2112+
if (this.pos !== undefined)
2113+
this.pos += toRead;
2114+
pool.used += toRead;
21182115
};
21192116

21202117
ReadStream.prototype._destroy = function(err, cb) {
@@ -2209,7 +2206,7 @@ fs.FileWriteStream = fs.WriteStream; // support the legacy name
22092206

22102207

22112208
WriteStream.prototype.open = function() {
2212-
fs.open(this.path, this.flags, this.mode, function(er, fd) {
2209+
fs.open(this.path, this.flags, this.mode, (er, fd) => {
22132210
if (er) {
22142211
if (this.autoClose) {
22152212
this.destroy();
@@ -2220,7 +2217,7 @@ WriteStream.prototype.open = function() {
22202217

22212218
this.fd = fd;
22222219
this.emit('open', fd);
2223-
}.bind(this));
2220+
});
22242221
};
22252222

22262223

@@ -2234,15 +2231,14 @@ WriteStream.prototype._write = function(data, encoding, cb) {
22342231
});
22352232
}
22362233

2237-
var self = this;
2238-
fs.write(this.fd, data, 0, data.length, this.pos, function(er, bytes) {
2234+
fs.write(this.fd, data, 0, data.length, this.pos, (er, bytes) => {
22392235
if (er) {
2240-
if (self.autoClose) {
2241-
self.destroy();
2236+
if (this.autoClose) {
2237+
this.destroy();
22422238
}
22432239
return cb(er);
22442240
}
2245-
self.bytesWritten += bytes;
2241+
this.bytesWritten += bytes;
22462242
cb();
22472243
});
22482244

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.