Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

typings: add fs_dir types #53631

Merged
merged 1 commit into from
Jun 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}