Skip to content

Commit 2d8490f

Browse files
anonrigmarco-ippolito
authored andcommitted
typings: add fs_dir types
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]>
1 parent 662bf52 commit 2d8490f

File tree

3 files changed

+36
-13
lines changed

3 files changed

+36
-13
lines changed

typings/globals.d.ts

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {ConfigBinding} from "./internalBinding/config";
44
import {ConstantsBinding} from "./internalBinding/constants";
55
import {HttpParserBinding} from "./internalBinding/http_parser";
66
import {FsBinding} from "./internalBinding/fs";
7+
import {FsDirBinding} from "./internalBinding/fs_dir";
78
import {MessagingBinding} from "./internalBinding/messaging";
89
import {OptionsBinding} from "./internalBinding/options";
910
import {OSBinding} from "./internalBinding/os";
@@ -34,6 +35,7 @@ interface InternalBindingMap {
3435
config: ConfigBinding;
3536
constants: ConstantsBinding;
3637
fs: FsBinding;
38+
fs_dir: FsDirBinding;
3739
http_parser: HttpParserBinding;
3840
messaging: MessagingBinding;
3941
options: OptionsBinding;

typings/internalBinding/fs.d.ts

+13-13
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
import { ConstantsBinding } from './constants';
22

3+
interface ReadFileContext {
4+
fd: number | undefined;
5+
isUserFd: boolean | undefined;
6+
size: number;
7+
callback: (err?: Error, data?: string | Uint8Array) => unknown;
8+
buffers: Uint8Array[];
9+
buffer: Uint8Array;
10+
pos: number;
11+
encoding: string;
12+
err: Error | null;
13+
signal: unknown /* AbortSignal | undefined */;
14+
}
15+
316
declare namespace InternalFSBinding {
417
class FSReqCallback<ResultType = unknown> {
518
constructor(bigint?: boolean);
619
oncomplete: ((error: Error) => void) | ((error: null, result: ResultType) => void);
720
context: ReadFileContext;
821
}
922

10-
interface ReadFileContext {
11-
fd: number | undefined;
12-
isUserFd: boolean | undefined;
13-
size: number;
14-
callback: (err?: Error, data?: string | Buffer) => unknown;
15-
buffers: Buffer[];
16-
buffer: Buffer;
17-
pos: number;
18-
encoding: string;
19-
err: Error | null;
20-
signal: unknown /* AbortSignal | undefined */;
21-
}
22-
2323
interface FSSyncContext {
2424
fd?: number;
2525
path?: string;

typings/internalBinding/fs_dir.d.ts

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import {InternalFSBinding, ReadFileContext} from './fs';
2+
3+
declare namespace InternalFSDirBinding {
4+
import FSReqCallback = InternalFSBinding.FSReqCallback;
5+
type Buffer = Uint8Array;
6+
type StringOrBuffer = string | Buffer;
7+
8+
class DirHandle {
9+
read(encoding: string, bufferSize: number, _: unknown, ctx: ReadFileContext): string[] | undefined;
10+
close(_: unknown, ctx: ReadFileContext): void;
11+
}
12+
13+
function opendir(path: StringOrBuffer, encoding: string, req: FSReqCallback): DirHandle;
14+
function opendir(path: StringOrBuffer, encoding: string, _: undefined, ctx: ReadFileContext): DirHandle;
15+
function opendirSync(path: StringOrBuffer): DirHandle;
16+
}
17+
18+
export interface FsDirBinding {
19+
opendir: typeof InternalFSDirBinding.opendir;
20+
opendirSync: typeof InternalFSDirBinding.opendirSync;
21+
}

0 commit comments

Comments
 (0)