From 2d8490fed50245522ecbc50d41afbd383d8a6ce0 Mon Sep 17 00:00:00 2001 From: Yagiz Nizipli Date: Sun, 30 Jun 2024 12:39:06 -0400 Subject: [PATCH] typings: add `fs_dir` types MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/nodejs/node/pull/53631 Reviewed-By: Benjamin Gruenbaum Reviewed-By: Antoine du Hamel Reviewed-By: Vinícius Lourenço Claro Cardoso Reviewed-By: Chemi Atlow Reviewed-By: James M Snell --- typings/globals.d.ts | 2 ++ typings/internalBinding/fs.d.ts | 26 +++++++++++++------------- typings/internalBinding/fs_dir.d.ts | 21 +++++++++++++++++++++ 3 files changed, 36 insertions(+), 13 deletions(-) create mode 100644 typings/internalBinding/fs_dir.d.ts diff --git a/typings/globals.d.ts b/typings/globals.d.ts index d72bf937bb75c9..bc47c08b02b376 100644 --- a/typings/globals.d.ts +++ b/typings/globals.d.ts @@ -4,6 +4,7 @@ import {ConfigBinding} from "./internalBinding/config"; import {ConstantsBinding} from "./internalBinding/constants"; import {HttpParserBinding} from "./internalBinding/http_parser"; import {FsBinding} from "./internalBinding/fs"; +import {FsDirBinding} from "./internalBinding/fs_dir"; import {MessagingBinding} from "./internalBinding/messaging"; import {OptionsBinding} from "./internalBinding/options"; import {OSBinding} from "./internalBinding/os"; @@ -34,6 +35,7 @@ interface InternalBindingMap { config: ConfigBinding; constants: ConstantsBinding; fs: FsBinding; + fs_dir: FsDirBinding; http_parser: HttpParserBinding; messaging: MessagingBinding; options: OptionsBinding; diff --git a/typings/internalBinding/fs.d.ts b/typings/internalBinding/fs.d.ts index c3fabe7b11e9c8..c8281253eedad8 100644 --- a/typings/internalBinding/fs.d.ts +++ b/typings/internalBinding/fs.d.ts @@ -1,5 +1,18 @@ import { ConstantsBinding } from './constants'; +interface ReadFileContext { + fd: number | undefined; + isUserFd: boolean | undefined; + size: number; + callback: (err?: Error, data?: string | Uint8Array) => unknown; + buffers: Uint8Array[]; + buffer: Uint8Array; + pos: number; + encoding: string; + err: Error | null; + signal: unknown /* AbortSignal | undefined */; +} + declare namespace InternalFSBinding { class FSReqCallback { constructor(bigint?: boolean); @@ -7,19 +20,6 @@ declare namespace InternalFSBinding { context: ReadFileContext; } - interface ReadFileContext { - fd: number | undefined; - isUserFd: boolean | undefined; - size: number; - callback: (err?: Error, data?: string | Buffer) => unknown; - buffers: Buffer[]; - buffer: Buffer; - pos: number; - encoding: string; - err: Error | null; - signal: unknown /* AbortSignal | undefined */; - } - interface FSSyncContext { fd?: number; path?: string; diff --git a/typings/internalBinding/fs_dir.d.ts b/typings/internalBinding/fs_dir.d.ts new file mode 100644 index 00000000000000..1b823dc820fc18 --- /dev/null +++ b/typings/internalBinding/fs_dir.d.ts @@ -0,0 +1,21 @@ +import {InternalFSBinding, ReadFileContext} from './fs'; + +declare namespace InternalFSDirBinding { + import FSReqCallback = InternalFSBinding.FSReqCallback; + type Buffer = Uint8Array; + type StringOrBuffer = string | Buffer; + + class DirHandle { + read(encoding: string, bufferSize: number, _: unknown, ctx: ReadFileContext): string[] | undefined; + close(_: unknown, ctx: ReadFileContext): void; + } + + function opendir(path: StringOrBuffer, encoding: string, req: FSReqCallback): DirHandle; + function opendir(path: StringOrBuffer, encoding: string, _: undefined, ctx: ReadFileContext): DirHandle; + function opendirSync(path: StringOrBuffer): DirHandle; +} + +export interface FsDirBinding { + opendir: typeof InternalFSDirBinding.opendir; + opendirSync: typeof InternalFSDirBinding.opendirSync; +}