From 123ba0f3661102094d800a8d1b148adfaee6e26c Mon Sep 17 00:00:00 2001 From: Yagiz Nizipli Date: Fri, 28 Jun 2024 12:33:58 -0400 Subject: [PATCH] typings: add `fs_dir` types --- 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 39df64f7ec5bf4..e2721c7c480371 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"; @@ -35,6 +36,7 @@ interface InternalBindingMap { config: ConfigBinding; constants: ConstantsBinding; fs: FsBinding; + fs_dir: FsDirBinding; http_parser: HttpParserBinding; messaging: MessagingBinding; modules: ModulesBinding; diff --git a/typings/internalBinding/fs.d.ts b/typings/internalBinding/fs.d.ts index 5a4741e99fa727..05b535daf3bf26 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..362b5a4ab2d407 --- /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): number; +} + +export interface FsDirBinding { + opendir: typeof InternalFSDirBinding.opendir; + opendirSync: typeof InternalFSDirBinding.opendirSync; +}