lib: convert to arrow function in fs.js
PR-URL: https://github.com/nodejs/node/pull/24604 Reviewed-By: Ouyang Yadong <oyydoibh@gmail.com> Reviewed-By: Shingo Inoue <leko.noor@gmail.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
This commit is contained in:
parent
f5b8853d40
commit
32b0958c58
30
lib/fs.js
30
lib/fs.js
@ -144,7 +144,7 @@ function makeCallback(cb) {
|
|||||||
throw new ERR_INVALID_CALLBACK();
|
throw new ERR_INVALID_CALLBACK();
|
||||||
}
|
}
|
||||||
|
|
||||||
return function(...args) {
|
return (...args) => {
|
||||||
return Reflect.apply(cb, undefined, args);
|
return Reflect.apply(cb, undefined, args);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -157,7 +157,7 @@ function makeStatsCallback(cb) {
|
|||||||
throw new ERR_INVALID_CALLBACK();
|
throw new ERR_INVALID_CALLBACK();
|
||||||
}
|
}
|
||||||
|
|
||||||
return function(err, stats) {
|
return (err, stats) => {
|
||||||
if (err) return cb(err);
|
if (err) return cb(err);
|
||||||
cb(err, getStatsFromBinding(stats));
|
cb(err, getStatsFromBinding(stats));
|
||||||
};
|
};
|
||||||
@ -631,11 +631,11 @@ function truncate(path, len, callback) {
|
|||||||
|
|
||||||
validateInteger(len, 'len');
|
validateInteger(len, 'len');
|
||||||
callback = maybeCallback(callback);
|
callback = maybeCallback(callback);
|
||||||
fs.open(path, 'r+', function(er, fd) {
|
fs.open(path, 'r+', (er, fd) => {
|
||||||
if (er) return callback(er);
|
if (er) return callback(er);
|
||||||
const req = new FSReqCallback();
|
const req = new FSReqCallback();
|
||||||
req.oncomplete = function oncomplete(er) {
|
req.oncomplete = function oncomplete(er) {
|
||||||
fs.close(fd, function(er2) {
|
fs.close(fd, (er2) => {
|
||||||
callback(er || er2);
|
callback(er || er2);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@ -995,15 +995,15 @@ function fchmodSync(fd, mode) {
|
|||||||
|
|
||||||
function lchmod(path, mode, callback) {
|
function lchmod(path, mode, callback) {
|
||||||
callback = maybeCallback(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) {
|
if (err) {
|
||||||
callback(err);
|
callback(err);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Prefer to return the chmod error, if one occurs,
|
// Prefer to return the chmod error, if one occurs,
|
||||||
// but still try to close, and report closing errors if they occur.
|
// but still try to close, and report closing errors if they occur.
|
||||||
fs.fchmod(fd, mode, function(err) {
|
fs.fchmod(fd, mode, (err) => {
|
||||||
fs.close(fd, function(err2) {
|
fs.close(fd, (err2) => {
|
||||||
callback(err || err2);
|
callback(err || err2);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -1152,7 +1152,7 @@ function futimesSync(fd, atime, mtime) {
|
|||||||
|
|
||||||
function writeAll(fd, isUserFd, buffer, offset, length, position, callback) {
|
function writeAll(fd, isUserFd, buffer, offset, length, position, callback) {
|
||||||
// write(fd, 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 (writeErr) {
|
||||||
if (isUserFd) {
|
if (isUserFd) {
|
||||||
callback(writeErr);
|
callback(writeErr);
|
||||||
@ -1188,7 +1188,7 @@ function writeFile(path, data, options, callback) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
fs.open(path, flag, options.mode, function(openErr, fd) {
|
fs.open(path, flag, options.mode, (openErr, fd) => {
|
||||||
if (openErr) {
|
if (openErr) {
|
||||||
callback(openErr);
|
callback(openErr);
|
||||||
} else {
|
} else {
|
||||||
@ -1531,7 +1531,7 @@ function realpathSync(p, options) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
realpathSync.native = function(path, options) {
|
realpathSync.native = (path, options) => {
|
||||||
options = getOptions(options, {});
|
options = getOptions(options, {});
|
||||||
path = toPathIfFileURL(path);
|
path = toPathIfFileURL(path);
|
||||||
validatePath(path);
|
validatePath(path);
|
||||||
@ -1572,7 +1572,7 @@ function realpath(p, options, callback) {
|
|||||||
|
|
||||||
// On windows, check that the root exists. On unix there is no need.
|
// On windows, check that the root exists. On unix there is no need.
|
||||||
if (isWindows && !knownHard[base]) {
|
if (isWindows && !knownHard[base]) {
|
||||||
fs.lstat(base, function(err, stats) {
|
fs.lstat(base, (err, stats) => {
|
||||||
if (err) return callback(err);
|
if (err) return callback(err);
|
||||||
knownHard[base] = true;
|
knownHard[base] = true;
|
||||||
LOOP();
|
LOOP();
|
||||||
@ -1636,10 +1636,10 @@ function realpath(p, options, callback) {
|
|||||||
return gotTarget(null, seenLinks[id], base);
|
return gotTarget(null, seenLinks[id], base);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fs.stat(base, function(err) {
|
fs.stat(base, (err) => {
|
||||||
if (err) return callback(err);
|
if (err) return callback(err);
|
||||||
|
|
||||||
fs.readlink(base, function(err, target) {
|
fs.readlink(base, (err, target) => {
|
||||||
if (!isWindows) seenLinks[id] = target;
|
if (!isWindows) seenLinks[id] = target;
|
||||||
gotTarget(err, target);
|
gotTarget(err, target);
|
||||||
});
|
});
|
||||||
@ -1660,7 +1660,7 @@ function realpath(p, options, callback) {
|
|||||||
|
|
||||||
// On windows, check that the root exists. On unix there is no need.
|
// On windows, check that the root exists. On unix there is no need.
|
||||||
if (isWindows && !knownHard[base]) {
|
if (isWindows && !knownHard[base]) {
|
||||||
fs.lstat(base, function(err) {
|
fs.lstat(base, (err) => {
|
||||||
if (err) return callback(err);
|
if (err) return callback(err);
|
||||||
knownHard[base] = true;
|
knownHard[base] = true;
|
||||||
LOOP();
|
LOOP();
|
||||||
@ -1672,7 +1672,7 @@ function realpath(p, options, callback) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
realpath.native = function(path, options, callback) {
|
realpath.native = (path, options, callback) => {
|
||||||
callback = makeCallback(callback || options);
|
callback = makeCallback(callback || options);
|
||||||
options = getOptions(options, {});
|
options = getOptions(options, {});
|
||||||
path = toPathIfFileURL(path);
|
path = toPathIfFileURL(path);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user