Skip to content

Commit

Permalink
fs: use arrow functions instead of .bind and self
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
starkwang authored and gibfahn committed Dec 20, 2017
1 parent 7900f8a commit b413e09
Showing 1 changed file with 18 additions and 22 deletions.
40 changes: 18 additions & 22 deletions lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -2026,30 +2026,27 @@ ReadStream.prototype._read = function(n) {
return this.push(null);

// the actual read.
var self = this;
fs.read(this.fd, pool, pool.used, toRead, this.pos, onread);

// move the pool positions, and internal position for reading.
if (this.pos !== undefined)
this.pos += toRead;
pool.used += toRead;

function onread(er, bytesRead) {
fs.read(this.fd, pool, pool.used, toRead, this.pos, (er, bytesRead) => {
if (er) {
if (self.autoClose) {
self.destroy();
if (this.autoClose) {
this.destroy();
}
self.emit('error', er);
this.emit('error', er);
} else {
var b = null;
if (bytesRead > 0) {
self.bytesRead += bytesRead;
this.bytesRead += bytesRead;
b = thisPool.slice(start, start + bytesRead);
}

self.push(b);
this.push(b);
}
}
});

// move the pool positions, and internal position for reading.
if (this.pos !== undefined)
this.pos += toRead;
pool.used += toRead;
};


Expand Down Expand Up @@ -2143,7 +2140,7 @@ fs.FileWriteStream = fs.WriteStream; // support the legacy name


WriteStream.prototype.open = function() {
fs.open(this.path, this.flags, this.mode, function(er, fd) {
fs.open(this.path, this.flags, this.mode, (er, fd) => {
if (er) {
if (this.autoClose) {
this.destroy();
Expand All @@ -2154,7 +2151,7 @@ WriteStream.prototype.open = function() {

this.fd = fd;
this.emit('open', fd);
}.bind(this));
});
};


Expand All @@ -2168,15 +2165,14 @@ WriteStream.prototype._write = function(data, encoding, cb) {
});
}

var self = this;
fs.write(this.fd, data, 0, data.length, this.pos, function(er, bytes) {
fs.write(this.fd, data, 0, data.length, this.pos, (er, bytes) => {
if (er) {
if (self.autoClose) {
self.destroy();
if (this.autoClose) {
this.destroy();
}
return cb(er);
}
self.bytesWritten += bytes;
this.bytesWritten += bytes;
cb();
});

Expand Down

0 comments on commit b413e09

Please sign in to comment.