From aee59e5e59669210ee385946aeff244368265e3d Mon Sep 17 00:00:00 2001 From: Yagiz Nizipli Date: Fri, 28 Jun 2024 10:37:10 -0400 Subject: [PATCH 1/2] fs: fix typings --- lib/fs.js | 31 ++++++++++++++----------------- typings/internalBinding/fs.d.ts | 9 ++++++--- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/lib/fs.js b/lib/fs.js index 5f225a4a97e381..a61c53c8e83224 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -255,7 +255,7 @@ function exists(path, callback) { validateFunction(callback, 'cb'); function suppressedCallback(err) { - callback(err ? false : true); + callback(!err); } try { @@ -751,8 +751,8 @@ function readSync(fd, buffer, offsetOrOptions, length, position) { * @param {( * err?: Error, * bytesRead?: number, - * buffers?: ArrayBufferView[]; - * ) => any} callback + * buffers?: ArrayBufferView[] + * ) => any} callback * @returns {void} */ function readv(fd, buffers, position, callback) { @@ -805,9 +805,9 @@ function readvSync(fd, buffers, position) { * @param {number | null} [position] * @param {( * err?: Error, - * bytesWritten?: number; + * bytesWritten?: number, * buffer?: Buffer | TypedArray | DataView - * ) => any} callback + * ) => any} callback * @returns {void} */ function write(fd, buffer, offsetOrOptions, length, position, callback) { @@ -882,7 +882,9 @@ ObjectDefineProperty(write, kCustomPromisifyArgsSymbol, * offset?: number; * length?: number; * position?: number | null; - * }} [offsetOrOptions] + * }} [offsetOrOptions]s + * @param {number} [length] + * @param {number} [position] * @returns {number} */ function writeSync(fd, buffer, offsetOrOptions, length, position) { @@ -1074,14 +1076,11 @@ function truncateSync(path, len) { } // Allow error to be thrown, but still close fd. const fd = fs.openSync(path, 'r+'); - let ret; - try { - ret = fs.ftruncateSync(fd, len); + fs.ftruncateSync(fd, len); } finally { fs.closeSync(fd); } - return ret; } /** @@ -1442,9 +1441,9 @@ function readdirSyncRecursive(basePath, options) { * recursive?: boolean; * }} [options] * @param {( - * err?: Error; - * files?: string[] | Buffer[] | Dirent[]; - * ) => any} callback + * err?: Error, + * files?: string[] | Buffer[] | Dirent[] + * ) => any} callback * @returns {void} */ function readdir(path, options, callback) { @@ -1932,13 +1931,11 @@ function lchmodSync(path, mode) { // Prefer to return the chmod error, if one occurs, // but still try to close, and report closing errors if they occur. - let ret; try { - ret = fs.fchmodSync(fd, mode); + fs.fchmodSync(fd, mode); } finally { fs.closeSync(fd); } - return ret; } /** @@ -2796,7 +2793,7 @@ function realpath(p, options, callback) { // On windows, check that the root exists. On unix there is no need. if (isWindows && !knownHard.has(base)) { - fs.lstat(base, (err, stats) => { + fs.lstat(base, (err) => { if (err) return callback(err); knownHard.add(base); LOOP(); diff --git a/typings/internalBinding/fs.d.ts b/typings/internalBinding/fs.d.ts index 5a4741e99fa727..1169dc72485b21 100644 --- a/typings/internalBinding/fs.d.ts +++ b/typings/internalBinding/fs.d.ts @@ -57,7 +57,7 @@ declare namespace InternalFSBinding { } function access(path: StringOrBuffer, mode: number, req: FSReqCallback): void; - function access(path: StringOrBuffer, mode: number, req: undefined, ctx: FSSyncContext): void; + function access(path: StringOrBuffer, mode: number): void; function access(path: StringOrBuffer, mode: number, usePromises: typeof kUsePromises): Promise; function chmod(path: string, mode: number, req: FSReqCallback): void; @@ -70,7 +70,7 @@ declare namespace InternalFSBinding { function chown(path: string, uid: number, gid: number): void; function close(fd: number, req: FSReqCallback): void; - function close(fd: number, req: undefined, ctx: FSSyncContext): void; + function close(fd: number): void; function copyFile(src: StringOrBuffer, dest: StringOrBuffer, mode: number, req: FSReqCallback): void; function copyFile(src: StringOrBuffer, dest: StringOrBuffer, mode: number, req: undefined, ctx: FSSyncContext): void; @@ -153,7 +153,7 @@ declare namespace InternalFSBinding { function mkdir(path: string, mode: number, recursive: false, usePromises: typeof kUsePromises): Promise; function open(path: StringOrBuffer, flags: number, mode: number, req: FSReqCallback): void; - function open(path: StringOrBuffer, flags: number, mode: number, req: undefined, ctx: FSSyncContext): number; + function open(path: StringOrBuffer, flags: number, mode: number): number; function openFileHandle(path: StringOrBuffer, flags: number, mode: number, usePromises: typeof kUsePromises): Promise; @@ -175,6 +175,8 @@ declare namespace InternalFSBinding { function readdir(path: StringOrBuffer, encoding: unknown, withFileTypes: true, usePromises: typeof kUsePromises): Promise<[string[], number[]]>; function readdir(path: StringOrBuffer, encoding: unknown, withFileTypes: false, usePromises: typeof kUsePromises): Promise; + function readFileUtf8(path: StringOrBuffer, flags: number): string; + function readlink(path: StringOrBuffer, encoding: unknown, req: FSReqCallback): void; function readlink(path: StringOrBuffer, encoding: unknown, req: undefined, ctx: FSSyncContext): string | Buffer; function readlink(path: StringOrBuffer, encoding: unknown, usePromises: typeof kUsePromises): Promise; @@ -272,6 +274,7 @@ export interface FsBinding { read: typeof InternalFSBinding.read; readBuffers: typeof InternalFSBinding.readBuffers; readdir: typeof InternalFSBinding.readdir; + readFileUtf8: typeof InternalFSBinding.readFileUtf8; readlink: typeof InternalFSBinding.readlink; realpath: typeof InternalFSBinding.realpath; rename: typeof InternalFSBinding.rename; From 634bd62d0c035e090603dfb38af3ff2fcf6a88ad Mon Sep 17 00:00:00 2001 From: Yagiz Nizipli Date: Fri, 28 Jun 2024 10:52:24 -0400 Subject: [PATCH 2/2] Update lib/fs.js --- lib/fs.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/fs.js b/lib/fs.js index a61c53c8e83224..27dc37e33e7958 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -882,7 +882,7 @@ ObjectDefineProperty(write, kCustomPromisifyArgsSymbol, * offset?: number; * length?: number; * position?: number | null; - * }} [offsetOrOptions]s + * }} [offsetOrOptions] * @param {number} [length] * @param {number} [position] * @returns {number}