Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fs: use arrow functions instead of .bind or self #17137

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 18 additions & 22 deletions lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -2091,30 +2091,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;
};

ReadStream.prototype._destroy = function(err, cb) {
Expand Down Expand Up @@ -2209,7 +2206,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 @@ -2220,7 +2217,7 @@ WriteStream.prototype.open = function() {

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


Expand All @@ -2234,15 +2231,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