Skip to content

Commit

Permalink
lib: convert to arrow function in fs.js
Browse files Browse the repository at this point in the history
PR-URL: #24604
Reviewed-By: Ouyang Yadong <oyydoibh@gmail.com>
Reviewed-By: Shingo Inoue <leko.noor@gmail.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
  • Loading branch information
exoego authored and BethGriggs committed Feb 12, 2019
1 parent 06208c8 commit 1b48c9d
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ function makeCallback(cb) {
throw new ERR_INVALID_CALLBACK();
}

return function(...args) {
return (...args) => {
return Reflect.apply(cb, undefined, args);
};
}
Expand All @@ -150,7 +150,7 @@ function makeStatsCallback(cb) {
throw new ERR_INVALID_CALLBACK();
}

return function(err, stats) {
return (err, stats) => {
if (err) return cb(err);
cb(err, getStatsFromBinding(stats));
};
Expand Down Expand Up @@ -608,11 +608,11 @@ function truncate(path, len, callback) {

validateInteger(len, 'len');
callback = maybeCallback(callback);
fs.open(path, 'r+', function(er, fd) {
fs.open(path, 'r+', (er, fd) => {
if (er) return callback(er);
const req = new FSReqWrap();
req.oncomplete = function oncomplete(er) {
fs.close(fd, function(er2) {
fs.close(fd, (er2) => {
callback(er || er2);
});
};
Expand Down Expand Up @@ -972,15 +972,15 @@ function fchmodSync(fd, mode) {

function lchmod(path, mode, callback) {
callback = maybeCallback(callback);
fs.open(path, O_WRONLY | O_SYMLINK, function(err, fd) {
fs.open(path, O_WRONLY | O_SYMLINK, (err, fd) => {
if (err) {
callback(err);
return;
}
// Prefer to return the chmod error, if one occurs,
// but still try to close, and report closing errors if they occur.
fs.fchmod(fd, mode, function(err) {
fs.close(fd, function(err2) {
fs.fchmod(fd, mode, (err) => {
fs.close(fd, (err2) => {
callback(err || err2);
});
});
Expand Down Expand Up @@ -1129,7 +1129,7 @@ function futimesSync(fd, atime, mtime) {

function writeAll(fd, isUserFd, buffer, offset, length, position, callback) {
// write(fd, buffer, offset, length, position, callback)
fs.write(fd, buffer, offset, length, position, function(writeErr, written) {
fs.write(fd, buffer, offset, length, position, (writeErr, written) => {
if (writeErr) {
if (isUserFd) {
callback(writeErr);
Expand Down Expand Up @@ -1165,7 +1165,7 @@ function writeFile(path, data, options, callback) {
return;
}

fs.open(path, flag, options.mode, function(openErr, fd) {
fs.open(path, flag, options.mode, (openErr, fd) => {
if (openErr) {
callback(openErr);
} else {
Expand Down Expand Up @@ -1508,7 +1508,7 @@ function realpathSync(p, options) {
}


realpathSync.native = function(path, options) {
realpathSync.native = (path, options) => {
options = getOptions(options, {});
path = toPathIfFileURL(path);
validatePath(path);
Expand Down Expand Up @@ -1549,7 +1549,7 @@ function realpath(p, options, callback) {

// On windows, check that the root exists. On unix there is no need.
if (isWindows && !knownHard[base]) {
fs.lstat(base, function(err, stats) {
fs.lstat(base, (err, stats) => {
if (err) return callback(err);
knownHard[base] = true;
LOOP();
Expand Down Expand Up @@ -1613,10 +1613,10 @@ function realpath(p, options, callback) {
return gotTarget(null, seenLinks[id], base);
}
}
fs.stat(base, function(err) {
fs.stat(base, (err) => {
if (err) return callback(err);

fs.readlink(base, function(err, target) {
fs.readlink(base, (err, target) => {
if (!isWindows) seenLinks[id] = target;
gotTarget(err, target);
});
Expand All @@ -1637,7 +1637,7 @@ function realpath(p, options, callback) {

// On windows, check that the root exists. On unix there is no need.
if (isWindows && !knownHard[base]) {
fs.lstat(base, function(err) {
fs.lstat(base, (err) => {
if (err) return callback(err);
knownHard[base] = true;
LOOP();
Expand All @@ -1649,7 +1649,7 @@ function realpath(p, options, callback) {
}


realpath.native = function(path, options, callback) {
realpath.native = (path, options, callback) => {
callback = makeCallback(callback || options);
options = getOptions(options, {});
path = toPathIfFileURL(path);
Expand Down

0 comments on commit 1b48c9d

Please sign in to comment.