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