MIRROR: javascript for 馃悳's, a tiny runtime with big ambitions
1declare module 'fs' {
2 import type { Readable, Writable } from 'stream';
3
4 interface Stats {
5 size: number;
6 mode: number;
7 uid: number;
8 gid: number;
9 isFile(): boolean;
10 isDirectory(): boolean;
11 isSymbolicLink(): boolean;
12 }
13
14 type Encoding = 'utf8' | 'utf-8' | 'utf16le' | 'ucs2' | 'ucs-2' | 'latin1' | 'binary' | 'base64' | 'base64url' | 'hex' | 'ascii';
15 type WatchEventType = 'rename' | 'change';
16
17 interface FSWatcher {
18 close(): this;
19 ref(): this;
20 unref(): this;
21 on(event: 'change', listener: (eventType: WatchEventType, filename?: string) => void): this;
22 on(event: 'error', listener: (error: Error) => void): this;
23 }
24
25 interface WatchOptions {
26 persistent?: boolean;
27 recursive?: boolean;
28 encoding?: Encoding | 'buffer';
29 }
30
31 interface WatchFileOptions {
32 persistent?: boolean;
33 interval?: number;
34 }
35
36 interface ReadStream extends Readable {
37 readonly path: string;
38 readonly bytesRead: number;
39 readonly pending: boolean;
40 readonly closed: boolean;
41 readonly fd?: number | null;
42 close(callback?: () => void): this;
43 }
44
45 interface WriteStream extends Writable {
46 readonly path: string;
47 readonly bytesWritten: number;
48 readonly pending: boolean;
49 readonly closed: boolean;
50 readonly fd?: number | null;
51 close(callback?: () => void): this;
52 }
53
54 const constants: {
55 F_OK: number;
56 R_OK: number;
57 W_OK: number;
58 X_OK: number;
59 O_RDONLY: number;
60 O_WRONLY: number;
61 O_RDWR: number;
62 O_CREAT: number;
63 O_EXCL: number;
64 O_TRUNC: number;
65 O_APPEND: number;
66 };
67 const promises: typeof import('fs/promises');
68
69 function readFile(path: string | URL, encoding: Encoding): Promise<string>;
70 function readFile(path: string | URL): Promise<Uint8Array>;
71 function readFileSync(path: string | URL, encoding: Encoding | { encoding: Encoding }): string;
72 function readFileSync(path: string | URL): Uint8Array;
73 function read(
74 fd: number,
75 buffer: ArrayBufferView,
76 offset?: number,
77 length?: number,
78 position?: number | null,
79 callback?: (err: Error | null, bytesRead: number, buffer: ArrayBufferView) => void
80 ): Promise<number>;
81 function readSync(fd: number, buffer: ArrayBufferView, offset?: number, length?: number, position?: number | null): number;
82 function stream(path: string): Promise<string>;
83 function createReadStream(
84 path: string,
85 options?: {
86 fd?: number;
87 flags?: string | number;
88 mode?: number;
89 start?: number;
90 end?: number;
91 autoClose?: boolean;
92 emitClose?: boolean;
93 highWaterMark?: number;
94 }
95 ): ReadStream;
96 function createWriteStream(
97 path: string,
98 options?: {
99 fd?: number;
100 flags?: string | number;
101 mode?: number;
102 start?: number;
103 autoClose?: boolean;
104 emitClose?: boolean;
105 highWaterMark?: number;
106 }
107 ): WriteStream;
108 function open(path: string, flags?: string, mode?: number): Promise<number>;
109 function openSync(path: string, flags?: string, mode?: number): number;
110 function close(fd: number): Promise<void>;
111 function closeSync(fd: number): void;
112 function writeFile(path: string, data: string | ArrayBufferView): Promise<void>;
113 function writeFileSync(path: string, data: string | ArrayBufferView): void;
114 function write(fd: number, data: string | ArrayBufferView, offset?: number, length?: number, position?: number | null): Promise<number>;
115 function writeSync(fd: number, data: string | ArrayBufferView, offset?: number, length?: number, position?: number | null): number;
116 function writev(fd: number, buffers: ArrayBufferView[], position?: number): Promise<number>;
117 function writevSync(fd: number, buffers: ArrayBufferView[], position?: number): number;
118 function appendFileSync(path: string, data: string): void;
119 function copyFileSync(src: string, dest: string): void;
120 function renameSync(oldPath: string, newPath: string): void;
121 function rm(path: string, options?: { recursive?: boolean; force?: boolean }): Promise<void>;
122 function unlink(path: string): Promise<void>;
123 function rmSync(path: string, options?: { recursive?: boolean; force?: boolean }): void;
124 function unlinkSync(path: string): void;
125 function mkdir(path: string, options?: { recursive?: boolean; mode?: number }): Promise<void>;
126 function mkdirSync(path: string, options?: number | { recursive?: boolean; mode?: number }): void;
127 function mkdtemp(prefix: string): Promise<string>;
128 function mkdtempSync(prefix: string): string;
129 function rmdir(path: string): Promise<void>;
130 function rmdirSync(path: string): void;
131 function stat(path: string): Promise<Stats>;
132 function statSync(path: string): Stats;
133 function exists(path: string): Promise<boolean>;
134 function existsSync(path: string): boolean;
135 function access(path: string, mode?: number): Promise<void>;
136 function accessSync(path: string, mode?: number): void;
137 function chmod(path: string, mode: number | string): Promise<void>;
138 function chmodSync(path: string, mode: number | string): void;
139 function readdir(path: string): Promise<string[]>;
140 function readdirSync(path: string): string[];
141 function realpath(path: string): Promise<string>;
142 function realpathSync(path: string): string;
143 function readlink(path: string): Promise<string>;
144 function readlinkSync(path: string): string;
145 namespace realpathSync {
146 function native(path: string): string;
147 }
148 function watch(path: string, listener?: (eventType: WatchEventType, filename?: string) => void): FSWatcher;
149 function watch(
150 path: string,
151 options: WatchOptions | Encoding | 'buffer',
152 listener?: (eventType: WatchEventType, filename?: string) => void
153 ): FSWatcher;
154 function watchFile(path: string, listener: (curr: Stats, prev: Stats) => void): void;
155 function watchFile(path: string, options: WatchFileOptions, listener: (curr: Stats, prev: Stats) => void): void;
156 function unwatchFile(path: string, listener?: (curr: Stats, prev: Stats) => void): void;
157 const FSWatcher: {
158 prototype: FSWatcher;
159 };
160 const ReadStream: {
161 prototype: ReadStream;
162 new (
163 path: string,
164 options?: {
165 fd?: number;
166 flags?: string | number;
167 mode?: number;
168 start?: number;
169 end?: number;
170 autoClose?: boolean;
171 emitClose?: boolean;
172 highWaterMark?: number;
173 }
174 ): ReadStream;
175 };
176 const WriteStream: {
177 prototype: WriteStream;
178 new (
179 path: string,
180 options?: {
181 fd?: number;
182 flags?: string | number;
183 mode?: number;
184 start?: number;
185 autoClose?: boolean;
186 emitClose?: boolean;
187 highWaterMark?: number;
188 }
189 ): WriteStream;
190 };
191}
192
193declare module 'ant:fs' {
194 export * from 'fs';
195}
196
197declare module 'node:fs' {
198 export * from 'fs';
199}
200
201declare module 'fs/promises' {
202 interface FileHandle {
203 readonly fd: number;
204 close(): Promise<void>;
205 stat(): Promise<Stats>;
206 sync(): Promise<void>;
207 read(
208 buffer: ArrayBufferView,
209 offset?: number,
210 length?: number,
211 position?: number | null
212 ): Promise<{ bytesRead: number; buffer: ArrayBufferView }>;
213 write(
214 data: string | ArrayBufferView,
215 offsetOrOptions?: number | { offset?: number; length?: number; position?: number | null },
216 length?: number,
217 position?: number | null
218 ): Promise<{ bytesWritten: number; buffer: string | ArrayBufferView }>;
219 writeFile(data: string | ArrayBufferView): Promise<void>;
220 }
221
222 interface Stats {
223 size: number;
224 mode: number;
225 uid: number;
226 gid: number;
227 isFile(): boolean;
228 isDirectory(): boolean;
229 isSymbolicLink(): boolean;
230 }
231
232 type Encoding = 'utf8' | 'utf-8' | 'utf16le' | 'ucs2' | 'ucs-2' | 'latin1' | 'binary' | 'base64' | 'base64url' | 'hex' | 'ascii';
233
234 const constants: {
235 F_OK: number;
236 R_OK: number;
237 W_OK: number;
238 X_OK: number;
239 O_RDONLY: number;
240 O_WRONLY: number;
241 O_RDWR: number;
242 O_CREAT: number;
243 O_EXCL: number;
244 O_TRUNC: number;
245 O_APPEND: number;
246 };
247
248 function readFile(path: string | URL, encoding: Encoding): Promise<string>;
249 function readFile(path: string | URL): Promise<Uint8Array>;
250 function open(path: string, flags?: string, mode?: number): Promise<FileHandle>;
251 function close(fd: number): Promise<void>;
252 function writeFile(path: string, data: string | ArrayBufferView): Promise<void>;
253 function write(fd: number, data: string | ArrayBufferView, offset?: number, length?: number, position?: number | null): Promise<number>;
254 function writev(fd: number, buffers: ArrayBufferView[], position?: number): Promise<number>;
255 function rm(path: string, options?: { recursive?: boolean; force?: boolean }): Promise<void>;
256 function unlink(path: string): Promise<void>;
257 function mkdir(path: string, options?: { recursive?: boolean; mode?: number }): Promise<void>;
258 function rmdir(path: string): Promise<void>;
259 function stat(path: string): Promise<Stats>;
260 function exists(path: string): Promise<boolean>;
261 function access(path: string, mode?: number): Promise<void>;
262 function chmod(path: string, mode: number | string): Promise<void>;
263 function readdir(path: string): Promise<string[]>;
264 function realpath(path: string): Promise<string>;
265 function readlink(path: string): Promise<string>;
266}
267
268declare module 'ant:fs/promises' {
269 export * from 'fs/promises';
270}
271
272declare module 'node:fs/promises' {
273 export * from 'fs/promises';
274}