Skip to content

Commit

Permalink
typings: add fs_dir types
Browse files Browse the repository at this point in the history
PR-URL: #53631
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: Vinícius Lourenço Claro Cardoso <[email protected]>
Reviewed-By: Chemi Atlow <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
anonrig authored and aduh95 committed Jul 16, 2024
1 parent bac2867 commit 0e25fae
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 13 deletions.
2 changes: 2 additions & 0 deletions typings/globals.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -35,6 +36,7 @@ interface InternalBindingMap {
config: ConfigBinding;
constants: ConstantsBinding;
fs: FsBinding;
fs_dir: FsDirBinding;
http_parser: HttpParserBinding;
messaging: MessagingBinding;
modules: ModulesBinding;
Expand Down
26 changes: 13 additions & 13 deletions typings/internalBinding/fs.d.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
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<ResultType = unknown> {
constructor(bigint?: boolean);
oncomplete: ((error: Error) => void) | ((error: null, result: ResultType) => void);
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;
Expand Down
21 changes: 21 additions & 0 deletions typings/internalBinding/fs_dir.d.ts
Original file line number Diff line number Diff line change
@@ -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;
}

0 comments on commit 0e25fae

Please sign in to comment.