UNPKG

139 kBTypeScriptView Raw
1declare module 'fs' {
2 import * as stream from 'stream';
3 import EventEmitter = require('events');
4 import { URL } from 'url';
5
6 /**
7 * Valid types for path values in "fs".
8 */
9 type PathLike = string | Buffer | URL;
10
11 type NoParamCallback = (err: NodeJS.ErrnoException | null) => void;
12
13 interface StatsBase<T> {
14 isFile(): boolean;
15 isDirectory(): boolean;
16 isBlockDevice(): boolean;
17 isCharacterDevice(): boolean;
18 isSymbolicLink(): boolean;
19 isFIFO(): boolean;
20 isSocket(): boolean;
21
22 dev: T;
23 ino: T;
24 mode: T;
25 nlink: T;
26 uid: T;
27 gid: T;
28 rdev: T;
29 size: T;
30 blksize: T;
31 blocks: T;
32 atimeMs: T;
33 mtimeMs: T;
34 ctimeMs: T;
35 birthtimeMs: T;
36 atime: Date;
37 mtime: Date;
38 ctime: Date;
39 birthtime: Date;
40 }
41
42 interface Stats extends StatsBase<number> {
43 }
44
45 class Stats {
46 }
47
48 class Dirent {
49 isFile(): boolean;
50 isDirectory(): boolean;
51 isBlockDevice(): boolean;
52 isCharacterDevice(): boolean;
53 isSymbolicLink(): boolean;
54 isFIFO(): boolean;
55 isSocket(): boolean;
56 name: string;
57 }
58
59 /**
60 * A class representing a directory stream.
61 */
62 class Dir {
63 readonly path: string;
64
65 /**
66 * Asynchronously iterates over the directory via `readdir(3)` until all entries have been read.
67 */
68 [Symbol.asyncIterator](): AsyncIterableIterator<Dirent>;
69
70 /**
71 * Asynchronously close the directory's underlying resource handle.
72 * Subsequent reads will result in errors.
73 */
74 close(): Promise<void>;
75 close(cb: NoParamCallback): void;
76
77 /**
78 * Synchronously close the directory's underlying resource handle.
79 * Subsequent reads will result in errors.
80 */
81 closeSync(): void;
82
83 /**
84 * Asynchronously read the next directory entry via `readdir(3)` as an `Dirent`.
85 * After the read is completed, a value is returned that will be resolved with an `Dirent`, or `null` if there are no more directory entries to read.
86 * Directory entries returned by this function are in no particular order as provided by the operating system's underlying directory mechanisms.
87 */
88 read(): Promise<Dirent | null>;
89 read(cb: (err: NodeJS.ErrnoException | null, dirEnt: Dirent | null) => void): void;
90
91 /**
92 * Synchronously read the next directory entry via `readdir(3)` as a `Dirent`.
93 * If there are no more directory entries to read, null will be returned.
94 * Directory entries returned by this function are in no particular order as provided by the operating system's underlying directory mechanisms.
95 */
96 readSync(): Dirent;
97 }
98
99 interface FSWatcher extends EventEmitter {
100 close(): void;
101
102 /**
103 * events.EventEmitter
104 * 1. change
105 * 2. error
106 */
107 addListener(event: string, listener: (...args: any[]) => void): this;
108 addListener(event: "change", listener: (eventType: string, filename: string | Buffer) => void): this;
109 addListener(event: "error", listener: (error: Error) => void): this;
110 addListener(event: "close", listener: () => void): this;
111
112 on(event: string, listener: (...args: any[]) => void): this;
113 on(event: "change", listener: (eventType: string, filename: string | Buffer) => void): this;
114 on(event: "error", listener: (error: Error) => void): this;
115 on(event: "close", listener: () => void): this;
116
117 once(event: string, listener: (...args: any[]) => void): this;
118 once(event: "change", listener: (eventType: string, filename: string | Buffer) => void): this;
119 once(event: "error", listener: (error: Error) => void): this;
120 once(event: "close", listener: () => void): this;
121
122 prependListener(event: string, listener: (...args: any[]) => void): this;
123 prependListener(event: "change", listener: (eventType: string, filename: string | Buffer) => void): this;
124 prependListener(event: "error", listener: (error: Error) => void): this;
125 prependListener(event: "close", listener: () => void): this;
126
127 prependOnceListener(event: string, listener: (...args: any[]) => void): this;
128 prependOnceListener(event: "change", listener: (eventType: string, filename: string | Buffer) => void): this;
129 prependOnceListener(event: "error", listener: (error: Error) => void): this;
130 prependOnceListener(event: "close", listener: () => void): this;
131 }
132
133 class ReadStream extends stream.Readable {
134 close(callback?: (err?: NodeJS.ErrnoException | null) => void): void;
135 bytesRead: number;
136 path: string | Buffer;
137
138 /**
139 * events.EventEmitter
140 * 1. open
141 * 2. close
142 */
143 addListener(event: string, listener: (...args: any[]) => void): this;
144 addListener(event: "open", listener: (fd: number) => void): this;
145 addListener(event: "close", listener: () => void): this;
146
147 on(event: string, listener: (...args: any[]) => void): this;
148 on(event: "open", listener: (fd: number) => void): this;
149 on(event: "close", listener: () => void): this;
150
151 once(event: string, listener: (...args: any[]) => void): this;
152 once(event: "open", listener: (fd: number) => void): this;
153 once(event: "close", listener: () => void): this;
154
155 prependListener(event: string, listener: (...args: any[]) => void): this;
156 prependListener(event: "open", listener: (fd: number) => void): this;
157 prependListener(event: "close", listener: () => void): this;
158
159 prependOnceListener(event: string, listener: (...args: any[]) => void): this;
160 prependOnceListener(event: "open", listener: (fd: number) => void): this;
161 prependOnceListener(event: "close", listener: () => void): this;
162 }
163
164 class WriteStream extends stream.Writable {
165 close(callback?: (err?: NodeJS.ErrnoException | null) => void): void;
166 bytesWritten: number;
167 path: string | Buffer;
168
169 /**
170 * events.EventEmitter
171 * 1. open
172 * 2. close
173 */
174 addListener(event: string, listener: (...args: any[]) => void): this;
175 addListener(event: "open", listener: (fd: number) => void): this;
176 addListener(event: "close", listener: () => void): this;
177
178 on(event: string, listener: (...args: any[]) => void): this;
179 on(event: "open", listener: (fd: number) => void): this;
180 on(event: "close", listener: () => void): this;
181
182 once(event: string, listener: (...args: any[]) => void): this;
183 once(event: "open", listener: (fd: number) => void): this;
184 once(event: "close", listener: () => void): this;
185
186 prependListener(event: string, listener: (...args: any[]) => void): this;
187 prependListener(event: "open", listener: (fd: number) => void): this;
188 prependListener(event: "close", listener: () => void): this;
189
190 prependOnceListener(event: string, listener: (...args: any[]) => void): this;
191 prependOnceListener(event: "open", listener: (fd: number) => void): this;
192 prependOnceListener(event: "close", listener: () => void): this;
193 }
194
195 /**
196 * Asynchronous rename(2) - Change the name or location of a file or directory.
197 * @param oldPath A path to a file. If a URL is provided, it must use the `file:` protocol.
198 * URL support is _experimental_.
199 * @param newPath A path to a file. If a URL is provided, it must use the `file:` protocol.
200 * URL support is _experimental_.
201 */
202 function rename(oldPath: PathLike, newPath: PathLike, callback: NoParamCallback): void;
203
204 // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
205 namespace rename {
206 /**
207 * Asynchronous rename(2) - Change the name or location of a file or directory.
208 * @param oldPath A path to a file. If a URL is provided, it must use the `file:` protocol.
209 * URL support is _experimental_.
210 * @param newPath A path to a file. If a URL is provided, it must use the `file:` protocol.
211 * URL support is _experimental_.
212 */
213 function __promisify__(oldPath: PathLike, newPath: PathLike): Promise<void>;
214 }
215
216 /**
217 * Synchronous rename(2) - Change the name or location of a file or directory.
218 * @param oldPath A path to a file. If a URL is provided, it must use the `file:` protocol.
219 * URL support is _experimental_.
220 * @param newPath A path to a file. If a URL is provided, it must use the `file:` protocol.
221 * URL support is _experimental_.
222 */
223 function renameSync(oldPath: PathLike, newPath: PathLike): void;
224
225 /**
226 * Asynchronous truncate(2) - Truncate a file to a specified length.
227 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
228 * @param len If not specified, defaults to `0`.
229 */
230 function truncate(path: PathLike, len: number | undefined | null, callback: NoParamCallback): void;
231
232 /**
233 * Asynchronous truncate(2) - Truncate a file to a specified length.
234 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
235 * URL support is _experimental_.
236 */
237 function truncate(path: PathLike, callback: NoParamCallback): void;
238
239 // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
240 namespace truncate {
241 /**
242 * Asynchronous truncate(2) - Truncate a file to a specified length.
243 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
244 * @param len If not specified, defaults to `0`.
245 */
246 function __promisify__(path: PathLike, len?: number | null): Promise<void>;
247 }
248
249 /**
250 * Synchronous truncate(2) - Truncate a file to a specified length.
251 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
252 * @param len If not specified, defaults to `0`.
253 */
254 function truncateSync(path: PathLike, len?: number | null): void;
255
256 /**
257 * Asynchronous ftruncate(2) - Truncate a file to a specified length.
258 * @param fd A file descriptor.
259 * @param len If not specified, defaults to `0`.
260 */
261 function ftruncate(fd: number, len: number | undefined | null, callback: NoParamCallback): void;
262
263 /**
264 * Asynchronous ftruncate(2) - Truncate a file to a specified length.
265 * @param fd A file descriptor.
266 */
267 function ftruncate(fd: number, callback: NoParamCallback): void;
268
269 // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
270 namespace ftruncate {
271 /**
272 * Asynchronous ftruncate(2) - Truncate a file to a specified length.
273 * @param fd A file descriptor.
274 * @param len If not specified, defaults to `0`.
275 */
276 function __promisify__(fd: number, len?: number | null): Promise<void>;
277 }
278
279 /**
280 * Synchronous ftruncate(2) - Truncate a file to a specified length.
281 * @param fd A file descriptor.
282 * @param len If not specified, defaults to `0`.
283 */
284 function ftruncateSync(fd: number, len?: number | null): void;
285
286 /**
287 * Asynchronous chown(2) - Change ownership of a file.
288 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
289 */
290 function chown(path: PathLike, uid: number, gid: number, callback: NoParamCallback): void;
291
292 // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
293 namespace chown {
294 /**
295 * Asynchronous chown(2) - Change ownership of a file.
296 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
297 */
298 function __promisify__(path: PathLike, uid: number, gid: number): Promise<void>;
299 }
300
301 /**
302 * Synchronous chown(2) - Change ownership of a file.
303 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
304 */
305 function chownSync(path: PathLike, uid: number, gid: number): void;
306
307 /**
308 * Asynchronous fchown(2) - Change ownership of a file.
309 * @param fd A file descriptor.
310 */
311 function fchown(fd: number, uid: number, gid: number, callback: NoParamCallback): void;
312
313 // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
314 namespace fchown {
315 /**
316 * Asynchronous fchown(2) - Change ownership of a file.
317 * @param fd A file descriptor.
318 */
319 function __promisify__(fd: number, uid: number, gid: number): Promise<void>;
320 }
321
322 /**
323 * Synchronous fchown(2) - Change ownership of a file.
324 * @param fd A file descriptor.
325 */
326 function fchownSync(fd: number, uid: number, gid: number): void;
327
328 /**
329 * Asynchronous lchown(2) - Change ownership of a file. Does not dereference symbolic links.
330 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
331 */
332 function lchown(path: PathLike, uid: number, gid: number, callback: NoParamCallback): void;
333
334 // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
335 namespace lchown {
336 /**
337 * Asynchronous lchown(2) - Change ownership of a file. Does not dereference symbolic links.
338 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
339 */
340 function __promisify__(path: PathLike, uid: number, gid: number): Promise<void>;
341 }
342
343 /**
344 * Synchronous lchown(2) - Change ownership of a file. Does not dereference symbolic links.
345 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
346 */
347 function lchownSync(path: PathLike, uid: number, gid: number): void;
348
349 /**
350 * Changes the access and modification times of a file in the same way as `fs.utimes()`,
351 * with the difference that if the path refers to a symbolic link, then the link is not
352 * dereferenced: instead, the timestamps of the symbolic link itself are changed.
353 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
354 * @param atime The last access time. If a string is provided, it will be coerced to number.
355 * @param mtime The last modified time. If a string is provided, it will be coerced to number.
356 */
357 function lutimes(path: PathLike, atime: string | number | Date, mtime: string | number | Date, callback: NoParamCallback): void;
358
359 // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
360 namespace lutimes {
361 /**
362 * Changes the access and modification times of a file in the same way as `fsPromises.utimes()`,
363 * with the difference that if the path refers to a symbolic link, then the link is not
364 * dereferenced: instead, the timestamps of the symbolic link itself are changed.
365 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
366 * @param atime The last access time. If a string is provided, it will be coerced to number.
367 * @param mtime The last modified time. If a string is provided, it will be coerced to number.
368 */
369 function __promisify__(path: PathLike, atime: string | number | Date, mtime: string | number | Date): Promise<void>;
370 }
371
372 /**
373 * Change the file system timestamps of the symbolic link referenced by `path`. Returns `undefined`,
374 * or throws an exception when parameters are incorrect or the operation fails.
375 * This is the synchronous version of `fs.lutimes()`.
376 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
377 * @param atime The last access time. If a string is provided, it will be coerced to number.
378 * @param mtime The last modified time. If a string is provided, it will be coerced to number.
379 */
380 function lutimesSync(path: PathLike, atime: string | number | Date, mtime: string | number | Date): void;
381
382 /**
383 * Asynchronous chmod(2) - Change permissions of a file.
384 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
385 * @param mode A file mode. If a string is passed, it is parsed as an octal integer.
386 */
387 function chmod(path: PathLike, mode: string | number, callback: NoParamCallback): void;
388
389 // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
390 namespace chmod {
391 /**
392 * Asynchronous chmod(2) - Change permissions of a file.
393 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
394 * @param mode A file mode. If a string is passed, it is parsed as an octal integer.
395 */
396 function __promisify__(path: PathLike, mode: string | number): Promise<void>;
397 }
398
399 /**
400 * Synchronous chmod(2) - Change permissions of a file.
401 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
402 * @param mode A file mode. If a string is passed, it is parsed as an octal integer.
403 */
404 function chmodSync(path: PathLike, mode: string | number): void;
405
406 /**
407 * Asynchronous fchmod(2) - Change permissions of a file.
408 * @param fd A file descriptor.
409 * @param mode A file mode. If a string is passed, it is parsed as an octal integer.
410 */
411 function fchmod(fd: number, mode: string | number, callback: NoParamCallback): void;
412
413 // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
414 namespace fchmod {
415 /**
416 * Asynchronous fchmod(2) - Change permissions of a file.
417 * @param fd A file descriptor.
418 * @param mode A file mode. If a string is passed, it is parsed as an octal integer.
419 */
420 function __promisify__(fd: number, mode: string | number): Promise<void>;
421 }
422
423 /**
424 * Synchronous fchmod(2) - Change permissions of a file.
425 * @param fd A file descriptor.
426 * @param mode A file mode. If a string is passed, it is parsed as an octal integer.
427 */
428 function fchmodSync(fd: number, mode: string | number): void;
429
430 /**
431 * Asynchronous lchmod(2) - Change permissions of a file. Does not dereference symbolic links.
432 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
433 * @param mode A file mode. If a string is passed, it is parsed as an octal integer.
434 */
435 function lchmod(path: PathLike, mode: string | number, callback: NoParamCallback): void;
436
437 // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
438 namespace lchmod {
439 /**
440 * Asynchronous lchmod(2) - Change permissions of a file. Does not dereference symbolic links.
441 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
442 * @param mode A file mode. If a string is passed, it is parsed as an octal integer.
443 */
444 function __promisify__(path: PathLike, mode: string | number): Promise<void>;
445 }
446
447 /**
448 * Synchronous lchmod(2) - Change permissions of a file. Does not dereference symbolic links.
449 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
450 * @param mode A file mode. If a string is passed, it is parsed as an octal integer.
451 */
452 function lchmodSync(path: PathLike, mode: string | number): void;
453
454 /**
455 * Asynchronous stat(2) - Get file status.
456 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
457 */
458 function stat(path: PathLike, callback: (err: NodeJS.ErrnoException | null, stats: Stats) => void): void;
459 function stat(path: PathLike, options: StatOptions & { bigint?: false | undefined } | undefined, callback: (err: NodeJS.ErrnoException | null, stats: Stats) => void): void;
460 function stat(path: PathLike, options: StatOptions & { bigint: true }, callback: (err: NodeJS.ErrnoException | null, stats: BigIntStats) => void): void;
461 function stat(path: PathLike, options: StatOptions | undefined, callback: (err: NodeJS.ErrnoException | null, stats: Stats | BigIntStats) => void): void;
462
463 // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
464 namespace stat {
465 /**
466 * Asynchronous stat(2) - Get file status.
467 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
468 */
469 function __promisify__(path: PathLike, options?: StatOptions & { bigint?: false | undefined }): Promise<Stats>;
470 function __promisify__(path: PathLike, options: StatOptions & { bigint: true }): Promise<BigIntStats>;
471 function __promisify__(path: PathLike, options?: StatOptions): Promise<Stats | BigIntStats>;
472 }
473
474 /**
475 * Synchronous stat(2) - Get file status.
476 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
477 */
478 function statSync(path: PathLike, options?: StatOptions & { bigint?: false | undefined }): Stats;
479 function statSync(path: PathLike, options: StatOptions & { bigint: true }): BigIntStats;
480 function statSync(path: PathLike, options?: StatOptions): Stats | BigIntStats;
481
482 // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
483 namespace fstat {
484 /**
485 * Asynchronous fstat(2) - Get file status.
486 * @param fd A file descriptor.
487 */
488 function __promisify__(fd: number, options?: StatOptions & { bigint?: false | undefined }): Promise<Stats>;
489 function __promisify__(fd: number, options: StatOptions & { bigint: true }): Promise<BigIntStats>;
490 function __promisify__(fd: number, options?: StatOptions): Promise<Stats | BigIntStats>;
491 }
492
493 /**
494 * Synchronous fstat(2) - Get file status.
495 * @param fd A file descriptor.
496 */
497 function fstatSync(fd: number, options?: StatOptions & { bigint?: false | undefined }): Stats;
498 function fstatSync(fd: number, options: StatOptions & { bigint: true }): BigIntStats;
499 function fstatSync(fd: number, options?: StatOptions): Stats | BigIntStats;
500
501 /**
502 * Asynchronous lstat(2) - Get file status. Does not dereference symbolic links.
503 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
504 */
505 function lstat(path: PathLike, callback: (err: NodeJS.ErrnoException | null, stats: Stats) => void): void;
506 function lstat(path: PathLike, options: StatOptions & { bigint?: false | undefined } | undefined, callback: (err: NodeJS.ErrnoException | null, stats: Stats) => void): void;
507 function lstat(path: PathLike, options: StatOptions & { bigint: true }, callback: (err: NodeJS.ErrnoException | null, stats: BigIntStats) => void): void;
508 function lstat(path: PathLike, options: StatOptions | undefined, callback: (err: NodeJS.ErrnoException | null, stats: Stats | BigIntStats) => void): void;
509
510 // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
511 namespace lstat {
512 /**
513 * Asynchronous lstat(2) - Get file status. Does not dereference symbolic links.
514 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
515 */
516 function __promisify__(path: PathLike, options?: StatOptions & { bigint?: false | undefined }): Promise<Stats>;
517 function __promisify__(path: PathLike, options: StatOptions & { bigint: true }): Promise<BigIntStats>;
518 function __promisify__(path: PathLike, options?: StatOptions): Promise<Stats | BigIntStats>;
519 }
520
521 /**
522 * Synchronous lstat(2) - Get file status. Does not dereference symbolic links.
523 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
524 */
525 function lstatSync(path: PathLike, options?: StatOptions & { bigint?: false | undefined }): Stats;
526 function lstatSync(path: PathLike, options: StatOptions & { bigint: true }): BigIntStats;
527 function lstatSync(path: PathLike, options?: StatOptions): Stats | BigIntStats;
528
529 /**
530 * Asynchronous link(2) - Create a new link (also known as a hard link) to an existing file.
531 * @param existingPath A path to a file. If a URL is provided, it must use the `file:` protocol.
532 * @param newPath A path to a file. If a URL is provided, it must use the `file:` protocol.
533 */
534 function link(existingPath: PathLike, newPath: PathLike, callback: NoParamCallback): void;
535
536 // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
537 namespace link {
538 /**
539 * Asynchronous link(2) - Create a new link (also known as a hard link) to an existing file.
540 * @param existingPath A path to a file. If a URL is provided, it must use the `file:` protocol.
541 * @param newPath A path to a file. If a URL is provided, it must use the `file:` protocol.
542 */
543 function __promisify__(existingPath: PathLike, newPath: PathLike): Promise<void>;
544 }
545
546 /**
547 * Synchronous link(2) - Create a new link (also known as a hard link) to an existing file.
548 * @param existingPath A path to a file. If a URL is provided, it must use the `file:` protocol.
549 * @param newPath A path to a file. If a URL is provided, it must use the `file:` protocol.
550 */
551 function linkSync(existingPath: PathLike, newPath: PathLike): void;
552
553 /**
554 * Asynchronous symlink(2) - Create a new symbolic link to an existing file.
555 * @param target A path to an existing file. If a URL is provided, it must use the `file:` protocol.
556 * @param path A path to the new symlink. If a URL is provided, it must use the `file:` protocol.
557 * @param type May be set to `'dir'`, `'file'`, or `'junction'` (default is `'file'`) and is only available on Windows (ignored on other platforms).
558 * When using `'junction'`, the `target` argument will automatically be normalized to an absolute path.
559 */
560 function symlink(target: PathLike, path: PathLike, type: symlink.Type | undefined | null, callback: NoParamCallback): void;
561
562 /**
563 * Asynchronous symlink(2) - Create a new symbolic link to an existing file.
564 * @param target A path to an existing file. If a URL is provided, it must use the `file:` protocol.
565 * @param path A path to the new symlink. If a URL is provided, it must use the `file:` protocol.
566 */
567 function symlink(target: PathLike, path: PathLike, callback: NoParamCallback): void;
568
569 // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
570 namespace symlink {
571 /**
572 * Asynchronous symlink(2) - Create a new symbolic link to an existing file.
573 * @param target A path to an existing file. If a URL is provided, it must use the `file:` protocol.
574 * @param path A path to the new symlink. If a URL is provided, it must use the `file:` protocol.
575 * @param type May be set to `'dir'`, `'file'`, or `'junction'` (default is `'file'`) and is only available on Windows (ignored on other platforms).
576 * When using `'junction'`, the `target` argument will automatically be normalized to an absolute path.
577 */
578 function __promisify__(target: PathLike, path: PathLike, type?: string | null): Promise<void>;
579
580 type Type = "dir" | "file" | "junction";
581 }
582
583 /**
584 * Synchronous symlink(2) - Create a new symbolic link to an existing file.
585 * @param target A path to an existing file. If a URL is provided, it must use the `file:` protocol.
586 * @param path A path to the new symlink. If a URL is provided, it must use the `file:` protocol.
587 * @param type May be set to `'dir'`, `'file'`, or `'junction'` (default is `'file'`) and is only available on Windows (ignored on other platforms).
588 * When using `'junction'`, the `target` argument will automatically be normalized to an absolute path.
589 */
590 function symlinkSync(target: PathLike, path: PathLike, type?: symlink.Type | null): void;
591
592 /**
593 * Asynchronous readlink(2) - read value of a symbolic link.
594 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
595 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
596 */
597 function readlink(
598 path: PathLike,
599 options: { encoding?: BufferEncoding | null | undefined } | BufferEncoding | undefined | null,
600 callback: (err: NodeJS.ErrnoException | null, linkString: string) => void
601 ): void;
602
603 /**
604 * Asynchronous readlink(2) - read value of a symbolic link.
605 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
606 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
607 */
608 function readlink(path: PathLike, options: { encoding: "buffer" } | "buffer", callback: (err: NodeJS.ErrnoException | null, linkString: Buffer) => void): void;
609
610 /**
611 * Asynchronous readlink(2) - read value of a symbolic link.
612 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
613 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
614 */
615 function readlink(
616 path: PathLike,
617 options: { encoding?: string | null | undefined } | string | undefined | null,
618 callback: (err: NodeJS.ErrnoException | null, linkString: string | Buffer) => void
619 ): void;
620
621 /**
622 * Asynchronous readlink(2) - read value of a symbolic link.
623 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
624 */
625 function readlink(path: PathLike, callback: (err: NodeJS.ErrnoException | null, linkString: string) => void): void;
626
627 // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
628 namespace readlink {
629 /**
630 * Asynchronous readlink(2) - read value of a symbolic link.
631 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
632 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
633 */
634 function __promisify__(path: PathLike, options?: { encoding?: BufferEncoding | null | undefined } | BufferEncoding | null): Promise<string>;
635
636 /**
637 * Asynchronous readlink(2) - read value of a symbolic link.
638 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
639 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
640 */
641 function __promisify__(path: PathLike, options: { encoding: "buffer" } | "buffer"): Promise<Buffer>;
642
643 /**
644 * Asynchronous readlink(2) - read value of a symbolic link.
645 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
646 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
647 */
648 function __promisify__(path: PathLike, options?: { encoding?: string | null | undefined } | string | null): Promise<string | Buffer>;
649 }
650
651 /**
652 * Synchronous readlink(2) - read value of a symbolic link.
653 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
654 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
655 */
656 function readlinkSync(path: PathLike, options?: { encoding?: BufferEncoding | null | undefined } | BufferEncoding | null): string;
657
658 /**
659 * Synchronous readlink(2) - read value of a symbolic link.
660 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
661 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
662 */
663 function readlinkSync(path: PathLike, options: { encoding: "buffer" } | "buffer"): Buffer;
664
665 /**
666 * Synchronous readlink(2) - read value of a symbolic link.
667 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
668 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
669 */
670 function readlinkSync(path: PathLike, options?: { encoding?: string | null | undefined } | string | null): string | Buffer;
671
672 /**
673 * Asynchronous realpath(3) - return the canonicalized absolute pathname.
674 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
675 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
676 */
677 function realpath(
678 path: PathLike,
679 options: { encoding?: BufferEncoding | null | undefined } | BufferEncoding | undefined | null,
680 callback: (err: NodeJS.ErrnoException | null, resolvedPath: string) => void
681 ): void;
682
683 /**
684 * Asynchronous realpath(3) - return the canonicalized absolute pathname.
685 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
686 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
687 */
688 function realpath(path: PathLike, options: { encoding: "buffer" } | "buffer", callback: (err: NodeJS.ErrnoException | null, resolvedPath: Buffer) => void): void;
689
690 /**
691 * Asynchronous realpath(3) - return the canonicalized absolute pathname.
692 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
693 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
694 */
695 function realpath(
696 path: PathLike,
697 options: { encoding?: string | null | undefined } | string | undefined | null,
698 callback: (err: NodeJS.ErrnoException | null, resolvedPath: string | Buffer) => void
699 ): void;
700
701 /**
702 * Asynchronous realpath(3) - return the canonicalized absolute pathname.
703 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
704 */
705 function realpath(path: PathLike, callback: (err: NodeJS.ErrnoException | null, resolvedPath: string) => void): void;
706
707 // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
708 namespace realpath {
709 /**
710 * Asynchronous realpath(3) - return the canonicalized absolute pathname.
711 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
712 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
713 */
714 function __promisify__(path: PathLike, options?: { encoding?: BufferEncoding | null | undefined } | BufferEncoding | null): Promise<string>;
715
716 /**
717 * Asynchronous realpath(3) - return the canonicalized absolute pathname.
718 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
719 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
720 */
721 function __promisify__(path: PathLike, options: { encoding: "buffer" } | "buffer"): Promise<Buffer>;
722
723 /**
724 * Asynchronous realpath(3) - return the canonicalized absolute pathname.
725 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
726 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
727 */
728 function __promisify__(path: PathLike, options?: { encoding?: string | null | undefined } | string | null): Promise<string | Buffer>;
729
730 function native(
731 path: PathLike,
732 options: { encoding?: BufferEncoding | null | undefined } | BufferEncoding | undefined | null,
733 callback: (err: NodeJS.ErrnoException | null, resolvedPath: string) => void
734 ): void;
735 function native(path: PathLike, options: { encoding: "buffer" } | "buffer", callback: (err: NodeJS.ErrnoException | null, resolvedPath: Buffer) => void): void;
736 function native(
737 path: PathLike,
738 options: { encoding?: string | null | undefined } | string | undefined | null,
739 callback: (err: NodeJS.ErrnoException | null, resolvedPath: string | Buffer) => void
740 ): void;
741 function native(path: PathLike, callback: (err: NodeJS.ErrnoException | null, resolvedPath: string) => void): void;
742 }
743
744 /**
745 * Synchronous realpath(3) - return the canonicalized absolute pathname.
746 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
747 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
748 */
749 function realpathSync(path: PathLike, options?: { encoding?: BufferEncoding | null | undefined } | BufferEncoding | null): string;
750
751 /**
752 * Synchronous realpath(3) - return the canonicalized absolute pathname.
753 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
754 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
755 */
756 function realpathSync(path: PathLike, options: { encoding: "buffer" } | "buffer"): Buffer;
757
758 /**
759 * Synchronous realpath(3) - return the canonicalized absolute pathname.
760 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
761 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
762 */
763 function realpathSync(path: PathLike, options?: { encoding?: string | null | undefined } | string | null): string | Buffer;
764
765 namespace realpathSync {
766 function native(path: PathLike, options?: { encoding?: BufferEncoding | null | undefined } | BufferEncoding | null): string;
767 function native(path: PathLike, options: { encoding: "buffer" } | "buffer"): Buffer;
768 function native(path: PathLike, options?: { encoding?: string | null | undefined } | string | null): string | Buffer;
769 }
770
771 /**
772 * Asynchronous unlink(2) - delete a name and possibly the file it refers to.
773 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
774 */
775 function unlink(path: PathLike, callback: NoParamCallback): void;
776
777 // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
778 namespace unlink {
779 /**
780 * Asynchronous unlink(2) - delete a name and possibly the file it refers to.
781 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
782 */
783 function __promisify__(path: PathLike): Promise<void>;
784 }
785
786 /**
787 * Synchronous unlink(2) - delete a name and possibly the file it refers to.
788 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
789 */
790 function unlinkSync(path: PathLike): void;
791
792 interface RmDirOptions {
793 /**
794 * If an `EBUSY`, `ENOTEMPTY`, or `EPERM` error is
795 * encountered, Node.js will retry the operation with a linear backoff wait of
796 * 100ms longer on each try. This option represents the number of retries. This
797 * option is ignored if the `recursive` option is not `true`.
798 * @default 3
799 */
800 maxRetries?: number | undefined;
801 /**
802 * If `true`, perform a recursive directory removal. In
803 * recursive mode, errors are not reported if `path` does not exist, and
804 * operations are retried on failure.
805 * @experimental
806 * @default false
807 */
808 recursive?: boolean | undefined;
809 /**
810 * If an `EMFILE` error is encountered, Node.js will
811 * retry the operation with a linear backoff of 1ms longer on each try until the
812 * timeout duration passes this limit. This option is ignored if the `recursive`
813 * option is not `true`.
814 * @default 1000
815 */
816 emfileWait?: number | undefined;
817 }
818
819 /**
820 * Asynchronous rmdir(2) - delete a directory.
821 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
822 */
823 function rmdir(path: PathLike, callback: NoParamCallback): void;
824 function rmdir(path: PathLike, options: RmDirOptions, callback: NoParamCallback): void;
825
826 // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
827 namespace rmdir {
828 /**
829 * Asynchronous rmdir(2) - delete a directory.
830 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
831 */
832 function __promisify__(path: PathLike, options?: RmDirOptions): Promise<void>;
833 }
834
835 /**
836 * Synchronous rmdir(2) - delete a directory.
837 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
838 */
839 function rmdirSync(path: PathLike, options?: RmDirOptions): void;
840
841 interface MakeDirectoryOptions {
842 /**
843 * Indicates whether parent folders should be created.
844 * @default false
845 */
846 recursive?: boolean | undefined;
847 /**
848 * A file mode. If a string is passed, it is parsed as an octal integer. If not specified
849 * @default 0o777.
850 */
851 mode?: number | string | undefined;
852 }
853
854 /**
855 * Asynchronous mkdir(2) - create a directory.
856 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
857 * @param options Either the file mode, or an object optionally specifying the file mode and whether parent folders
858 * should be created. If a string is passed, it is parsed as an octal integer. If not specified, defaults to `0o777`.
859 */
860 function mkdir(path: PathLike, options: number | string | MakeDirectoryOptions | undefined | null, callback: NoParamCallback): void;
861
862 /**
863 * Asynchronous mkdir(2) - create a directory with a mode of `0o777`.
864 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
865 */
866 function mkdir(path: PathLike, callback: NoParamCallback): void;
867
868 // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
869 namespace mkdir {
870 /**
871 * Asynchronous mkdir(2) - create a directory.
872 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
873 * @param options Either the file mode, or an object optionally specifying the file mode and whether parent folders
874 * should be created. If a string is passed, it is parsed as an octal integer. If not specified, defaults to `0o777`.
875 */
876 function __promisify__(path: PathLike, options?: number | string | MakeDirectoryOptions | null): Promise<void>;
877 }
878
879 /**
880 * Synchronous mkdir(2) - create a directory.
881 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
882 * @param options Either the file mode, or an object optionally specifying the file mode and whether parent folders
883 * should be created. If a string is passed, it is parsed as an octal integer. If not specified, defaults to `0o777`.
884 */
885 function mkdirSync(path: PathLike, options?: number | string | MakeDirectoryOptions | null): void;
886
887 /**
888 * Asynchronously creates a unique temporary directory.
889 * Generates six random characters to be appended behind a required prefix to create a unique temporary directory.
890 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
891 */
892 function mkdtemp(
893 prefix: string,
894 options: { encoding?: BufferEncoding | null | undefined } | BufferEncoding | undefined | null,
895 callback: (err: NodeJS.ErrnoException | null, folder: string) => void
896 ): void;
897
898 /**
899 * Asynchronously creates a unique temporary directory.
900 * Generates six random characters to be appended behind a required prefix to create a unique temporary directory.
901 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
902 */
903 function mkdtemp(prefix: string, options: "buffer" | { encoding: "buffer" }, callback: (err: NodeJS.ErrnoException | null, folder: Buffer) => void): void;
904
905 /**
906 * Asynchronously creates a unique temporary directory.
907 * Generates six random characters to be appended behind a required prefix to create a unique temporary directory.
908 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
909 */
910 function mkdtemp(
911 prefix: string,
912 options: { encoding?: string | null | undefined } | string | undefined | null,
913 callback: (err: NodeJS.ErrnoException | null, folder: string | Buffer) => void
914 ): void;
915
916 /**
917 * Asynchronously creates a unique temporary directory.
918 * Generates six random characters to be appended behind a required prefix to create a unique temporary directory.
919 */
920 function mkdtemp(prefix: string, callback: (err: NodeJS.ErrnoException | null, folder: string) => void): void;
921
922 // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
923 namespace mkdtemp {
924 /**
925 * Asynchronously creates a unique temporary directory.
926 * Generates six random characters to be appended behind a required prefix to create a unique temporary directory.
927 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
928 */
929 function __promisify__(prefix: string, options?: { encoding?: BufferEncoding | null | undefined } | BufferEncoding | null): Promise<string>;
930
931 /**
932 * Asynchronously creates a unique temporary directory.
933 * Generates six random characters to be appended behind a required prefix to create a unique temporary directory.
934 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
935 */
936 function __promisify__(prefix: string, options: { encoding: "buffer" } | "buffer"): Promise<Buffer>;
937
938 /**
939 * Asynchronously creates a unique temporary directory.
940 * Generates six random characters to be appended behind a required prefix to create a unique temporary directory.
941 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
942 */
943 function __promisify__(prefix: string, options?: { encoding?: string | null | undefined } | string | null): Promise<string | Buffer>;
944 }
945
946 /**
947 * Synchronously creates a unique temporary directory.
948 * Generates six random characters to be appended behind a required prefix to create a unique temporary directory.
949 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
950 */
951 function mkdtempSync(prefix: string, options?: { encoding?: BufferEncoding | null | undefined } | BufferEncoding | null): string;
952
953 /**
954 * Synchronously creates a unique temporary directory.
955 * Generates six random characters to be appended behind a required prefix to create a unique temporary directory.
956 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
957 */
958 function mkdtempSync(prefix: string, options: { encoding: "buffer" } | "buffer"): Buffer;
959
960 /**
961 * Synchronously creates a unique temporary directory.
962 * Generates six random characters to be appended behind a required prefix to create a unique temporary directory.
963 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
964 */
965 function mkdtempSync(prefix: string, options?: { encoding?: string | null | undefined } | string | null): string | Buffer;
966
967 /**
968 * Asynchronous readdir(3) - read a directory.
969 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
970 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
971 */
972 function readdir(
973 path: PathLike,
974 options: { encoding: BufferEncoding | null; withFileTypes?: false | undefined } | BufferEncoding | undefined | null,
975 callback: (err: NodeJS.ErrnoException | null, files: string[]) => void,
976 ): void;
977
978 /**
979 * Asynchronous readdir(3) - read a directory.
980 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
981 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
982 */
983 function readdir(path: PathLike, options: { encoding: "buffer"; withFileTypes?: false | undefined } | "buffer", callback: (err: NodeJS.ErrnoException | null, files: Buffer[]) => void): void;
984
985 /**
986 * Asynchronous readdir(3) - read a directory.
987 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
988 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
989 */
990 function readdir(
991 path: PathLike,
992 options: { encoding?: string | null | undefined; withFileTypes?: false | undefined } | string | undefined | null,
993 callback: (err: NodeJS.ErrnoException | null, files: string[] | Buffer[]) => void,
994 ): void;
995
996 /**
997 * Asynchronous readdir(3) - read a directory.
998 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
999 */
1000 function readdir(path: PathLike, callback: (err: NodeJS.ErrnoException | null, files: string[]) => void): void;
1001
1002 /**
1003 * Asynchronous readdir(3) - read a directory.
1004 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1005 * @param options If called with `withFileTypes: true` the result data will be an array of Dirent.
1006 */
1007 function readdir(path: PathLike, options: { encoding?: string | null | undefined; withFileTypes: true }, callback: (err: NodeJS.ErrnoException | null, files: Dirent[]) => void): void;
1008
1009 // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
1010 namespace readdir {
1011 /**
1012 * Asynchronous readdir(3) - read a directory.
1013 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1014 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
1015 */
1016 function __promisify__(path: PathLike, options?: { encoding: BufferEncoding | null; withFileTypes?: false | undefined } | BufferEncoding | null): Promise<string[]>;
1017
1018 /**
1019 * Asynchronous readdir(3) - read a directory.
1020 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1021 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
1022 */
1023 function __promisify__(path: PathLike, options: "buffer" | { encoding: "buffer"; withFileTypes?: false | undefined }): Promise<Buffer[]>;
1024
1025 /**
1026 * Asynchronous readdir(3) - read a directory.
1027 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1028 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
1029 */
1030 function __promisify__(path: PathLike, options?: { encoding?: string | null | undefined; withFileTypes?: false | undefined } | string | null): Promise<string[] | Buffer[]>;
1031
1032 /**
1033 * Asynchronous readdir(3) - read a directory.
1034 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1035 * @param options If called with `withFileTypes: true` the result data will be an array of Dirent
1036 */
1037 function __promisify__(path: PathLike, options: { encoding?: string | null | undefined; withFileTypes: true }): Promise<Dirent[]>;
1038 }
1039
1040 /**
1041 * Synchronous readdir(3) - read a directory.
1042 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1043 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
1044 */
1045 function readdirSync(path: PathLike, options?: { encoding: BufferEncoding | null; withFileTypes?: false | undefined } | BufferEncoding | null): string[];
1046
1047 /**
1048 * Synchronous readdir(3) - read a directory.
1049 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1050 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
1051 */
1052 function readdirSync(path: PathLike, options: { encoding: "buffer"; withFileTypes?: false | undefined } | "buffer"): Buffer[];
1053
1054 /**
1055 * Synchronous readdir(3) - read a directory.
1056 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1057 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
1058 */
1059 function readdirSync(path: PathLike, options?: { encoding?: string | null | undefined; withFileTypes?: false | undefined } | string | null): string[] | Buffer[];
1060
1061 /**
1062 * Synchronous readdir(3) - read a directory.
1063 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1064 * @param options If called with `withFileTypes: true` the result data will be an array of Dirent.
1065 */
1066 function readdirSync(path: PathLike, options: { encoding?: string | null | undefined; withFileTypes: true }): Dirent[];
1067
1068 /**
1069 * Asynchronous close(2) - close a file descriptor.
1070 * @param fd A file descriptor.
1071 */
1072 function close(fd: number, callback: NoParamCallback): void;
1073
1074 // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
1075 namespace close {
1076 /**
1077 * Asynchronous close(2) - close a file descriptor.
1078 * @param fd A file descriptor.
1079 */
1080 function __promisify__(fd: number): Promise<void>;
1081 }
1082
1083 /**
1084 * Synchronous close(2) - close a file descriptor.
1085 * @param fd A file descriptor.
1086 */
1087 function closeSync(fd: number): void;
1088
1089 /**
1090 * Asynchronous open(2) - open and possibly create a file.
1091 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1092 * @param mode A file mode. If a string is passed, it is parsed as an octal integer. If not supplied, defaults to `0o666`.
1093 */
1094 function open(path: PathLike, flags: string | number, mode: string | number | undefined | null, callback: (err: NodeJS.ErrnoException | null, fd: number) => void): void;
1095
1096 /**
1097 * Asynchronous open(2) - open and possibly create a file. If the file is created, its mode will be `0o666`.
1098 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1099 */
1100 function open(path: PathLike, flags: string | number, callback: (err: NodeJS.ErrnoException | null, fd: number) => void): void;
1101
1102 // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
1103 namespace open {
1104 /**
1105 * Asynchronous open(2) - open and possibly create a file.
1106 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1107 * @param mode A file mode. If a string is passed, it is parsed as an octal integer. If not supplied, defaults to `0o666`.
1108 */
1109 function __promisify__(path: PathLike, flags: string | number, mode?: string | number | null): Promise<number>;
1110 }
1111
1112 /**
1113 * Synchronous open(2) - open and possibly create a file, returning a file descriptor..
1114 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1115 * @param mode A file mode. If a string is passed, it is parsed as an octal integer. If not supplied, defaults to `0o666`.
1116 */
1117 function openSync(path: PathLike, flags: string | number, mode?: string | number | null): number;
1118
1119 /**
1120 * Asynchronously change file timestamps of the file referenced by the supplied path.
1121 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1122 * @param atime The last access time. If a string is provided, it will be coerced to number.
1123 * @param mtime The last modified time. If a string is provided, it will be coerced to number.
1124 */
1125 function utimes(path: PathLike, atime: string | number | Date, mtime: string | number | Date, callback: NoParamCallback): void;
1126
1127 // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
1128 namespace utimes {
1129 /**
1130 * Asynchronously change file timestamps of the file referenced by the supplied path.
1131 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1132 * @param atime The last access time. If a string is provided, it will be coerced to number.
1133 * @param mtime The last modified time. If a string is provided, it will be coerced to number.
1134 */
1135 function __promisify__(path: PathLike, atime: string | number | Date, mtime: string | number | Date): Promise<void>;
1136 }
1137
1138 /**
1139 * Synchronously change file timestamps of the file referenced by the supplied path.
1140 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1141 * @param atime The last access time. If a string is provided, it will be coerced to number.
1142 * @param mtime The last modified time. If a string is provided, it will be coerced to number.
1143 */
1144 function utimesSync(path: PathLike, atime: string | number | Date, mtime: string | number | Date): void;
1145
1146 /**
1147 * Asynchronously change file timestamps of the file referenced by the supplied file descriptor.
1148 * @param fd A file descriptor.
1149 * @param atime The last access time. If a string is provided, it will be coerced to number.
1150 * @param mtime The last modified time. If a string is provided, it will be coerced to number.
1151 */
1152 function futimes(fd: number, atime: string | number | Date, mtime: string | number | Date, callback: NoParamCallback): void;
1153
1154 // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
1155 namespace futimes {
1156 /**
1157 * Asynchronously change file timestamps of the file referenced by the supplied file descriptor.
1158 * @param fd A file descriptor.
1159 * @param atime The last access time. If a string is provided, it will be coerced to number.
1160 * @param mtime The last modified time. If a string is provided, it will be coerced to number.
1161 */
1162 function __promisify__(fd: number, atime: string | number | Date, mtime: string | number | Date): Promise<void>;
1163 }
1164
1165 /**
1166 * Synchronously change file timestamps of the file referenced by the supplied file descriptor.
1167 * @param fd A file descriptor.
1168 * @param atime The last access time. If a string is provided, it will be coerced to number.
1169 * @param mtime The last modified time. If a string is provided, it will be coerced to number.
1170 */
1171 function futimesSync(fd: number, atime: string | number | Date, mtime: string | number | Date): void;
1172
1173 /**
1174 * Asynchronous fsync(2) - synchronize a file's in-core state with the underlying storage device.
1175 * @param fd A file descriptor.
1176 */
1177 function fsync(fd: number, callback: NoParamCallback): void;
1178
1179 // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
1180 namespace fsync {
1181 /**
1182 * Asynchronous fsync(2) - synchronize a file's in-core state with the underlying storage device.
1183 * @param fd A file descriptor.
1184 */
1185 function __promisify__(fd: number): Promise<void>;
1186 }
1187
1188 /**
1189 * Synchronous fsync(2) - synchronize a file's in-core state with the underlying storage device.
1190 * @param fd A file descriptor.
1191 */
1192 function fsyncSync(fd: number): void;
1193
1194 /**
1195 * Asynchronously writes `buffer` to the file referenced by the supplied file descriptor.
1196 * @param fd A file descriptor.
1197 * @param offset The part of the buffer to be written. If not supplied, defaults to `0`.
1198 * @param length The number of bytes to write. If not supplied, defaults to `buffer.length - offset`.
1199 * @param position The offset from the beginning of the file where this data should be written. If not supplied, defaults to the current position.
1200 */
1201 function write<TBuffer extends NodeJS.ArrayBufferView>(
1202 fd: number,
1203 buffer: TBuffer,
1204 offset: number | undefined | null,
1205 length: number | undefined | null,
1206 position: number | undefined | null,
1207 callback: (err: NodeJS.ErrnoException | null, written: number, buffer: TBuffer) => void,
1208 ): void;
1209
1210 /**
1211 * Asynchronously writes `buffer` to the file referenced by the supplied file descriptor.
1212 * @param fd A file descriptor.
1213 * @param offset The part of the buffer to be written. If not supplied, defaults to `0`.
1214 * @param length The number of bytes to write. If not supplied, defaults to `buffer.length - offset`.
1215 */
1216 function write<TBuffer extends NodeJS.ArrayBufferView>(
1217 fd: number,
1218 buffer: TBuffer,
1219 offset: number | undefined | null,
1220 length: number | undefined | null,
1221 callback: (err: NodeJS.ErrnoException | null, written: number, buffer: TBuffer) => void,
1222 ): void;
1223
1224 /**
1225 * Asynchronously writes `buffer` to the file referenced by the supplied file descriptor.
1226 * @param fd A file descriptor.
1227 * @param offset The part of the buffer to be written. If not supplied, defaults to `0`.
1228 */
1229 function write<TBuffer extends NodeJS.ArrayBufferView>(
1230 fd: number,
1231 buffer: TBuffer,
1232 offset: number | undefined | null,
1233 callback: (err: NodeJS.ErrnoException | null, written: number, buffer: TBuffer) => void
1234 ): void;
1235
1236 /**
1237 * Asynchronously writes `buffer` to the file referenced by the supplied file descriptor.
1238 * @param fd A file descriptor.
1239 */
1240 function write<TBuffer extends NodeJS.ArrayBufferView>(fd: number, buffer: TBuffer, callback: (err: NodeJS.ErrnoException | null, written: number, buffer: TBuffer) => void): void;
1241
1242 /**
1243 * Asynchronously writes `string` to the file referenced by the supplied file descriptor.
1244 * @param fd A file descriptor.
1245 * @param string A string to write. If something other than a string is supplied it will be coerced to a string.
1246 * @param position The offset from the beginning of the file where this data should be written. If not supplied, defaults to the current position.
1247 * @param encoding The expected string encoding.
1248 */
1249 function write(
1250 fd: number,
1251 string: any,
1252 position: number | undefined | null,
1253 encoding: string | undefined | null,
1254 callback: (err: NodeJS.ErrnoException | null, written: number, str: string) => void,
1255 ): void;
1256
1257 /**
1258 * Asynchronously writes `string` to the file referenced by the supplied file descriptor.
1259 * @param fd A file descriptor.
1260 * @param string A string to write. If something other than a string is supplied it will be coerced to a string.
1261 * @param position The offset from the beginning of the file where this data should be written. If not supplied, defaults to the current position.
1262 */
1263 function write(fd: number, string: any, position: number | undefined | null, callback: (err: NodeJS.ErrnoException | null, written: number, str: string) => void): void;
1264
1265 /**
1266 * Asynchronously writes `string` to the file referenced by the supplied file descriptor.
1267 * @param fd A file descriptor.
1268 * @param string A string to write. If something other than a string is supplied it will be coerced to a string.
1269 */
1270 function write(fd: number, string: any, callback: (err: NodeJS.ErrnoException | null, written: number, str: string) => void): void;
1271
1272 // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
1273 namespace write {
1274 /**
1275 * Asynchronously writes `buffer` to the file referenced by the supplied file descriptor.
1276 * @param fd A file descriptor.
1277 * @param offset The part of the buffer to be written. If not supplied, defaults to `0`.
1278 * @param length The number of bytes to write. If not supplied, defaults to `buffer.length - offset`.
1279 * @param position The offset from the beginning of the file where this data should be written. If not supplied, defaults to the current position.
1280 */
1281 function __promisify__<TBuffer extends NodeJS.ArrayBufferView>(
1282 fd: number,
1283 buffer?: TBuffer,
1284 offset?: number,
1285 length?: number,
1286 position?: number | null,
1287 ): Promise<{ bytesWritten: number, buffer: TBuffer }>;
1288
1289 /**
1290 * Asynchronously writes `string` to the file referenced by the supplied file descriptor.
1291 * @param fd A file descriptor.
1292 * @param string A string to write. If something other than a string is supplied it will be coerced to a string.
1293 * @param position The offset from the beginning of the file where this data should be written. If not supplied, defaults to the current position.
1294 * @param encoding The expected string encoding.
1295 */
1296 function __promisify__(fd: number, string: any, position?: number | null, encoding?: string | null): Promise<{ bytesWritten: number, buffer: string }>;
1297 }
1298
1299 /**
1300 * Synchronously writes `buffer` to the file referenced by the supplied file descriptor, returning the number of bytes written.
1301 * @param fd A file descriptor.
1302 * @param offset The part of the buffer to be written. If not supplied, defaults to `0`.
1303 * @param length The number of bytes to write. If not supplied, defaults to `buffer.length - offset`.
1304 * @param position The offset from the beginning of the file where this data should be written. If not supplied, defaults to the current position.
1305 */
1306 function writeSync(fd: number, buffer: NodeJS.ArrayBufferView, offset?: number | null, length?: number | null, position?: number | null): number;
1307
1308 /**
1309 * Synchronously writes `string` to the file referenced by the supplied file descriptor, returning the number of bytes written.
1310 * @param fd A file descriptor.
1311 * @param string A string to write. If something other than a string is supplied it will be coerced to a string.
1312 * @param position The offset from the beginning of the file where this data should be written. If not supplied, defaults to the current position.
1313 * @param encoding The expected string encoding.
1314 */
1315 function writeSync(fd: number, string: any, position?: number | null, encoding?: string | null): number;
1316
1317 /**
1318 * Asynchronously reads data from the file referenced by the supplied file descriptor.
1319 * @param fd A file descriptor.
1320 * @param buffer The buffer that the data will be written to.
1321 * @param offset The offset in the buffer at which to start writing.
1322 * @param length The number of bytes to read.
1323 * @param position The offset from the beginning of the file from which data should be read. If `null`, data will be read from the current position.
1324 */
1325 function read<TBuffer extends NodeJS.ArrayBufferView>(
1326 fd: number,
1327 buffer: TBuffer,
1328 offset: number,
1329 length: number,
1330 position: number | null,
1331 callback: (err: NodeJS.ErrnoException | null, bytesRead: number, buffer: TBuffer) => void,
1332 ): void;
1333
1334 // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
1335 namespace read {
1336 /**
1337 * @param fd A file descriptor.
1338 * @param buffer The buffer that the data will be written to.
1339 * @param offset The offset in the buffer at which to start writing.
1340 * @param length The number of bytes to read.
1341 * @param position The offset from the beginning of the file from which data should be read. If `null`, data will be read from the current position.
1342 */
1343 function __promisify__<TBuffer extends NodeJS.ArrayBufferView>(
1344 fd: number,
1345 buffer: TBuffer,
1346 offset: number,
1347 length: number,
1348 position: number | null
1349 ): Promise<{ bytesRead: number, buffer: TBuffer }>;
1350 }
1351
1352 /**
1353 * Synchronously reads data from the file referenced by the supplied file descriptor, returning the number of bytes read.
1354 * @param fd A file descriptor.
1355 * @param buffer The buffer that the data will be written to.
1356 * @param offset The offset in the buffer at which to start writing.
1357 * @param length The number of bytes to read.
1358 * @param position The offset from the beginning of the file from which data should be read. If `null`, data will be read from the current position.
1359 */
1360 function readSync(fd: number, buffer: NodeJS.ArrayBufferView, offset: number, length: number, position: number | null): number;
1361
1362 /**
1363 * Asynchronously reads the entire contents of a file.
1364 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1365 * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
1366 * @param options An object that may contain an optional flag.
1367 * If a flag is not provided, it defaults to `'r'`.
1368 */
1369 function readFile(
1370 path: PathLike | number,
1371 options: { encoding?: null | undefined; flag?: string | undefined; } | undefined | null,
1372 callback: (err: NodeJS.ErrnoException | null, data: Buffer) => void
1373 ): void;
1374
1375 /**
1376 * Asynchronously reads the entire contents of a file.
1377 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1378 * URL support is _experimental_.
1379 * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
1380 * @param options Either the encoding for the result, or an object that contains the encoding and an optional flag.
1381 * If a flag is not provided, it defaults to `'r'`.
1382 */
1383 function readFile(path: PathLike | number, options: { encoding: string; flag?: string | undefined; } | string, callback: (err: NodeJS.ErrnoException | null, data: string) => void): void;
1384
1385 /**
1386 * Asynchronously reads the entire contents of a file.
1387 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1388 * URL support is _experimental_.
1389 * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
1390 * @param options Either the encoding for the result, or an object that contains the encoding and an optional flag.
1391 * If a flag is not provided, it defaults to `'r'`.
1392 */
1393 function readFile(
1394 path: PathLike | number,
1395 options: { encoding?: string | null | undefined; flag?: string | undefined; } | string | undefined | null,
1396 callback: (err: NodeJS.ErrnoException | null, data: string | Buffer) => void,
1397 ): void;
1398
1399 /**
1400 * Asynchronously reads the entire contents of a file.
1401 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1402 * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
1403 */
1404 function readFile(path: PathLike | number, callback: (err: NodeJS.ErrnoException | null, data: Buffer) => void): void;
1405
1406 // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
1407 namespace readFile {
1408 /**
1409 * Asynchronously reads the entire contents of a file.
1410 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1411 * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
1412 * @param options An object that may contain an optional flag.
1413 * If a flag is not provided, it defaults to `'r'`.
1414 */
1415 function __promisify__(path: PathLike | number, options?: { encoding?: null | undefined; flag?: string | undefined; } | null): Promise<Buffer>;
1416
1417 /**
1418 * Asynchronously reads the entire contents of a file.
1419 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1420 * URL support is _experimental_.
1421 * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
1422 * @param options Either the encoding for the result, or an object that contains the encoding and an optional flag.
1423 * If a flag is not provided, it defaults to `'r'`.
1424 */
1425 function __promisify__(path: PathLike | number, options: { encoding: string; flag?: string | undefined; } | string): Promise<string>;
1426
1427 /**
1428 * Asynchronously reads the entire contents of a file.
1429 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1430 * URL support is _experimental_.
1431 * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
1432 * @param options Either the encoding for the result, or an object that contains the encoding and an optional flag.
1433 * If a flag is not provided, it defaults to `'r'`.
1434 */
1435 function __promisify__(path: PathLike | number, options?: { encoding?: string | null | undefined; flag?: string | undefined; } | string | null): Promise<string | Buffer>;
1436 }
1437
1438 /**
1439 * Synchronously reads the entire contents of a file.
1440 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1441 * URL support is _experimental_.
1442 * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
1443 * @param options An object that may contain an optional flag. If a flag is not provided, it defaults to `'r'`.
1444 */
1445 function readFileSync(path: PathLike | number, options?: { encoding?: null | undefined; flag?: string | undefined; } | null): Buffer;
1446
1447 /**
1448 * Synchronously reads the entire contents of a file.
1449 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1450 * URL support is _experimental_.
1451 * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
1452 * @param options Either the encoding for the result, or an object that contains the encoding and an optional flag.
1453 * If a flag is not provided, it defaults to `'r'`.
1454 */
1455 function readFileSync(path: PathLike | number, options: { encoding: string; flag?: string | undefined; } | string): string;
1456
1457 /**
1458 * Synchronously reads the entire contents of a file.
1459 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1460 * URL support is _experimental_.
1461 * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
1462 * @param options Either the encoding for the result, or an object that contains the encoding and an optional flag.
1463 * If a flag is not provided, it defaults to `'r'`.
1464 */
1465 function readFileSync(path: PathLike | number, options?: { encoding?: string | null | undefined; flag?: string | undefined; } | string | null): string | Buffer;
1466
1467 type WriteFileOptions = { encoding?: string | null | undefined; mode?: number | string | undefined; flag?: string | undefined; } | string | null;
1468
1469 /**
1470 * Asynchronously writes data to a file, replacing the file if it already exists.
1471 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1472 * URL support is _experimental_.
1473 * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
1474 * @param data The data to write. If something other than a Buffer or Uint8Array is provided, the value is coerced to a string.
1475 * @param options Either the encoding for the file, or an object optionally specifying the encoding, file mode, and flag.
1476 * If `encoding` is not supplied, the default of `'utf8'` is used.
1477 * If `mode` is not supplied, the default of `0o666` is used.
1478 * If `mode` is a string, it is parsed as an octal integer.
1479 * If `flag` is not supplied, the default of `'w'` is used.
1480 */
1481 function writeFile(path: PathLike | number, data: any, options: WriteFileOptions, callback: NoParamCallback): void;
1482
1483 /**
1484 * Asynchronously writes data to a file, replacing the file if it already exists.
1485 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1486 * URL support is _experimental_.
1487 * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
1488 * @param data The data to write. If something other than a Buffer or Uint8Array is provided, the value is coerced to a string.
1489 */
1490 function writeFile(path: PathLike | number, data: any, callback: NoParamCallback): void;
1491
1492 // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
1493 namespace writeFile {
1494 /**
1495 * Asynchronously writes data to a file, replacing the file if it already exists.
1496 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1497 * URL support is _experimental_.
1498 * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
1499 * @param data The data to write. If something other than a Buffer or Uint8Array is provided, the value is coerced to a string.
1500 * @param options Either the encoding for the file, or an object optionally specifying the encoding, file mode, and flag.
1501 * If `encoding` is not supplied, the default of `'utf8'` is used.
1502 * If `mode` is not supplied, the default of `0o666` is used.
1503 * If `mode` is a string, it is parsed as an octal integer.
1504 * If `flag` is not supplied, the default of `'w'` is used.
1505 */
1506 function __promisify__(path: PathLike | number, data: any, options?: WriteFileOptions): Promise<void>;
1507 }
1508
1509 /**
1510 * Synchronously writes data to a file, replacing the file if it already exists.
1511 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1512 * URL support is _experimental_.
1513 * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
1514 * @param data The data to write. If something other than a Buffer or Uint8Array is provided, the value is coerced to a string.
1515 * @param options Either the encoding for the file, or an object optionally specifying the encoding, file mode, and flag.
1516 * If `encoding` is not supplied, the default of `'utf8'` is used.
1517 * If `mode` is not supplied, the default of `0o666` is used.
1518 * If `mode` is a string, it is parsed as an octal integer.
1519 * If `flag` is not supplied, the default of `'w'` is used.
1520 */
1521 function writeFileSync(path: PathLike | number, data: any, options?: WriteFileOptions): void;
1522
1523 /**
1524 * Asynchronously append data to a file, creating the file if it does not exist.
1525 * @param file A path to a file. If a URL is provided, it must use the `file:` protocol.
1526 * URL support is _experimental_.
1527 * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
1528 * @param data The data to write. If something other than a Buffer or Uint8Array is provided, the value is coerced to a string.
1529 * @param options Either the encoding for the file, or an object optionally specifying the encoding, file mode, and flag.
1530 * If `encoding` is not supplied, the default of `'utf8'` is used.
1531 * If `mode` is not supplied, the default of `0o666` is used.
1532 * If `mode` is a string, it is parsed as an octal integer.
1533 * If `flag` is not supplied, the default of `'a'` is used.
1534 */
1535 function appendFile(file: PathLike | number, data: any, options: WriteFileOptions, callback: NoParamCallback): void;
1536
1537 /**
1538 * Asynchronously append data to a file, creating the file if it does not exist.
1539 * @param file A path to a file. If a URL is provided, it must use the `file:` protocol.
1540 * URL support is _experimental_.
1541 * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
1542 * @param data The data to write. If something other than a Buffer or Uint8Array is provided, the value is coerced to a string.
1543 */
1544 function appendFile(file: PathLike | number, data: any, callback: NoParamCallback): void;
1545
1546 // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
1547 namespace appendFile {
1548 /**
1549 * Asynchronously append data to a file, creating the file if it does not exist.
1550 * @param file A path to a file. If a URL is provided, it must use the `file:` protocol.
1551 * URL support is _experimental_.
1552 * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
1553 * @param data The data to write. If something other than a Buffer or Uint8Array is provided, the value is coerced to a string.
1554 * @param options Either the encoding for the file, or an object optionally specifying the encoding, file mode, and flag.
1555 * If `encoding` is not supplied, the default of `'utf8'` is used.
1556 * If `mode` is not supplied, the default of `0o666` is used.
1557 * If `mode` is a string, it is parsed as an octal integer.
1558 * If `flag` is not supplied, the default of `'a'` is used.
1559 */
1560 function __promisify__(file: PathLike | number, data: any, options?: WriteFileOptions): Promise<void>;
1561 }
1562
1563 /**
1564 * Synchronously append data to a file, creating the file if it does not exist.
1565 * @param file A path to a file. If a URL is provided, it must use the `file:` protocol.
1566 * URL support is _experimental_.
1567 * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
1568 * @param data The data to write. If something other than a Buffer or Uint8Array is provided, the value is coerced to a string.
1569 * @param options Either the encoding for the file, or an object optionally specifying the encoding, file mode, and flag.
1570 * If `encoding` is not supplied, the default of `'utf8'` is used.
1571 * If `mode` is not supplied, the default of `0o666` is used.
1572 * If `mode` is a string, it is parsed as an octal integer.
1573 * If `flag` is not supplied, the default of `'a'` is used.
1574 */
1575 function appendFileSync(file: PathLike | number, data: any, options?: WriteFileOptions): void;
1576
1577 /**
1578 * Watch for changes on `filename`. The callback `listener` will be called each time the file is accessed.
1579 */
1580 function watchFile(filename: PathLike, options: { persistent?: boolean | undefined; interval?: number | undefined; } | undefined, listener: (curr: Stats, prev: Stats) => void): void;
1581
1582 /**
1583 * Watch for changes on `filename`. The callback `listener` will be called each time the file is accessed.
1584 * @param filename A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
1585 * URL support is _experimental_.
1586 */
1587 function watchFile(filename: PathLike, listener: (curr: Stats, prev: Stats) => void): void;
1588
1589 /**
1590 * Stop watching for changes on `filename`.
1591 * @param filename A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
1592 * URL support is _experimental_.
1593 */
1594 function unwatchFile(filename: PathLike, listener?: (curr: Stats, prev: Stats) => void): void;
1595
1596 /**
1597 * Watch for changes on `filename`, where `filename` is either a file or a directory, returning an `FSWatcher`.
1598 * @param filename A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
1599 * URL support is _experimental_.
1600 * @param options Either the encoding for the filename provided to the listener, or an object optionally specifying encoding, persistent, and recursive options.
1601 * If `encoding` is not supplied, the default of `'utf8'` is used.
1602 * If `persistent` is not supplied, the default of `true` is used.
1603 * If `recursive` is not supplied, the default of `false` is used.
1604 */
1605 function watch(
1606 filename: PathLike,
1607 options: { encoding?: BufferEncoding | null | undefined, persistent?: boolean | undefined, recursive?: boolean | undefined } | BufferEncoding | undefined | null,
1608 listener?: (event: string, filename: string) => void,
1609 ): FSWatcher;
1610
1611 /**
1612 * Watch for changes on `filename`, where `filename` is either a file or a directory, returning an `FSWatcher`.
1613 * @param filename A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
1614 * URL support is _experimental_.
1615 * @param options Either the encoding for the filename provided to the listener, or an object optionally specifying encoding, persistent, and recursive options.
1616 * If `encoding` is not supplied, the default of `'utf8'` is used.
1617 * If `persistent` is not supplied, the default of `true` is used.
1618 * If `recursive` is not supplied, the default of `false` is used.
1619 */
1620 function watch(
1621 filename: PathLike,
1622 options: { encoding: "buffer", persistent?: boolean | undefined, recursive?: boolean | undefined } | "buffer",
1623 listener?: (event: string, filename: Buffer) => void
1624 ): FSWatcher;
1625
1626 /**
1627 * Watch for changes on `filename`, where `filename` is either a file or a directory, returning an `FSWatcher`.
1628 * @param filename A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
1629 * URL support is _experimental_.
1630 * @param options Either the encoding for the filename provided to the listener, or an object optionally specifying encoding, persistent, and recursive options.
1631 * If `encoding` is not supplied, the default of `'utf8'` is used.
1632 * If `persistent` is not supplied, the default of `true` is used.
1633 * If `recursive` is not supplied, the default of `false` is used.
1634 */
1635 function watch(
1636 filename: PathLike,
1637 options: { encoding?: string | null | undefined, persistent?: boolean | undefined, recursive?: boolean | undefined } | string | null,
1638 listener?: (event: string, filename: string | Buffer) => void,
1639 ): FSWatcher;
1640
1641 /**
1642 * Watch for changes on `filename`, where `filename` is either a file or a directory, returning an `FSWatcher`.
1643 * @param filename A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
1644 * URL support is _experimental_.
1645 */
1646 function watch(filename: PathLike, listener?: (event: string, filename: string) => any): FSWatcher;
1647
1648 /**
1649 * Asynchronously tests whether or not the given path exists by checking with the file system.
1650 * @deprecated
1651 * @param path A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
1652 * URL support is _experimental_.
1653 */
1654 function exists(path: PathLike, callback: (exists: boolean) => void): void;
1655
1656 // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
1657 namespace exists {
1658 /**
1659 * @param path A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
1660 * URL support is _experimental_.
1661 */
1662 function __promisify__(path: PathLike): Promise<boolean>;
1663 }
1664
1665 /**
1666 * Synchronously tests whether or not the given path exists by checking with the file system.
1667 * @param path A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
1668 * URL support is _experimental_.
1669 */
1670 function existsSync(path: PathLike): boolean;
1671
1672 namespace constants {
1673 // File Access Constants
1674
1675 /** Constant for fs.access(). File is visible to the calling process. */
1676 const F_OK: number;
1677
1678 /** Constant for fs.access(). File can be read by the calling process. */
1679 const R_OK: number;
1680
1681 /** Constant for fs.access(). File can be written by the calling process. */
1682 const W_OK: number;
1683
1684 /** Constant for fs.access(). File can be executed by the calling process. */
1685 const X_OK: number;
1686
1687 // File Copy Constants
1688
1689 /** Constant for fs.copyFile. Flag indicating the destination file should not be overwritten if it already exists. */
1690 const COPYFILE_EXCL: number;
1691
1692 /**
1693 * Constant for fs.copyFile. copy operation will attempt to create a copy-on-write reflink.
1694 * If the underlying platform does not support copy-on-write, then a fallback copy mechanism is used.
1695 */
1696 const COPYFILE_FICLONE: number;
1697
1698 /**
1699 * Constant for fs.copyFile. Copy operation will attempt to create a copy-on-write reflink.
1700 * If the underlying platform does not support copy-on-write, then the operation will fail with an error.
1701 */
1702 const COPYFILE_FICLONE_FORCE: number;
1703
1704 // File Open Constants
1705
1706 /** Constant for fs.open(). Flag indicating to open a file for read-only access. */
1707 const O_RDONLY: number;
1708
1709 /** Constant for fs.open(). Flag indicating to open a file for write-only access. */
1710 const O_WRONLY: number;
1711
1712 /** Constant for fs.open(). Flag indicating to open a file for read-write access. */
1713 const O_RDWR: number;
1714
1715 /** Constant for fs.open(). Flag indicating to create the file if it does not already exist. */
1716 const O_CREAT: number;
1717
1718 /** Constant for fs.open(). Flag indicating that opening a file should fail if the O_CREAT flag is set and the file already exists. */
1719 const O_EXCL: number;
1720
1721 /**
1722 * Constant for fs.open(). Flag indicating that if path identifies a terminal device,
1723 * opening the path shall not cause that terminal to become the controlling terminal for the process
1724 * (if the process does not already have one).
1725 */
1726 const O_NOCTTY: number;
1727
1728 /** Constant for fs.open(). Flag indicating that if the file exists and is a regular file, and the file is opened successfully for write access, its length shall be truncated to zero. */
1729 const O_TRUNC: number;
1730
1731 /** Constant for fs.open(). Flag indicating that data will be appended to the end of the file. */
1732 const O_APPEND: number;
1733
1734 /** Constant for fs.open(). Flag indicating that the open should fail if the path is not a directory. */
1735 const O_DIRECTORY: number;
1736
1737 /**
1738 * constant for fs.open().
1739 * Flag indicating reading accesses to the file system will no longer result in
1740 * an update to the atime information associated with the file.
1741 * This flag is available on Linux operating systems only.
1742 */
1743 const O_NOATIME: number;
1744
1745 /** Constant for fs.open(). Flag indicating that the open should fail if the path is a symbolic link. */
1746 const O_NOFOLLOW: number;
1747
1748 /** Constant for fs.open(). Flag indicating that the file is opened for synchronous I/O. */
1749 const O_SYNC: number;
1750
1751 /** Constant for fs.open(). Flag indicating that the file is opened for synchronous I/O with write operations waiting for data integrity. */
1752 const O_DSYNC: number;
1753
1754 /** Constant for fs.open(). Flag indicating to open the symbolic link itself rather than the resource it is pointing to. */
1755 const O_SYMLINK: number;
1756
1757 /** Constant for fs.open(). When set, an attempt will be made to minimize caching effects of file I/O. */
1758 const O_DIRECT: number;
1759
1760 /** Constant for fs.open(). Flag indicating to open the file in nonblocking mode when possible. */
1761 const O_NONBLOCK: number;
1762
1763 // File Type Constants
1764
1765 /** Constant for fs.Stats mode property for determining a file's type. Bit mask used to extract the file type code. */
1766 const S_IFMT: number;
1767
1768 /** Constant for fs.Stats mode property for determining a file's type. File type constant for a regular file. */
1769 const S_IFREG: number;
1770
1771 /** Constant for fs.Stats mode property for determining a file's type. File type constant for a directory. */
1772 const S_IFDIR: number;
1773
1774 /** Constant for fs.Stats mode property for determining a file's type. File type constant for a character-oriented device file. */
1775 const S_IFCHR: number;
1776
1777 /** Constant for fs.Stats mode property for determining a file's type. File type constant for a block-oriented device file. */
1778 const S_IFBLK: number;
1779
1780 /** Constant for fs.Stats mode property for determining a file's type. File type constant for a FIFO/pipe. */
1781 const S_IFIFO: number;
1782
1783 /** Constant for fs.Stats mode property for determining a file's type. File type constant for a symbolic link. */
1784 const S_IFLNK: number;
1785
1786 /** Constant for fs.Stats mode property for determining a file's type. File type constant for a socket. */
1787 const S_IFSOCK: number;
1788
1789 // File Mode Constants
1790
1791 /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating readable, writable and executable by owner. */
1792 const S_IRWXU: number;
1793
1794 /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating readable by owner. */
1795 const S_IRUSR: number;
1796
1797 /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating writable by owner. */
1798 const S_IWUSR: number;
1799
1800 /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating executable by owner. */
1801 const S_IXUSR: number;
1802
1803 /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating readable, writable and executable by group. */
1804 const S_IRWXG: number;
1805
1806 /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating readable by group. */
1807 const S_IRGRP: number;
1808
1809 /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating writable by group. */
1810 const S_IWGRP: number;
1811
1812 /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating executable by group. */
1813 const S_IXGRP: number;
1814
1815 /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating readable, writable and executable by others. */
1816 const S_IRWXO: number;
1817
1818 /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating readable by others. */
1819 const S_IROTH: number;
1820
1821 /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating writable by others. */
1822 const S_IWOTH: number;
1823
1824 /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating executable by others. */
1825 const S_IXOTH: number;
1826
1827 /**
1828 * When set, a memory file mapping is used to access the file. This flag
1829 * is available on Windows operating systems only. On other operating systems,
1830 * this flag is ignored.
1831 */
1832 const UV_FS_O_FILEMAP: number;
1833 }
1834
1835 /**
1836 * Asynchronously tests a user's permissions for the file specified by path.
1837 * @param path A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
1838 * URL support is _experimental_.
1839 */
1840 function access(path: PathLike, mode: number | undefined, callback: NoParamCallback): void;
1841
1842 /**
1843 * Asynchronously tests a user's permissions for the file specified by path.
1844 * @param path A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
1845 * URL support is _experimental_.
1846 */
1847 function access(path: PathLike, callback: NoParamCallback): void;
1848
1849 // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
1850 namespace access {
1851 /**
1852 * Asynchronously tests a user's permissions for the file specified by path.
1853 * @param path A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
1854 * URL support is _experimental_.
1855 */
1856 function __promisify__(path: PathLike, mode?: number): Promise<void>;
1857 }
1858
1859 /**
1860 * Synchronously tests a user's permissions for the file specified by path.
1861 * @param path A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
1862 * URL support is _experimental_.
1863 */
1864 function accessSync(path: PathLike, mode?: number): void;
1865
1866 /**
1867 * Returns a new `ReadStream` object.
1868 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1869 * URL support is _experimental_.
1870 */
1871 function createReadStream(path: PathLike, options?: string | {
1872 flags?: string | undefined;
1873 encoding?: string | undefined;
1874 fd?: number | undefined;
1875 mode?: number | undefined;
1876 autoClose?: boolean | undefined;
1877 /**
1878 * @default false
1879 */
1880 emitClose?: boolean | undefined;
1881 start?: number | undefined;
1882 end?: number | undefined;
1883 highWaterMark?: number | undefined;
1884 }): ReadStream;
1885
1886 /**
1887 * Returns a new `WriteStream` object.
1888 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1889 * URL support is _experimental_.
1890 */
1891 function createWriteStream(path: PathLike, options?: string | {
1892 flags?: string | undefined;
1893 encoding?: string | undefined;
1894 fd?: number | undefined;
1895 mode?: number | undefined;
1896 autoClose?: boolean | undefined;
1897 emitClose?: boolean | undefined;
1898 start?: number | undefined;
1899 highWaterMark?: number | undefined;
1900 }): WriteStream;
1901
1902 /**
1903 * Asynchronous fdatasync(2) - synchronize a file's in-core state with storage device.
1904 * @param fd A file descriptor.
1905 */
1906 function fdatasync(fd: number, callback: NoParamCallback): void;
1907
1908 // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
1909 namespace fdatasync {
1910 /**
1911 * Asynchronous fdatasync(2) - synchronize a file's in-core state with storage device.
1912 * @param fd A file descriptor.
1913 */
1914 function __promisify__(fd: number): Promise<void>;
1915 }
1916
1917 /**
1918 * Synchronous fdatasync(2) - synchronize a file's in-core state with storage device.
1919 * @param fd A file descriptor.
1920 */
1921 function fdatasyncSync(fd: number): void;
1922
1923 /**
1924 * Asynchronously copies src to dest. By default, dest is overwritten if it already exists.
1925 * No arguments other than a possible exception are given to the callback function.
1926 * Node.js makes no guarantees about the atomicity of the copy operation.
1927 * If an error occurs after the destination file has been opened for writing, Node.js will attempt
1928 * to remove the destination.
1929 * @param src A path to the source file.
1930 * @param dest A path to the destination file.
1931 */
1932 function copyFile(src: PathLike, dest: PathLike, callback: NoParamCallback): void;
1933 /**
1934 * Asynchronously copies src to dest. By default, dest is overwritten if it already exists.
1935 * No arguments other than a possible exception are given to the callback function.
1936 * Node.js makes no guarantees about the atomicity of the copy operation.
1937 * If an error occurs after the destination file has been opened for writing, Node.js will attempt
1938 * to remove the destination.
1939 * @param src A path to the source file.
1940 * @param dest A path to the destination file.
1941 * @param flags An integer that specifies the behavior of the copy operation. The only supported flag is fs.constants.COPYFILE_EXCL, which causes the copy operation to fail if dest already exists.
1942 */
1943 function copyFile(src: PathLike, dest: PathLike, flags: number, callback: NoParamCallback): void;
1944
1945 // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
1946 namespace copyFile {
1947 /**
1948 * Asynchronously copies src to dest. By default, dest is overwritten if it already exists.
1949 * No arguments other than a possible exception are given to the callback function.
1950 * Node.js makes no guarantees about the atomicity of the copy operation.
1951 * If an error occurs after the destination file has been opened for writing, Node.js will attempt
1952 * to remove the destination.
1953 * @param src A path to the source file.
1954 * @param dest A path to the destination file.
1955 * @param flags An optional integer that specifies the behavior of the copy operation.
1956 * The only supported flag is fs.constants.COPYFILE_EXCL,
1957 * which causes the copy operation to fail if dest already exists.
1958 */
1959 function __promisify__(src: PathLike, dst: PathLike, flags?: number): Promise<void>;
1960 }
1961
1962 /**
1963 * Synchronously copies src to dest. By default, dest is overwritten if it already exists.
1964 * Node.js makes no guarantees about the atomicity of the copy operation.
1965 * If an error occurs after the destination file has been opened for writing, Node.js will attempt
1966 * to remove the destination.
1967 * @param src A path to the source file.
1968 * @param dest A path to the destination file.
1969 * @param flags An optional integer that specifies the behavior of the copy operation.
1970 * The only supported flag is fs.constants.COPYFILE_EXCL, which causes the copy operation to fail if dest already exists.
1971 */
1972 function copyFileSync(src: PathLike, dest: PathLike, flags?: number): void;
1973
1974 /**
1975 * Write an array of ArrayBufferViews to the file specified by fd using writev().
1976 * position is the offset from the beginning of the file where this data should be written.
1977 * It is unsafe to use fs.writev() multiple times on the same file without waiting for the callback. For this scenario, use fs.createWriteStream().
1978 * On Linux, positional writes don't work when the file is opened in append mode.
1979 * The kernel ignores the position argument and always appends the data to the end of the file.
1980 */
1981 function writev(
1982 fd: number,
1983 buffers: ReadonlyArray<NodeJS.ArrayBufferView>,
1984 cb: (err: NodeJS.ErrnoException | null, bytesWritten: number, buffers: NodeJS.ArrayBufferView[]) => void
1985 ): void;
1986 function writev(
1987 fd: number,
1988 buffers: ReadonlyArray<NodeJS.ArrayBufferView>,
1989 position: number,
1990 cb: (err: NodeJS.ErrnoException | null, bytesWritten: number, buffers: NodeJS.ArrayBufferView[]) => void
1991 ): void;
1992
1993 interface WriteVResult {
1994 bytesWritten: number;
1995 buffers: NodeJS.ArrayBufferView[];
1996 }
1997
1998 namespace writev {
1999 function __promisify__(fd: number, buffers: ReadonlyArray<NodeJS.ArrayBufferView>, position?: number): Promise<WriteVResult>;
2000 }
2001
2002 /**
2003 * See `writev`.
2004 */
2005 function writevSync(fd: number, buffers: ReadonlyArray<NodeJS.ArrayBufferView>, position?: number): number;
2006
2007 interface OpenDirOptions {
2008 encoding?: BufferEncoding | undefined;
2009 }
2010
2011 function opendirSync(path: PathLike, options?: OpenDirOptions): Dir;
2012
2013 function opendir(path: PathLike, cb: (err: NodeJS.ErrnoException | null, dir: Dir) => void): void;
2014 function opendir(path: PathLike, options: OpenDirOptions, cb: (err: NodeJS.ErrnoException | null, dir: Dir) => void): void;
2015
2016 namespace opendir {
2017 function __promisify__(path: PathLike, options?: OpenDirOptions): Promise<Dir>;
2018 }
2019
2020 namespace promises {
2021 interface FileHandle {
2022 /**
2023 * Gets the file descriptor for this file handle.
2024 */
2025 readonly fd: number;
2026
2027 /**
2028 * Asynchronously append data to a file, creating the file if it does not exist. The underlying file will _not_ be closed automatically.
2029 * The `FileHandle` must have been opened for appending.
2030 * @param data The data to write. If something other than a `Buffer` or `Uint8Array` is provided, the value is coerced to a string.
2031 * @param options Either the encoding for the file, or an object optionally specifying the encoding, file mode, and flag.
2032 * If `encoding` is not supplied, the default of `'utf8'` is used.
2033 * If `mode` is not supplied, the default of `0o666` is used.
2034 * If `mode` is a string, it is parsed as an octal integer.
2035 * If `flag` is not supplied, the default of `'a'` is used.
2036 */
2037 appendFile(data: any, options?: { encoding?: string | null | undefined, mode?: string | number | undefined, flag?: string | number | undefined } | string | null): Promise<void>;
2038
2039 /**
2040 * Asynchronous fchown(2) - Change ownership of a file.
2041 */
2042 chown(uid: number, gid: number): Promise<void>;
2043
2044 /**
2045 * Asynchronous fchmod(2) - Change permissions of a file.
2046 * @param mode A file mode. If a string is passed, it is parsed as an octal integer.
2047 */
2048 chmod(mode: string | number): Promise<void>;
2049
2050 /**
2051 * Asynchronous fdatasync(2) - synchronize a file's in-core state with storage device.
2052 */
2053 datasync(): Promise<void>;
2054
2055 /**
2056 * Asynchronous fsync(2) - synchronize a file's in-core state with the underlying storage device.
2057 */
2058 sync(): Promise<void>;
2059
2060 /**
2061 * Asynchronously reads data from the file.
2062 * The `FileHandle` must have been opened for reading.
2063 * @param buffer The buffer that the data will be written to.
2064 * @param offset The offset in the buffer at which to start writing.
2065 * @param length The number of bytes to read.
2066 * @param position The offset from the beginning of the file from which data should be read. If `null`, data will be read from the current position.
2067 */
2068 read<TBuffer extends Uint8Array>(buffer: TBuffer, offset?: number | null, length?: number | null, position?: number | null): Promise<{ bytesRead: number, buffer: TBuffer }>;
2069
2070 /**
2071 * Asynchronously reads the entire contents of a file. The underlying file will _not_ be closed automatically.
2072 * The `FileHandle` must have been opened for reading.
2073 * @param options An object that may contain an optional flag.
2074 * If a flag is not provided, it defaults to `'r'`.
2075 */
2076 readFile(options?: { encoding?: null | undefined, flag?: string | number | undefined } | null): Promise<Buffer>;
2077
2078 /**
2079 * Asynchronously reads the entire contents of a file. The underlying file will _not_ be closed automatically.
2080 * The `FileHandle` must have been opened for reading.
2081 * @param options An object that may contain an optional flag.
2082 * If a flag is not provided, it defaults to `'r'`.
2083 */
2084 readFile(options: { encoding: BufferEncoding, flag?: string | number | undefined } | BufferEncoding): Promise<string>;
2085
2086 /**
2087 * Asynchronously reads the entire contents of a file. The underlying file will _not_ be closed automatically.
2088 * The `FileHandle` must have been opened for reading.
2089 * @param options An object that may contain an optional flag.
2090 * If a flag is not provided, it defaults to `'r'`.
2091 */
2092 readFile(options?: { encoding?: string | null | undefined, flag?: string | number | undefined } | string | null): Promise<string | Buffer>;
2093
2094 /**
2095 * Asynchronous fstat(2) - Get file status.
2096 */
2097 stat(opts?: StatOptions & { bigint?: false | undefined }): Promise<Stats>;
2098 stat(opts: StatOptions & { bigint: true }): Promise<BigIntStats>;
2099 stat(opts: StatOptions): Promise<Stats | BigIntStats>;
2100
2101 /**
2102 * Asynchronous ftruncate(2) - Truncate a file to a specified length.
2103 * @param len If not specified, defaults to `0`.
2104 */
2105 truncate(len?: number): Promise<void>;
2106
2107 /**
2108 * Asynchronously change file timestamps of the file.
2109 * @param atime The last access time. If a string is provided, it will be coerced to number.
2110 * @param mtime The last modified time. If a string is provided, it will be coerced to number.
2111 */
2112 utimes(atime: string | number | Date, mtime: string | number | Date): Promise<void>;
2113
2114 /**
2115 * Asynchronously writes `buffer` to the file.
2116 * The `FileHandle` must have been opened for writing.
2117 * @param buffer The buffer that the data will be written to.
2118 * @param offset The part of the buffer to be written. If not supplied, defaults to `0`.
2119 * @param length The number of bytes to write. If not supplied, defaults to `buffer.length - offset`.
2120 * @param position The offset from the beginning of the file where this data should be written. If not supplied, defaults to the current position.
2121 */
2122 write<TBuffer extends Uint8Array>(buffer: TBuffer, offset?: number | null, length?: number | null, position?: number | null): Promise<{ bytesWritten: number, buffer: TBuffer }>;
2123
2124 /**
2125 * Asynchronously writes `string` to the file.
2126 * The `FileHandle` must have been opened for writing.
2127 * It is unsafe to call `write()` multiple times on the same file without waiting for the `Promise`
2128 * to be resolved (or rejected). For this scenario, `fs.createWriteStream` is strongly recommended.
2129 * @param string A string to write. If something other than a string is supplied it will be coerced to a string.
2130 * @param position The offset from the beginning of the file where this data should be written. If not supplied, defaults to the current position.
2131 * @param encoding The expected string encoding.
2132 */
2133 write(data: any, position?: number | null, encoding?: string | null): Promise<{ bytesWritten: number, buffer: string }>;
2134
2135 /**
2136 * Asynchronously writes data to a file, replacing the file if it already exists. The underlying file will _not_ be closed automatically.
2137 * The `FileHandle` must have been opened for writing.
2138 * It is unsafe to call `writeFile()` multiple times on the same file without waiting for the `Promise` to be resolved (or rejected).
2139 * @param data The data to write. If something other than a `Buffer` or `Uint8Array` is provided, the value is coerced to a string.
2140 * @param options Either the encoding for the file, or an object optionally specifying the encoding, file mode, and flag.
2141 * If `encoding` is not supplied, the default of `'utf8'` is used.
2142 * If `mode` is not supplied, the default of `0o666` is used.
2143 * If `mode` is a string, it is parsed as an octal integer.
2144 * If `flag` is not supplied, the default of `'w'` is used.
2145 */
2146 writeFile(data: any, options?: { encoding?: string | null | undefined, mode?: string | number | undefined, flag?: string | number | undefined } | string | null): Promise<void>;
2147
2148 /**
2149 * See `fs.writev` promisified version.
2150 */
2151 writev(buffers: ReadonlyArray<NodeJS.ArrayBufferView>, position?: number): Promise<WriteVResult>;
2152
2153 /**
2154 * Asynchronous close(2) - close a `FileHandle`.
2155 */
2156 close(): Promise<void>;
2157 }
2158
2159 /**
2160 * Asynchronously tests a user's permissions for the file specified by path.
2161 * @param path A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
2162 * URL support is _experimental_.
2163 */
2164 function access(path: PathLike, mode?: number): Promise<void>;
2165
2166 /**
2167 * Asynchronously copies `src` to `dest`. By default, `dest` is overwritten if it already exists.
2168 * Node.js makes no guarantees about the atomicity of the copy operation.
2169 * If an error occurs after the destination file has been opened for writing, Node.js will attempt
2170 * to remove the destination.
2171 * @param src A path to the source file.
2172 * @param dest A path to the destination file.
2173 * @param flags An optional integer that specifies the behavior of the copy operation. The only
2174 * supported flag is `fs.constants.COPYFILE_EXCL`, which causes the copy operation to fail if
2175 * `dest` already exists.
2176 */
2177 function copyFile(src: PathLike, dest: PathLike, flags?: number): Promise<void>;
2178
2179 /**
2180 * Asynchronous open(2) - open and possibly create a file.
2181 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
2182 * @param mode A file mode. If a string is passed, it is parsed as an octal integer. If not
2183 * supplied, defaults to `0o666`.
2184 */
2185 function open(path: PathLike, flags: string | number, mode?: string | number): Promise<FileHandle>;
2186
2187 /**
2188 * Asynchronously reads data from the file referenced by the supplied `FileHandle`.
2189 * @param handle A `FileHandle`.
2190 * @param buffer The buffer that the data will be written to.
2191 * @param offset The offset in the buffer at which to start writing.
2192 * @param length The number of bytes to read.
2193 * @param position The offset from the beginning of the file from which data should be read. If
2194 * `null`, data will be read from the current position.
2195 */
2196 function read<TBuffer extends Uint8Array>(
2197 handle: FileHandle,
2198 buffer: TBuffer,
2199 offset?: number | null,
2200 length?: number | null,
2201 position?: number | null,
2202 ): Promise<{ bytesRead: number, buffer: TBuffer }>;
2203
2204 /**
2205 * Asynchronously writes `buffer` to the file referenced by the supplied `FileHandle`.
2206 * It is unsafe to call `fsPromises.write()` multiple times on the same file without waiting for the `Promise`
2207 * to be resolved (or rejected). For this scenario, `fs.createWriteStream` is strongly recommended.
2208 * @param handle A `FileHandle`.
2209 * @param buffer The buffer that the data will be written to.
2210 * @param offset The part of the buffer to be written. If not supplied, defaults to `0`.
2211 * @param length The number of bytes to write. If not supplied, defaults to `buffer.length - offset`.
2212 * @param position The offset from the beginning of the file where this data should be written. If not supplied, defaults to the current position.
2213 */
2214 function write<TBuffer extends Uint8Array>(
2215 handle: FileHandle,
2216 buffer: TBuffer,
2217 offset?: number | null,
2218 length?: number | null, position?: number | null): Promise<{ bytesWritten: number, buffer: TBuffer }>;
2219
2220 /**
2221 * Asynchronously writes `string` to the file referenced by the supplied `FileHandle`.
2222 * It is unsafe to call `fsPromises.write()` multiple times on the same file without waiting for the `Promise`
2223 * to be resolved (or rejected). For this scenario, `fs.createWriteStream` is strongly recommended.
2224 * @param handle A `FileHandle`.
2225 * @param string A string to write. If something other than a string is supplied it will be coerced to a string.
2226 * @param position The offset from the beginning of the file where this data should be written. If not supplied, defaults to the current position.
2227 * @param encoding The expected string encoding.
2228 */
2229 function write(handle: FileHandle, string: any, position?: number | null, encoding?: string | null): Promise<{ bytesWritten: number, buffer: string }>;
2230
2231 /**
2232 * Asynchronous rename(2) - Change the name or location of a file or directory.
2233 * @param oldPath A path to a file. If a URL is provided, it must use the `file:` protocol.
2234 * URL support is _experimental_.
2235 * @param newPath A path to a file. If a URL is provided, it must use the `file:` protocol.
2236 * URL support is _experimental_.
2237 */
2238 function rename(oldPath: PathLike, newPath: PathLike): Promise<void>;
2239
2240 /**
2241 * Asynchronous truncate(2) - Truncate a file to a specified length.
2242 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
2243 * @param len If not specified, defaults to `0`.
2244 */
2245 function truncate(path: PathLike, len?: number): Promise<void>;
2246
2247 /**
2248 * Asynchronous ftruncate(2) - Truncate a file to a specified length.
2249 * @param handle A `FileHandle`.
2250 * @param len If not specified, defaults to `0`.
2251 */
2252 function ftruncate(handle: FileHandle, len?: number): Promise<void>;
2253
2254 /**
2255 * Asynchronous rmdir(2) - delete a directory.
2256 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
2257 */
2258 function rmdir(path: PathLike, options?: RmDirOptions): Promise<void>;
2259
2260 /**
2261 * Asynchronous fdatasync(2) - synchronize a file's in-core state with storage device.
2262 * @param handle A `FileHandle`.
2263 */
2264 function fdatasync(handle: FileHandle): Promise<void>;
2265
2266 /**
2267 * Asynchronous fsync(2) - synchronize a file's in-core state with the underlying storage device.
2268 * @param handle A `FileHandle`.
2269 */
2270 function fsync(handle: FileHandle): Promise<void>;
2271
2272 /**
2273 * Asynchronous mkdir(2) - create a directory.
2274 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
2275 * @param options Either the file mode, or an object optionally specifying the file mode and whether parent folders
2276 * should be created. If a string is passed, it is parsed as an octal integer. If not specified, defaults to `0o777`.
2277 */
2278 function mkdir(path: PathLike, options?: number | string | MakeDirectoryOptions | null): Promise<void>;
2279
2280 /**
2281 * Asynchronous readdir(3) - read a directory.
2282 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
2283 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
2284 */
2285 function readdir(path: PathLike, options?: { encoding?: BufferEncoding | null | undefined; withFileTypes?: false | undefined } | BufferEncoding | null): Promise<string[]>;
2286
2287 /**
2288 * Asynchronous readdir(3) - read a directory.
2289 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
2290 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
2291 */
2292 function readdir(path: PathLike, options: { encoding: "buffer"; withFileTypes?: false | undefined } | "buffer"): Promise<Buffer[]>;
2293
2294 /**
2295 * Asynchronous readdir(3) - read a directory.
2296 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
2297 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
2298 */
2299 function readdir(path: PathLike, options?: { encoding?: string | null | undefined; withFileTypes?: false | undefined } | string | null): Promise<string[] | Buffer[]>;
2300
2301 /**
2302 * Asynchronous readdir(3) - read a directory.
2303 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
2304 * @param options If called with `withFileTypes: true` the result data will be an array of Dirent.
2305 */
2306 function readdir(path: PathLike, options: { encoding?: string | null | undefined; withFileTypes: true }): Promise<Dirent[]>;
2307
2308 /**
2309 * Asynchronous readlink(2) - read value of a symbolic link.
2310 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
2311 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
2312 */
2313 function readlink(path: PathLike, options?: { encoding?: BufferEncoding | null | undefined } | BufferEncoding | null): Promise<string>;
2314
2315 /**
2316 * Asynchronous readlink(2) - read value of a symbolic link.
2317 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
2318 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
2319 */
2320 function readlink(path: PathLike, options: { encoding: "buffer" } | "buffer"): Promise<Buffer>;
2321
2322 /**
2323 * Asynchronous readlink(2) - read value of a symbolic link.
2324 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
2325 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
2326 */
2327 function readlink(path: PathLike, options?: { encoding?: string | null | undefined } | string | null): Promise<string | Buffer>;
2328
2329 /**
2330 * Asynchronous symlink(2) - Create a new symbolic link to an existing file.
2331 * @param target A path to an existing file. If a URL is provided, it must use the `file:` protocol.
2332 * @param path A path to the new symlink. If a URL is provided, it must use the `file:` protocol.
2333 * @param type May be set to `'dir'`, `'file'`, or `'junction'` (default is `'file'`) and is only available on Windows (ignored on other platforms).
2334 * When using `'junction'`, the `target` argument will automatically be normalized to an absolute path.
2335 */
2336 function symlink(target: PathLike, path: PathLike, type?: string | null): Promise<void>;
2337
2338 /**
2339 * Asynchronous lstat(2) - Get file status. Does not dereference symbolic links.
2340 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
2341 */
2342 function lstat(path: PathLike, opts?: StatOptions & { bigint?: false | undefined }): Promise<Stats>;
2343 function lstat(path: PathLike, opts: StatOptions & { bigint: true }): Promise<BigIntStats>;
2344 function lstat(path: PathLike, opts?: StatOptions): Promise<Stats | BigIntStats>;
2345
2346 /**
2347 * Asynchronous stat(2) - Get file status.
2348 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
2349 */
2350 function stat(path: PathLike, opts?: StatOptions & { bigint?: false | undefined }): Promise<Stats>;
2351 function stat(path: PathLike, opts: StatOptions & { bigint: true }): Promise<BigIntStats>;
2352 function stat(path: PathLike, opts?: StatOptions): Promise<Stats | BigIntStats>;
2353
2354 /**
2355 * Asynchronous link(2) - Create a new link (also known as a hard link) to an existing file.
2356 * @param existingPath A path to a file. If a URL is provided, it must use the `file:` protocol.
2357 * @param newPath A path to a file. If a URL is provided, it must use the `file:` protocol.
2358 */
2359 function link(existingPath: PathLike, newPath: PathLike): Promise<void>;
2360
2361 /**
2362 * Asynchronous unlink(2) - delete a name and possibly the file it refers to.
2363 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
2364 */
2365 function unlink(path: PathLike): Promise<void>;
2366
2367 /**
2368 * Asynchronous fchmod(2) - Change permissions of a file.
2369 * @param handle A `FileHandle`.
2370 * @param mode A file mode. If a string is passed, it is parsed as an octal integer.
2371 */
2372 function fchmod(handle: FileHandle, mode: string | number): Promise<void>;
2373
2374 /**
2375 * Asynchronous chmod(2) - Change permissions of a file.
2376 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
2377 * @param mode A file mode. If a string is passed, it is parsed as an octal integer.
2378 */
2379 function chmod(path: PathLike, mode: string | number): Promise<void>;
2380
2381 /**
2382 * Asynchronous lchmod(2) - Change permissions of a file. Does not dereference symbolic links.
2383 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
2384 * @param mode A file mode. If a string is passed, it is parsed as an octal integer.
2385 */
2386 function lchmod(path: PathLike, mode: string | number): Promise<void>;
2387
2388 /**
2389 * Asynchronous lchown(2) - Change ownership of a file. Does not dereference symbolic links.
2390 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
2391 */
2392 function lchown(path: PathLike, uid: number, gid: number): Promise<void>;
2393
2394 /**
2395 * Changes the access and modification times of a file in the same way as `fsPromises.utimes()`,
2396 * with the difference that if the path refers to a symbolic link, then the link is not
2397 * dereferenced: instead, the timestamps of the symbolic link itself are changed.
2398 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
2399 * @param atime The last access time. If a string is provided, it will be coerced to number.
2400 * @param mtime The last modified time. If a string is provided, it will be coerced to number.
2401 */
2402 function lutimes(path: PathLike, atime: string | number | Date, mtime: string | number | Date): Promise<void>;
2403
2404 /**
2405 * Asynchronous fchown(2) - Change ownership of a file.
2406 * @param handle A `FileHandle`.
2407 */
2408 function fchown(handle: FileHandle, uid: number, gid: number): Promise<void>;
2409
2410 /**
2411 * Asynchronous chown(2) - Change ownership of a file.
2412 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
2413 */
2414 function chown(path: PathLike, uid: number, gid: number): Promise<void>;
2415
2416 /**
2417 * Asynchronously change file timestamps of the file referenced by the supplied path.
2418 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
2419 * @param atime The last access time. If a string is provided, it will be coerced to number.
2420 * @param mtime The last modified time. If a string is provided, it will be coerced to number.
2421 */
2422 function utimes(path: PathLike, atime: string | number | Date, mtime: string | number | Date): Promise<void>;
2423
2424 /**
2425 * Asynchronously change file timestamps of the file referenced by the supplied `FileHandle`.
2426 * @param handle A `FileHandle`.
2427 * @param atime The last access time. If a string is provided, it will be coerced to number.
2428 * @param mtime The last modified time. If a string is provided, it will be coerced to number.
2429 */
2430 function futimes(handle: FileHandle, atime: string | number | Date, mtime: string | number | Date): Promise<void>;
2431
2432 /**
2433 * Asynchronous realpath(3) - return the canonicalized absolute pathname.
2434 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
2435 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
2436 */
2437 function realpath(path: PathLike, options?: { encoding?: BufferEncoding | null | undefined } | BufferEncoding | null): Promise<string>;
2438
2439 /**
2440 * Asynchronous realpath(3) - return the canonicalized absolute pathname.
2441 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
2442 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
2443 */
2444 function realpath(path: PathLike, options: { encoding: "buffer" } | "buffer"): Promise<Buffer>;
2445
2446 /**
2447 * Asynchronous realpath(3) - return the canonicalized absolute pathname.
2448 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
2449 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
2450 */
2451 function realpath(path: PathLike, options?: { encoding?: string | null | undefined } | string | null): Promise<string | Buffer>;
2452
2453 /**
2454 * Asynchronously creates a unique temporary directory.
2455 * Generates six random characters to be appended behind a required `prefix` to create a unique temporary directory.
2456 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
2457 */
2458 function mkdtemp(prefix: string, options?: { encoding?: BufferEncoding | null | undefined } | BufferEncoding | null): Promise<string>;
2459
2460 /**
2461 * Asynchronously creates a unique temporary directory.
2462 * Generates six random characters to be appended behind a required `prefix` to create a unique temporary directory.
2463 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
2464 */
2465 function mkdtemp(prefix: string, options: { encoding: "buffer" } | "buffer"): Promise<Buffer>;
2466
2467 /**
2468 * Asynchronously creates a unique temporary directory.
2469 * Generates six random characters to be appended behind a required `prefix` to create a unique temporary directory.
2470 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
2471 */
2472 function mkdtemp(prefix: string, options?: { encoding?: string | null | undefined } | string | null): Promise<string | Buffer>;
2473
2474 /**
2475 * Asynchronously writes data to a file, replacing the file if it already exists.
2476 * It is unsafe to call `fsPromises.writeFile()` multiple times on the same file without waiting for the `Promise` to be resolved (or rejected).
2477 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
2478 * URL support is _experimental_.
2479 * If a `FileHandle` is provided, the underlying file will _not_ be closed automatically.
2480 * @param data The data to write. If something other than a `Buffer` or `Uint8Array` is provided, the value is coerced to a string.
2481 * @param options Either the encoding for the file, or an object optionally specifying the encoding, file mode, and flag.
2482 * If `encoding` is not supplied, the default of `'utf8'` is used.
2483 * If `mode` is not supplied, the default of `0o666` is used.
2484 * If `mode` is a string, it is parsed as an octal integer.
2485 * If `flag` is not supplied, the default of `'w'` is used.
2486 */
2487 function writeFile(
2488 path: PathLike | FileHandle,
2489 data: any,
2490 options?: { encoding?: string | null | undefined, mode?: string | number | undefined, flag?: string | number | undefined } | string | null
2491 ): Promise<void>;
2492
2493 /**
2494 * Asynchronously append data to a file, creating the file if it does not exist.
2495 * @param file A path to a file. If a URL is provided, it must use the `file:` protocol.
2496 * URL support is _experimental_.
2497 * If a `FileHandle` is provided, the underlying file will _not_ be closed automatically.
2498 * @param data The data to write. If something other than a `Buffer` or `Uint8Array` is provided, the value is coerced to a string.
2499 * @param options Either the encoding for the file, or an object optionally specifying the encoding, file mode, and flag.
2500 * If `encoding` is not supplied, the default of `'utf8'` is used.
2501 * If `mode` is not supplied, the default of `0o666` is used.
2502 * If `mode` is a string, it is parsed as an octal integer.
2503 * If `flag` is not supplied, the default of `'a'` is used.
2504 */
2505 function appendFile(
2506 path: PathLike | FileHandle,
2507 data: any,
2508 options?: { encoding?: string | null | undefined, mode?: string | number | undefined, flag?: string | number | undefined } | string | null
2509 ): Promise<void>;
2510
2511 /**
2512 * Asynchronously reads the entire contents of a file.
2513 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
2514 * If a `FileHandle` is provided, the underlying file will _not_ be closed automatically.
2515 * @param options An object that may contain an optional flag.
2516 * If a flag is not provided, it defaults to `'r'`.
2517 */
2518 function readFile(path: PathLike | FileHandle, options?: { encoding?: null | undefined, flag?: string | number | undefined } | null): Promise<Buffer>;
2519
2520 /**
2521 * Asynchronously reads the entire contents of a file.
2522 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
2523 * If a `FileHandle` is provided, the underlying file will _not_ be closed automatically.
2524 * @param options An object that may contain an optional flag.
2525 * If a flag is not provided, it defaults to `'r'`.
2526 */
2527 function readFile(path: PathLike | FileHandle, options: { encoding: BufferEncoding, flag?: string | number | undefined } | BufferEncoding): Promise<string>;
2528
2529 /**
2530 * Asynchronously reads the entire contents of a file.
2531 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
2532 * If a `FileHandle` is provided, the underlying file will _not_ be closed automatically.
2533 * @param options An object that may contain an optional flag.
2534 * If a flag is not provided, it defaults to `'r'`.
2535 */
2536 function readFile(path: PathLike | FileHandle, options?: { encoding?: string | null | undefined, flag?: string | number | undefined } | string | null): Promise<string | Buffer>;
2537
2538 function opendir(path: PathLike, options?: OpenDirOptions): Promise<Dir>;
2539 }
2540
2541 interface BigIntStats extends StatsBase<bigint> {
2542 }
2543
2544 class BigIntStats {
2545 atimeNs: bigint;
2546 mtimeNs: bigint;
2547 ctimeNs: bigint;
2548 birthtimeNs: bigint;
2549 }
2550
2551 interface BigIntOptions {
2552 bigint: true;
2553 }
2554
2555 interface StatOptions {
2556 bigint: boolean;
2557 }
2558}