Skip to content

Commit f1ac7df

Browse files
authored
fs: fix typings
PR-URL: #53626 Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent ce2faef commit f1ac7df

File tree

2 files changed

+19
-19
lines changed

2 files changed

+19
-19
lines changed

lib/fs.js

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ function exists(path, callback) {
255255
validateFunction(callback, 'cb');
256256

257257
function suppressedCallback(err) {
258-
callback(err ? false : true);
258+
callback(!err);
259259
}
260260

261261
try {
@@ -751,8 +751,8 @@ function readSync(fd, buffer, offsetOrOptions, length, position) {
751751
* @param {(
752752
* err?: Error,
753753
* bytesRead?: number,
754-
* buffers?: ArrayBufferView[];
755-
* ) => any} callback
754+
* buffers?: ArrayBufferView[]
755+
* ) => any} callback
756756
* @returns {void}
757757
*/
758758
function readv(fd, buffers, position, callback) {
@@ -805,9 +805,9 @@ function readvSync(fd, buffers, position) {
805805
* @param {number | null} [position]
806806
* @param {(
807807
* err?: Error,
808-
* bytesWritten?: number;
808+
* bytesWritten?: number,
809809
* buffer?: Buffer | TypedArray | DataView
810-
* ) => any} callback
810+
* ) => any} callback
811811
* @returns {void}
812812
*/
813813
function write(fd, buffer, offsetOrOptions, length, position, callback) {
@@ -883,6 +883,8 @@ ObjectDefineProperty(write, kCustomPromisifyArgsSymbol,
883883
* length?: number;
884884
* position?: number | null;
885885
* }} [offsetOrOptions]
886+
* @param {number} [length]
887+
* @param {number} [position]
886888
* @returns {number}
887889
*/
888890
function writeSync(fd, buffer, offsetOrOptions, length, position) {
@@ -1074,14 +1076,11 @@ function truncateSync(path, len) {
10741076
}
10751077
// Allow error to be thrown, but still close fd.
10761078
const fd = fs.openSync(path, 'r+');
1077-
let ret;
1078-
10791079
try {
1080-
ret = fs.ftruncateSync(fd, len);
1080+
fs.ftruncateSync(fd, len);
10811081
} finally {
10821082
fs.closeSync(fd);
10831083
}
1084-
return ret;
10851084
}
10861085

10871086
/**
@@ -1442,9 +1441,9 @@ function readdirSyncRecursive(basePath, options) {
14421441
* recursive?: boolean;
14431442
* }} [options]
14441443
* @param {(
1445-
* err?: Error;
1446-
* files?: string[] | Buffer[] | Dirent[];
1447-
* ) => any} callback
1444+
* err?: Error,
1445+
* files?: string[] | Buffer[] | Dirent[]
1446+
* ) => any} callback
14481447
* @returns {void}
14491448
*/
14501449
function readdir(path, options, callback) {
@@ -1932,13 +1931,11 @@ function lchmodSync(path, mode) {
19321931

19331932
// Prefer to return the chmod error, if one occurs,
19341933
// but still try to close, and report closing errors if they occur.
1935-
let ret;
19361934
try {
1937-
ret = fs.fchmodSync(fd, mode);
1935+
fs.fchmodSync(fd, mode);
19381936
} finally {
19391937
fs.closeSync(fd);
19401938
}
1941-
return ret;
19421939
}
19431940

19441941
/**
@@ -2796,7 +2793,7 @@ function realpath(p, options, callback) {
27962793

27972794
// On windows, check that the root exists. On unix there is no need.
27982795
if (isWindows && !knownHard.has(base)) {
2799-
fs.lstat(base, (err, stats) => {
2796+
fs.lstat(base, (err) => {
28002797
if (err) return callback(err);
28012798
knownHard.add(base);
28022799
LOOP();

typings/internalBinding/fs.d.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ declare namespace InternalFSBinding {
5757
}
5858

5959
function access(path: StringOrBuffer, mode: number, req: FSReqCallback): void;
60-
function access(path: StringOrBuffer, mode: number, req: undefined, ctx: FSSyncContext): void;
60+
function access(path: StringOrBuffer, mode: number): void;
6161
function access(path: StringOrBuffer, mode: number, usePromises: typeof kUsePromises): Promise<void>;
6262

6363
function chmod(path: string, mode: number, req: FSReqCallback): void;
@@ -70,7 +70,7 @@ declare namespace InternalFSBinding {
7070
function chown(path: string, uid: number, gid: number): void;
7171

7272
function close(fd: number, req: FSReqCallback): void;
73-
function close(fd: number, req: undefined, ctx: FSSyncContext): void;
73+
function close(fd: number): void;
7474

7575
function copyFile(src: StringOrBuffer, dest: StringOrBuffer, mode: number, req: FSReqCallback): void;
7676
function copyFile(src: StringOrBuffer, dest: StringOrBuffer, mode: number, req: undefined, ctx: FSSyncContext): void;
@@ -153,7 +153,7 @@ declare namespace InternalFSBinding {
153153
function mkdir(path: string, mode: number, recursive: false, usePromises: typeof kUsePromises): Promise<void>;
154154

155155
function open(path: StringOrBuffer, flags: number, mode: number, req: FSReqCallback<number>): void;
156-
function open(path: StringOrBuffer, flags: number, mode: number, req: undefined, ctx: FSSyncContext): number;
156+
function open(path: StringOrBuffer, flags: number, mode: number): number;
157157

158158
function openFileHandle(path: StringOrBuffer, flags: number, mode: number, usePromises: typeof kUsePromises): Promise<FileHandle>;
159159

@@ -175,6 +175,8 @@ declare namespace InternalFSBinding {
175175
function readdir(path: StringOrBuffer, encoding: unknown, withFileTypes: true, usePromises: typeof kUsePromises): Promise<[string[], number[]]>;
176176
function readdir(path: StringOrBuffer, encoding: unknown, withFileTypes: false, usePromises: typeof kUsePromises): Promise<string[]>;
177177

178+
function readFileUtf8(path: StringOrBuffer, flags: number): string;
179+
178180
function readlink(path: StringOrBuffer, encoding: unknown, req: FSReqCallback<string | Buffer>): void;
179181
function readlink(path: StringOrBuffer, encoding: unknown, req: undefined, ctx: FSSyncContext): string | Buffer;
180182
function readlink(path: StringOrBuffer, encoding: unknown, usePromises: typeof kUsePromises): Promise<string | Buffer>;
@@ -272,6 +274,7 @@ export interface FsBinding {
272274
read: typeof InternalFSBinding.read;
273275
readBuffers: typeof InternalFSBinding.readBuffers;
274276
readdir: typeof InternalFSBinding.readdir;
277+
readFileUtf8: typeof InternalFSBinding.readFileUtf8;
275278
readlink: typeof InternalFSBinding.readlink;
276279
realpath: typeof InternalFSBinding.realpath;
277280
rename: typeof InternalFSBinding.rename;

0 commit comments

Comments
 (0)