UNPKG

57 kBTypeScriptView Raw
1// Modified from the node.js definitions.
2// https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/node/fs.d.ts
3
4import {
5 Dirent,
6 FSWatcher,
7 MakeDirectoryOptions,
8 NoParamCallback,
9 PathLike,
10 RmDirOptions,
11 Stats,
12 symlink as symlinkNS,
13 WriteFileOptions,
14} from "fs";
15export * from "fs";
16
17/**
18 * Asynchronous `rename(2)`.
19 *
20 * Change the name or location of a file or directory.
21 *
22 * @param oldPath A path to a file. If a URL is provided, it must use the `file:` protocol.
23 * URL support is _experimental_.
24 * @param newPath A path to a file. If a URL is provided, it must use the `file:` protocol.
25 * URL support is _experimental_.
26 */
27export function rename(oldPath: PathLike, newPath: PathLike, callback: NoParamCallback): void;
28
29/**
30 * Asynchronous `rename(2)`.
31 *
32 * Change the name or location of a file or directory.
33 *
34 * @param oldPath A path to a file. If a URL is provided, it must use the `file:` protocol.
35 * URL support is _experimental_.
36 * @param newPath A path to a file. If a URL is provided, it must use the `file:` protocol.
37 * URL support is _experimental_.
38 */
39export function rename(oldPath: PathLike, newPath: PathLike): Promise<void>;
40
41/**
42 * Asynchronous `truncate(2)`.
43 *
44 * Truncate a file to a specified length.
45 *
46 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
47 * @param len If not specified, defaults to `0`.
48 */
49export function truncate(path: PathLike, len: number | null | undefined, callback: NoParamCallback): void;
50
51/**
52 * Asynchronous `truncate(2)`.
53 *
54 * Truncate a file to a specified length.
55 *
56 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
57 * URL support is _experimental_.
58 */
59export function truncate(path: PathLike, callback: NoParamCallback): void;
60
61/**
62 * Asynchronous `truncate(2)`.
63 *
64 * Truncate a file to a specified length.
65 *
66 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
67 * @param len If not specified, defaults to `0`.
68 */
69export function truncate(path: PathLike, len?: number | null): Promise<void>;
70
71/**
72 * Asynchronous `ftruncate(2)`.
73 *
74 * Truncate a file to a specified length.
75 *
76 * @param fd A file descriptor.
77 * @param len If not specified, defaults to `0`.
78 */
79export function ftruncate(fd: number, len: number | null | undefined, callback: NoParamCallback): void;
80
81/**
82 * Asynchronous `ftruncate(2)`.
83 *
84 * Truncate a file to a specified length.
85 *
86 * @param fd A file descriptor.
87 */
88export function ftruncate(fd: number, callback: NoParamCallback): void;
89
90/**
91 * Asynchronous `ftruncate(2)`.
92 *
93 * Truncate a file to a specified length.
94 *
95 * @param fd A file descriptor.
96 * @param len If not specified, defaults to `0`.
97 */
98export function ftruncate(fd: number, len?: number | null): Promise<void>;
99
100/**
101 * Asynchronous `chown(2)`.
102 *
103 * Change ownership of a file.
104 *
105 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
106 */
107export function chown(path: PathLike, uid: number, gid: number, callback: NoParamCallback): void;
108
109/**
110 * Asynchronous `chown(2)`.
111 *
112 * Change ownership of a file.
113 *
114 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
115 */
116export function chown(path: PathLike, uid: number, gid: number): Promise<void>;
117
118/**
119 * Asynchronous `fchown(2)`.
120 *
121 * Change ownership of a file.
122 *
123 * @param fd A file descriptor.
124 */
125export function fchown(fd: number, uid: number, gid: number, callback: NoParamCallback): void;
126export function fchown(fd: number, uid: number, gid: number, callback: NoParamCallback): void;
127
128/**
129 * Asynchronous `fchown(2)`.
130 *
131 * Change ownership of a file.
132 *
133 * @param fd A file descriptor.
134 */
135export function fchown(fd: number, uid: number, gid: number): Promise<void>;
136
137/**
138 * Asynchronous `lchown(2)`.
139 *
140 * Change ownership of a file. Does not dereference symbolic links.
141 *
142 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
143 */
144export function lchown(path: PathLike, uid: number, gid: number, callback: NoParamCallback): void;
145
146/**
147 * Asynchronous `lchown(2)`.
148 *
149 * Change ownership of a file. Does not dereference symbolic links.
150 *
151 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
152 */
153export function lchown(path: PathLike, uid: number, gid: number): Promise<void>;
154
155/**
156 * Asynchronous `chmod(2)`.
157 *
158 * Change permissions of a file.
159 *
160 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
161 * @param mode A file mode. If a string is passed, it is parsed as an octal integer.
162 */
163export function chmod(path: PathLike, mode: string | number, callback: NoParamCallback): void;
164
165/**
166 * Asynchronous `chmod(2)`.
167 *
168 * Change permissions of a file.
169 *
170 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
171 * @param mode A file mode. If a string is passed, it is parsed as an octal integer.
172 */
173export function chmod(path: PathLike, mode: string | number): Promise<void>;
174
175/**
176 * Asynchronous `fchmod(2)`.
177 *
178 * Change permissions of a file.
179 *
180 * @param fd A file descriptor.
181 * @param mode A file mode. If a string is passed, it is parsed as an octal integer.
182 */
183export function fchmod(fd: number, mode: string | number, callback: NoParamCallback): void;
184
185/**
186 * Asynchronous `fchmod(2)`.
187 *
188 * Change permissions of a file.
189 *
190 * @param fd A file descriptor.
191 * @param mode A file mode. If a string is passed, it is parsed as an octal integer.
192 */
193export function fchmod(fd: number, mode: string | number): Promise<void>;
194
195/**
196 * Asynchronous `lchmod(2)`.
197 *
198 * Change permissions of a file. Does not dereference symbolic links.
199 *
200 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
201 * @param mode A file mode. If a string is passed, it is parsed as an octal integer.
202 */
203export function lchmod(path: PathLike, mode: string | number, callback: NoParamCallback): void;
204
205/**
206 * Asynchronous `lchmod(2)`.
207 *
208 * Change permissions of a file. Does not dereference symbolic links.
209 *
210 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
211 * @param mode A file mode. If a string is passed, it is parsed as an octal integer.
212 */
213export function lchmod(path: PathLike, mode: string | number): Promise<void>;
214
215/**
216 * Asynchronous `stat(2)`.
217 *
218 * Get file status.
219 *
220 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
221 */
222export function stat(path: PathLike, callback: (err: NodeJS.ErrnoException | null, stats: Stats) => void): void;
223
224/**
225 * Asynchronous `stat(2)`.
226 *
227 * Get file status.
228 *
229 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
230 */
231export function stat(path: PathLike): Promise<Stats>;
232
233/**
234 * Asynchronous `fstat(2)`.
235 *
236 * Get file status.
237 *
238 * @param fd A file descriptor.
239 */
240export function fstat(fd: number, callback: (err: NodeJS.ErrnoException | null, stats: Stats) => void): void;
241
242/**
243 * Asynchronous `fstat(2)`.
244 *
245 * Get file status.
246 *
247 * @param fd A file descriptor.
248 */
249export function fstat(fd: number): Promise<Stats>;
250
251/**
252 * Synchronous fstat(2) - Get file status.
253 * @param fd A file descriptor.
254 */
255export function fstatSync(fd: number): Stats;
256
257/**
258 * Asynchronous `lstat(2)`.
259 *
260 * Get file status. Does not dereference symbolic links.
261 *
262 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
263 */
264export function lstat(path: PathLike, callback: (err: NodeJS.ErrnoException | null, stats: Stats) => void): void;
265
266/**
267 * Asynchronous `lstat(2)`.
268 *
269 * Get file status. Does not dereference symbolic links.
270 *
271 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
272 */
273export function lstat(path: PathLike): Promise<Stats>;
274
275/**
276 * Asynchronous `link(2)`.
277 *
278 * Create a new link (also known as a hard link) to an existing file.
279 *
280 * @param existingPath A path to a file. If a URL is provided, it must use the `file:` protocol.
281 * @param newPath A path to a file. If a URL is provided, it must use the `file:` protocol.
282 */
283export function link(existingPath: PathLike, newPath: PathLike, callback: NoParamCallback): void;
284
285/**
286 * Asynchronous `link(2)`.
287 *
288 * Create a new link (also known as a hard link) to an existing file.
289 *
290 * @param existingPath A path to a file. If a URL is provided, it must use the `file:` protocol.
291 * @param newPath A path to a file. If a URL is provided, it must use the `file:` protocol.
292 */
293export function link(existingPath: PathLike, newPath: PathLike): Promise<void>;
294
295/**
296 * Asynchronous `symlink(2)`.
297 *
298 * Create a new symbolic link to an existing file.
299 *
300 * @param target A path to an existing file. If a URL is provided, it must use the `file:` protocol.
301 * @param path A path to the new symlink. If a URL is provided, it must use the `file:` protocol.
302 * @param type May be set to `'dir'`, `'file'`, or `'junction'` (default is `'file'`) and is only available on Windows (ignored on other platforms).
303 * When using `'junction'`, the `target` argument will automatically be normalized to an absolute path.
304 */
305export function symlink(
306 target: PathLike,
307 path: PathLike,
308 type: symlinkNS.Type | null | undefined,
309 callback: NoParamCallback,
310): void;
311
312/**
313 * Asynchronous `symlink(2)`.
314 *
315 * Create a new symbolic link to an existing file.
316 *
317 * @param target A path to an existing file. If a URL is provided, it must use the `file:` protocol.
318 * @param path A path to the new symlink. If a URL is provided, it must use the `file:` protocol.
319 */
320export function symlink(target: PathLike, path: PathLike, callback: NoParamCallback): void;
321
322/**
323 * Asynchronous `symlink(2)`.
324 *
325 * Create a new symbolic link to an existing file.
326 *
327 * @param target A path to an existing file. If a URL is provided, it must use the `file:` protocol.
328 * @param path A path to the new symlink. If a URL is provided, it must use the `file:` protocol.
329 * @param type May be set to `'dir'`, `'file'`, or `'junction'` (default is `'file'`) and is only available on Windows (ignored on other platforms).
330 * When using `'junction'`, the `target` argument will automatically be normalized to an absolute path.
331 */
332export function symlink(target: PathLike, path: PathLike, type?: string | null): Promise<void>;
333
334/**
335 * Asynchronous `readlink(2)`.
336 *
337 * read value of a symbolic link.
338 *
339 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
340 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
341 */
342export function readlink(
343 path: PathLike,
344 options: { encoding?: BufferEncoding | null | undefined } | BufferEncoding | null | undefined,
345 callback: (err: NodeJS.ErrnoException | null, linkString: string) => void,
346): void;
347
348/**
349 * Asynchronous `readlink(2)`.
350 *
351 * read value of a symbolic link.
352 *
353 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
354 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
355 */
356export function readlink(
357 path: PathLike,
358 options: { encoding: "buffer" } | "buffer",
359 callback: (err: NodeJS.ErrnoException | null, linkString: Buffer) => void,
360): void;
361
362/**
363 * Asynchronous `readlink(2)`.
364 *
365 * read value of a symbolic link.
366 *
367 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
368 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
369 */
370export function readlink(
371 path: PathLike,
372 options: { encoding?: string | null | undefined } | string | null | undefined,
373 callback: (err: NodeJS.ErrnoException | null, linkString: string | Buffer) => void,
374): void;
375
376/**
377 * Asynchronous `readlink(2)`.
378 *
379 * read value of a symbolic link.
380 *
381 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
382 */
383export function readlink(
384 path: PathLike,
385 callback: (err: NodeJS.ErrnoException | null, linkString: string) => void,
386): void;
387
388/**
389 * Asynchronous `readlink(2)`.
390 *
391 * read value of a symbolic link.
392 *
393 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
394 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
395 */
396export function readlink(
397 path: PathLike,
398 options?: { encoding?: BufferEncoding | null | undefined } | BufferEncoding | null,
399): Promise<string>;
400
401/**
402 * Asynchronous `readlink(2)`.
403 *
404 * read value of a symbolic link.
405 *
406 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
407 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
408 */
409export function readlink(path: PathLike, options: { encoding: "buffer" } | "buffer"): Promise<Buffer>;
410
411/**
412 * Asynchronous `readlink(2)`.
413 *
414 * read value of a symbolic link.
415 *
416 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
417 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
418 */
419export function readlink(
420 path: PathLike,
421 options?: { encoding?: string | null | undefined } | string | null,
422): Promise<string | Buffer>;
423
424/**
425 * Asynchronous `realpath(3)`.
426 *
427 * return the canonicalized absolute pathname.
428 *
429 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
430 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
431 */
432export function realpath(
433 path: PathLike,
434 options: { encoding?: BufferEncoding | null | undefined } | BufferEncoding | null | undefined,
435 callback: (err: NodeJS.ErrnoException | null, resolvedPath: string) => void,
436): void;
437
438/**
439 * Asynchronous `realpath(3)`.
440 *
441 * return the canonicalized absolute pathname.
442 *
443 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
444 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
445 */
446export function realpath(
447 path: PathLike,
448 options: { encoding: "buffer" } | "buffer",
449 callback: (err: NodeJS.ErrnoException | null, resolvedPath: Buffer) => void,
450): void;
451
452/**
453 * Asynchronous `realpath(3)`.
454 *
455 * return the canonicalized absolute pathname.
456 *
457 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
458 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
459 */
460export function realpath(
461 path: PathLike,
462 options: { encoding?: string | null | undefined } | string | null | undefined,
463 callback: (err: NodeJS.ErrnoException | null, resolvedPath: string | Buffer) => void,
464): void;
465
466/**
467 * Asynchronous `realpath(3)`.
468 *
469 * return the canonicalized absolute pathname.
470 *
471 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
472 */
473export function realpath(
474 path: PathLike,
475 callback: (err: NodeJS.ErrnoException | null, resolvedPath: string) => void,
476): void;
477
478/**
479 * Asynchronous `realpath(3)`.
480 *
481 * return the canonicalized absolute pathname.
482 *
483 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
484 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
485 */
486export function realpath(
487 path: PathLike,
488 options?: { encoding?: BufferEncoding | null | undefined } | BufferEncoding | null,
489): Promise<string>;
490
491/**
492 * Asynchronous `realpath(3)`.
493 *
494 * return the canonicalized absolute pathname.
495 *
496 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
497 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
498 */
499export function realpath(path: PathLike, options: { encoding: "buffer" } | "buffer"): Promise<Buffer>;
500
501/**
502 * Asynchronous `realpath(3)`.
503 *
504 * return the canonicalized absolute pathname.
505 *
506 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
507 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
508 */
509export function realpath(
510 path: PathLike,
511 options?: { encoding?: string | null | undefined } | string | null,
512): Promise<string | Buffer>;
513
514export namespace realpath {
515 function native(
516 path: PathLike,
517 options: { encoding?: BufferEncoding | null | undefined } | BufferEncoding | null | undefined,
518 callback: (err: NodeJS.ErrnoException | null, resolvedPath: string) => void,
519 ): void;
520 function native(
521 path: PathLike,
522 options: { encoding: "buffer" } | "buffer",
523 callback: (err: NodeJS.ErrnoException | null, resolvedPath: Buffer) => void,
524 ): void;
525 function native(
526 path: PathLike,
527 options: { encoding?: string | null | undefined } | string | null | undefined,
528 callback: (err: NodeJS.ErrnoException | null, resolvedPath: string | Buffer) => void,
529 ): void;
530 function native(path: PathLike, callback: (err: NodeJS.ErrnoException | null, resolvedPath: string) => void): void;
531
532 function native(
533 path: PathLike,
534 options?: { encoding?: BufferEncoding | null | undefined } | BufferEncoding | null,
535 ): Promise<string>;
536 function native(path: PathLike, options: { encoding: "buffer" } | "buffer"): Promise<Buffer>;
537 function native(
538 path: PathLike,
539 options: { encoding?: string | null | undefined } | string | null | undefined,
540 ): Promise<string | Buffer>;
541}
542
543/**
544 * Asynchronous `unlink(2)`.
545 *
546 * delete a name and possibly the file it refers to.
547 *
548 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
549 */
550export function unlink(path: PathLike, callback: NoParamCallback): void;
551
552/**
553 * Asynchronous `unlink(2)`.
554 *
555 * delete a name and possibly the file it refers to.
556 *
557 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
558 */
559export function unlink(path: PathLike): Promise<void>;
560
561/**
562 * Asynchronous `rmdir(2)`
563 *
564 * Removes the directory specified in `path`.
565 *
566 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
567 */
568export function rmdir(path: PathLike, callback: NoParamCallback): void;
569
570/**
571 * Asynchronous `rmdir(2)`.
572 *
573 * Removes the directory specified in `path`.
574 *
575 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
576 */
577export function rmdir(path: PathLike, options: RmDirOptions, callback: NoParamCallback): void;
578
579/**
580 * Asynchronous `rmdir(2)`
581 *
582 * Removes the directory specified in `path`.
583 *
584 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
585 */
586export function rmdir(path: PathLike, options?: RmDirOptions): Promise<void>;
587
588/**
589 * Asynchronous `mkdir(2)`.
590 *
591 * Creates the directory specified in `path`.
592 *
593 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
594 * @param options Either the file mode, or an object optionally specifying the file mode and whether parent folders
595 * should be created. If a string is passed, it is parsed as an octal integer. If not specified, defaults to `0o777`.
596 */
597export function mkdir(
598 path: PathLike,
599 options: number | string | MakeDirectoryOptions | null | undefined,
600 callback: NoParamCallback,
601): void;
602
603/**
604 * Asynchronous `mkdir(2)`.
605 *
606 * Creates the directory with a mode of `0o777`.
607 *
608 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
609 */
610export function mkdir(path: PathLike, callback: NoParamCallback): void;
611
612/**
613 * Asynchronous `mkdir(2)`.
614 *
615 * Creates the directory specified in `path`.
616 *
617 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
618 * @param options Either the file mode, or an object optionally specifying the file mode and whether parent folders
619 * should be created. If a string is passed, it is parsed as an octal integer. If not specified, defaults to `0o777`.
620 */
621export function mkdir(path: PathLike, options?: number | string | MakeDirectoryOptions | null): Promise<void>;
622
623/**
624 * Creates a unique temporary directory.
625 *
626 * Generates six random characters to be appended behind a required prefix to create a unique temporary directory.
627 *
628 * @param prefix temp dir prefix
629 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
630 */
631export function mkdtemp(
632 prefix: string,
633 options: { encoding?: BufferEncoding | null | undefined } | BufferEncoding | null | undefined,
634 callback: (err: NodeJS.ErrnoException | null, folder: string) => void,
635): void;
636
637/**
638 * Creates a unique temporary directory.
639 *
640 * Generates six random characters to be appended behind a required prefix to create a unique temporary directory.
641 *
642 * @param prefix temp dir prefix
643 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
644 */
645export function mkdtemp(
646 prefix: string,
647 options: "buffer" | { encoding: "buffer" },
648 callback: (err: NodeJS.ErrnoException | null, folder: Buffer) => void,
649): void;
650
651/**
652 * Creates a unique temporary directory.
653 *
654 * Generates six random characters to be appended behind a required prefix to create a unique temporary directory.
655 *
656 * @param prefix temp dir prefix
657 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
658 */
659export function mkdtemp(
660 prefix: string,
661 options: { encoding?: string | null | undefined } | string | null | undefined,
662 callback: (err: NodeJS.ErrnoException | null, folder: string | Buffer) => void,
663): void;
664
665/**
666 * Creates a unique temporary directory.
667 *
668 * Generates six random characters to be appended behind a required prefix to create a unique temporary directory.
669 *
670 * @param prefix temp dir prefix
671 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
672 */
673export function mkdtemp(prefix: string, callback: (err: NodeJS.ErrnoException | null, folder: string) => void): void;
674
675/***
676 * Creates a unique temporary directory.
677 *
678 * Generates six random characters to be appended behind a required prefix to create a unique temporary directory.
679 *
680 * @param prefix temp dir prefix
681 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
682 */
683export function mkdtemp(
684 prefix: string,
685 options?: { encoding?: BufferEncoding | null | undefined } | BufferEncoding | null,
686): Promise<string>;
687
688/***
689 * Creates a unique temporary directory.
690 *
691 * Generates six random characters to be appended behind a required prefix to create a unique temporary directory.
692 *
693 * @param prefix temp dir prefix
694 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
695 */
696export function mkdtemp(prefix: string, options: { encoding: "buffer" } | "buffer"): Promise<Buffer>;
697
698/***
699 * Creates a unique temporary directory.
700 *
701 * Generates six random characters to be appended behind a required prefix to create a unique temporary directory.
702 *
703 * @param prefix temp dir prefix
704 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
705 */
706export function mkdtemp(
707 prefix: string,
708 options?: { encoding?: string | null | undefined } | string | null,
709): Promise<string | Buffer>;
710
711/**
712 * Asynchronous `readdir(3)`.
713 *
714 * Reads the contents of a directory.
715 *
716 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
717 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
718 */
719export function readdir(
720 path: PathLike,
721 options: { encoding: BufferEncoding | null; withFileTypes?: false | undefined } | BufferEncoding | null | undefined,
722 callback: (err: NodeJS.ErrnoException | null, files: string[]) => void,
723): void;
724
725/**
726 * Asynchronous `readdir(3)`.
727 *
728 * Reads the contents of a directory.
729 *
730 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
731 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
732 */
733export function readdir(
734 path: PathLike,
735 options: { encoding: "buffer"; withFileTypes?: false | undefined } | "buffer",
736 callback: (err: NodeJS.ErrnoException | null, files: Buffer[]) => void,
737): void;
738
739/**
740 * Asynchronous `readdir(3)`.
741 *
742 * Reads the contents of a directory.
743 *
744 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
745 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
746 */
747export function readdir(
748 path: PathLike,
749 options: { encoding?: string | null | undefined; withFileTypes?: false | undefined } | string | null | undefined,
750 callback: (err: NodeJS.ErrnoException | null, files: string[] | Buffer[]) => void,
751): void;
752
753/**
754 * Asynchronous `readdir(3)`.
755 *
756 * Reads the contents of a directory.
757 *
758 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
759 */
760export function readdir(path: PathLike, callback: (err: NodeJS.ErrnoException | null, files: string[]) => void): void;
761
762/**
763 * Asynchronous `readdir(3)`.
764 *
765 * Reads the contents of a directory.
766 *
767 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
768 * @param options If called with `withFileTypes: true` the result data will be an array of Dirent.
769 */
770export function readdir(
771 path: PathLike,
772 options: { encoding?: string | null | undefined; withFileTypes: true },
773 callback: (err: NodeJS.ErrnoException | null, files: Dirent[]) => void,
774): void;
775
776/**
777 * Asynchronous `readdir(3)`.
778 *
779 * Reads the contents of a directory.
780 *
781 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
782 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
783 */
784export function readdir(
785 path: PathLike,
786 options?: { encoding: BufferEncoding | null; withFileTypes?: false | undefined } | BufferEncoding | null,
787): Promise<string[]>;
788
789/**
790 * Asynchronous `readdir(3)`.
791 *
792 * Reads the contents of a directory.
793 *
794 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
795 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
796 */
797export function readdir(
798 path: PathLike,
799 options: "buffer" | { encoding: "buffer"; withFileTypes?: false | undefined },
800): Promise<Buffer[]>;
801
802/**
803 * Asynchronous `readdir(3)`.
804 *
805 * Reads the contents of a directory.
806 *
807 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
808 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
809 */
810export function readdir(
811 path: PathLike,
812 options?: { encoding?: string | null | undefined; withFileTypes?: false | undefined } | string | null,
813): Promise<string[] | Buffer[]>;
814
815/**
816 * Asynchronous `readdir(3)`.
817 *
818 * Reads the contents of a directory.
819 *
820 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
821 * @param options If called with `withFileTypes: true` the result data will be an array of Dirent
822 */
823export function readdir(
824 path: PathLike,
825 options: { encoding?: string | null | undefined; withFileTypes: true },
826): Promise<Dirent[]>;
827
828/**
829 * Asynchronous `close(2)`.
830 *
831 * close a file descriptor.
832 *
833 * @param fd A file descriptor.
834 */
835export function close(fd: number, callback: NoParamCallback): void;
836
837/**
838 * Asynchronous `close(2)`.
839 *
840 * close a file descriptor.
841 *
842 * @param fd A file descriptor.
843 */
844export function close(fd: number): Promise<void>;
845
846/**
847 * Asynchronous `open(2)`.
848 *
849 * open and possibly create a file.
850 *
851 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
852 * @param mode A file mode. If a string is passed, it is parsed as an octal integer. If not supplied, defaults to `0o666`.
853 */
854export function open(
855 path: PathLike,
856 flags: string | number,
857 mode: string | number | null | undefined,
858 callback: (err: NodeJS.ErrnoException | null, fd: number) => void,
859): void;
860
861/**
862 * Asynchronous `open(2)`.
863 *
864 * open and possibly create a file. If the file is created, its mode will be `0o666`.
865 *
866 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
867 */
868export function open(
869 path: PathLike,
870 flags: string | number,
871 callback: (err: NodeJS.ErrnoException | null, fd: number) => void,
872): void;
873
874/**
875 * Asynchronous `open(2)`.
876 *
877 * open and possibly create a file.
878 *
879 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
880 * @param mode A file mode. If a string is passed, it is parsed as an octal integer. If not supplied, defaults to `0o666`.
881 */
882export function open(path: PathLike, flags: string | number, mode?: string | number | null): Promise<number>;
883
884/**
885 * Change the file timestamps of the file referenced by the supplied path.
886 *
887 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
888 * @param atime The last access time. If a string is provided, it will be coerced to number.
889 * @param mtime The last modified time. If a string is provided, it will be coerced to number.
890 */
891export function utimes(
892 path: PathLike,
893 atime: string | number | Date,
894 mtime: string | number | Date,
895 callback: NoParamCallback,
896): void;
897
898/**
899 * Change the file timestamps of the file referenced by the supplied path.
900 *
901 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
902 * @param atime The last access time. If a string is provided, it will be coerced to number.
903 * @param mtime The last modified time. If a string is provided, it will be coerced to number.
904 */
905export function utimes(path: PathLike, atime: string | number | Date, mtime: string | number | Date): Promise<void>;
906
907/**
908 * Change the file timestamps of a file referenced by the supplied file descriptor.
909 *
910 * @param fd A file descriptor.
911 * @param atime The last access time. If a string is provided, it will be coerced to number.
912 * @param mtime The last modified time. If a string is provided, it will be coerced to number.
913 */
914export function futimes(
915 fd: number,
916 atime: string | number | Date,
917 mtime: string | number | Date,
918 callback: NoParamCallback,
919): void;
920
921/**
922 * Change the file timestamps of a file referenced by the supplied file descriptor.
923 *
924 * @param fd A file descriptor.
925 * @param atime The last access time. If a string is provided, it will be coerced to number.
926 * @param mtime The last modified time. If a string is provided, it will be coerced to number.
927 */
928export function futimes(fd: number, atime: string | number | Date, mtime: string | number | Date): Promise<void>;
929
930/**
931 * Asynchronous `fsync(2)`.
932 *
933 * synchronize a file's in-core state with the underlying storage device.
934 *
935 * @param fd A file descriptor.
936 */
937export function fsync(fd: number, callback: NoParamCallback): void;
938
939/**
940 * Asynchronous `fsync(2)`.
941 *
942 * synchronize a file's in-core state with the underlying storage device.
943 *
944 * @param fd A file descriptor.
945 */
946export function fsync(fd: number): Promise<void>;
947
948/**
949 * Write `buffer` to the file specified by `fd`.
950 *
951 * @param fd A file descriptor.
952 * @param offset The part of the buffer to be written. If not supplied, defaults to `0`.
953 * @param length The number of bytes to write. If not supplied, defaults to `buffer.length - offset`.
954 * @param position The offset from the beginning of the file where this data should be written. If not supplied, defaults to the current position.
955 */
956export function write<TBuffer extends NodeJS.ArrayBufferView>(
957 fd: number,
958 buffer: TBuffer,
959 offset: number | null | undefined,
960 length: number | null | undefined,
961 position: number | null | undefined,
962 callback: (err: NodeJS.ErrnoException | null, written: number, buffer: TBuffer) => void,
963): void;
964
965/**
966 * Write `buffer` to the file specified by `fd`.
967 *
968 * @param fd A file descriptor.
969 * @param offset The part of the buffer to be written. If not supplied, defaults to `0`.
970 * @param length The number of bytes to write. If not supplied, defaults to `buffer.length - offset`.
971 */
972export function write<TBuffer extends NodeJS.ArrayBufferView>(
973 fd: number,
974 buffer: TBuffer,
975 offset: number | null | undefined,
976 length: number | null | undefined,
977 callback: (err: NodeJS.ErrnoException | null, written: number, buffer: TBuffer) => void,
978): void;
979
980/**
981 * Write `buffer` to the file specified by `fd`.
982 *
983 * @param fd A file descriptor.
984 * @param offset The part of the buffer to be written. If not supplied, defaults to `0`.
985 */
986export function write<TBuffer extends NodeJS.ArrayBufferView>(
987 fd: number,
988 buffer: TBuffer,
989 offset: number | null | undefined,
990 callback: (err: NodeJS.ErrnoException | null, written: number, buffer: TBuffer) => void,
991): void;
992
993/**
994 * Write `buffer` to the file specified by `fd`.
995 *
996 * @param fd A file descriptor.
997 */
998export function write<TBuffer extends NodeJS.ArrayBufferView>(
999 fd: number,
1000 buffer: TBuffer,
1001 callback: (err: NodeJS.ErrnoException | null, written: number, buffer: TBuffer) => void,
1002): void;
1003
1004/**
1005 * Write `buffer` to the file specified by `fd`.
1006 *
1007 * @param fd A file descriptor.
1008 * @param offset The part of the buffer to be written. If not supplied, defaults to `0`.
1009 * @param length The number of bytes to write. If not supplied, defaults to `buffer.length - offset`.
1010 * @param position The offset from the beginning of the file where this data should be written. If not supplied, defaults to the current position.
1011 */
1012export function write<TBuffer extends NodeJS.ArrayBufferView>(
1013 fd: number,
1014 buffer?: TBuffer,
1015 offset?: number,
1016 length?: number,
1017 position?: number | null,
1018): Promise<[number, TBuffer]>;
1019
1020/**
1021 * Write `data` to the file specified by `fd`.
1022 *
1023 * @param fd A file descriptor.
1024 * @param string A string to write. If something other than a string is supplied it will be coerced to a string.
1025 * @param position The offset from the beginning of the file where this data should be written. If not supplied, defaults to the current position.
1026 * @param encoding The expected string encoding.
1027 */
1028export function write(
1029 fd: number,
1030 data: any,
1031 position: number | null | undefined,
1032 encoding: string | null | undefined,
1033 callback: (err: NodeJS.ErrnoException | null, written: number, str: string) => void,
1034): void;
1035
1036/**
1037 * Write `data` to the file specified by `fd`.
1038 *
1039 * @param fd A file descriptor.
1040 * @param string A string to write. If something other than a string is supplied it will be coerced to a string.
1041 * @param position The offset from the beginning of the file where this data should be written. If not supplied, defaults to the current position.
1042 */
1043export function write(
1044 fd: number,
1045 data: any,
1046 position: number | null | undefined,
1047 callback: (err: NodeJS.ErrnoException | null, written: number, str: string) => void,
1048): void;
1049
1050/**
1051 * Write `data` to the file specified by `fd`.
1052 *
1053 * @param fd A file descriptor.
1054 * @param string A string to write. If something other than a string is supplied it will be coerced to a string.
1055 */
1056export function write(
1057 fd: number,
1058 data: any,
1059 callback: (err: NodeJS.ErrnoException | null, written: number, str: string) => void,
1060): void;
1061
1062/**
1063 * Write `data` to the file specified by `fd`.
1064 *
1065 * @param fd A file descriptor.
1066 * @param string A string to write. If something other than a string is supplied it will be coerced to a string.
1067 * @param position The offset from the beginning of the file where this data should be written. If not supplied, defaults to the current position.
1068 * @param encoding The expected string encoding.
1069 */
1070export function write(
1071 fd: number,
1072 string: any,
1073 position?: number | null,
1074 encoding?: string | null,
1075): Promise<[number, string]>;
1076
1077/**
1078 * Read data from the file specified by `fd`.
1079 *
1080 * @param fd A file descriptor.
1081 * @param buffer The buffer that the data will be written to.
1082 * @param offset The offset in the buffer at which to start writing.
1083 * @param length The number of bytes to read.
1084 * @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.
1085 */
1086export function read<TBuffer extends NodeJS.ArrayBufferView>(
1087 fd: number,
1088 buffer: TBuffer,
1089 offset: number,
1090 length: number,
1091 position: number | null,
1092 callback: (err: NodeJS.ErrnoException | null, bytesRead: number, buffer: TBuffer) => void,
1093): void;
1094
1095/**
1096 * Read data from the file specified by `fd`.
1097 *
1098 * @param fd A file descriptor.
1099 * @param buffer The buffer that the data will be written to.
1100 * @param offset The offset in the buffer at which to start writing.
1101 * @param length The number of bytes to read.
1102 * @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.
1103 */
1104export function read<TBuffer extends NodeJS.ArrayBufferView>(
1105 fd: number,
1106 buffer: TBuffer,
1107 offset: number,
1108 length: number,
1109 position: number | null,
1110): Promise<[number, TBuffer]>;
1111
1112/**
1113 * Asynchronously reads the entire contents of a file.
1114 *
1115 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1116 * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
1117 * @param options An object that may contain an optional flag.
1118 * If a flag is not provided, it defaults to `'r'`.
1119 */
1120export function readFile(
1121 path: PathLike | number,
1122 options: { encoding?: null | undefined; flag?: string | undefined } | null | undefined,
1123 callback: (err: NodeJS.ErrnoException | null, data: Buffer) => void,
1124): void;
1125
1126/**
1127 * Asynchronously reads the entire contents of a file.
1128 *
1129 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1130 * URL support is _experimental_.
1131 * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
1132 * @param options Either the encoding for the result, or an object that contains the encoding and an optional flag.
1133 * If a flag is not provided, it defaults to `'r'`.
1134 */
1135export function readFile(
1136 path: PathLike | number,
1137 options: { encoding: string; flag?: string | undefined } | string,
1138 callback: (err: NodeJS.ErrnoException | null, data: string) => void,
1139): void;
1140
1141/**
1142 * Asynchronously reads the entire contents of a file.
1143 *
1144 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1145 * URL support is _experimental_.
1146 * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
1147 * @param options Either the encoding for the result, or an object that contains the encoding and an optional flag.
1148 * If a flag is not provided, it defaults to `'r'`.
1149 */
1150export function readFile(
1151 path: PathLike | number,
1152 options: { encoding?: string | null | undefined; flag?: string | undefined } | string | null | undefined,
1153 callback: (err: NodeJS.ErrnoException | null, data: string | Buffer) => void,
1154): void;
1155
1156/**
1157 * Asynchronously reads the entire contents of a file.
1158 *
1159 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1160 * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
1161 */
1162export function readFile(
1163 path: PathLike | number,
1164 callback: (err: NodeJS.ErrnoException | null, data: Buffer) => void,
1165): void;
1166
1167/**
1168 * Asynchronously reads the entire contents of a file.
1169 *
1170 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1171 * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
1172 * @param options An object that may contain an optional flag.
1173 * If a flag is not provided, it defaults to `'r'`.
1174 */
1175export function readFile(
1176 path: PathLike | number,
1177 options?: { encoding?: null | undefined; flag?: string | undefined } | null,
1178): Promise<Buffer>;
1179
1180/**
1181 * Asynchronously reads the entire contents of a file.
1182 *
1183 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1184 * URL support is _experimental_.
1185 * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
1186 * @param options Either the encoding for the result, or an object that contains the encoding and an optional flag.
1187 * If a flag is not provided, it defaults to `'r'`.
1188 */
1189export function readFile(
1190 path: PathLike | number,
1191 options: { encoding: string; flag?: string | undefined } | string,
1192): Promise<string>;
1193
1194/**
1195 * Asynchronously reads the entire contents of a file.
1196 *
1197 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1198 * URL support is _experimental_.
1199 * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
1200 * @param options Either the encoding for the result, or an object that contains the encoding and an optional flag.
1201 * If a flag is not provided, it defaults to `'r'`.
1202 */
1203export function readFile(
1204 path: PathLike | number,
1205 options?: { encoding?: string | null | undefined; flag?: string | undefined } | string | null,
1206): Promise<string | Buffer>;
1207
1208/**
1209 * Asynchronously writes data to a file, replacing the file if it already exists.
1210 *
1211 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1212 * URL support is _experimental_.
1213 * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
1214 * @param data The data to write. If something other than a Buffer or Uint8Array is provided, the value is coerced to a string.
1215 * @param options Either the encoding for the file, or an object optionally specifying the encoding, file mode, and flag.
1216 * If `encoding` is not supplied, the default of `'utf8'` is used.
1217 * If `mode` is not supplied, the default of `0o666` is used.
1218 * If `mode` is a string, it is parsed as an octal integer.
1219 * If `flag` is not supplied, the default of `'w'` is used.
1220 */
1221export function writeFile(
1222 path: PathLike | number,
1223 data: any,
1224 options: WriteFileOptions,
1225 callback: NoParamCallback,
1226): void;
1227
1228/**
1229 * Asynchronously writes data to a file, replacing the file if it already exists.
1230 *
1231 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1232 * URL support is _experimental_.
1233 * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
1234 * @param data The data to write. If something other than a Buffer or Uint8Array is provided, the value is coerced to a string.
1235 */
1236export function writeFile(path: PathLike | number, data: any, callback: NoParamCallback): void;
1237
1238/**
1239 * Asynchronously writes data to a file, replacing the file if it already exists.
1240 *
1241 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1242 * URL support is _experimental_.
1243 * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
1244 * @param data The data to write. If something other than a Buffer or Uint8Array is provided, the value is coerced to a string.
1245 * @param options Either the encoding for the file, or an object optionally specifying the encoding, file mode, and flag.
1246 * If `encoding` is not supplied, the default of `'utf8'` is used.
1247 * If `mode` is not supplied, the default of `0o666` is used.
1248 * If `mode` is a string, it is parsed as an octal integer.
1249 * If `flag` is not supplied, the default of `'w'` is used.
1250 */
1251export function writeFile(path: PathLike | number, data: any, options?: WriteFileOptions): Promise<void>;
1252
1253/**
1254 * Asynchronously append data to a file, creating the file if it does not yet exist.
1255 *
1256 * @param file A path to a file. If a URL is provided, it must use the `file:` protocol.
1257 * URL support is _experimental_.
1258 * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
1259 * @param data The data to write. If something other than a Buffer or Uint8Array is provided, the value is coerced to a string.
1260 * @param options Either the encoding for the file, or an object optionally specifying the encoding, file mode, and flag.
1261 * If `encoding` is not supplied, the default of `'utf8'` is used.
1262 * If `mode` is not supplied, the default of `0o666` is used.
1263 * If `mode` is a string, it is parsed as an octal integer.
1264 * If `flag` is not supplied, the default of `'a'` is used.
1265 */
1266export function appendFile(
1267 file: PathLike | number,
1268 data: any,
1269 options: WriteFileOptions,
1270 callback: NoParamCallback,
1271): void;
1272
1273/**
1274 * Asynchronously append data to a file, creating the file if it does not yet exist.
1275 *
1276 * @param file A path to a file. If a URL is provided, it must use the `file:` protocol.
1277 * URL support is _experimental_.
1278 * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
1279 * @param data The data to write. If something other than a Buffer or Uint8Array is provided, the value is coerced to a string.
1280 */
1281export function appendFile(file: PathLike | number, data: any, callback: NoParamCallback): void;
1282
1283/**
1284 * Asynchronously append data to a file, creating the file if it does not yet exist.
1285 *
1286 * @param file A path to a file. If a URL is provided, it must use the `file:` protocol.
1287 * URL support is _experimental_.
1288 * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
1289 * @param data The data to write. If something other than a Buffer or Uint8Array is provided, the value is coerced to a string.
1290 * @param options Either the encoding for the file, or an object optionally specifying the encoding, file mode, and flag.
1291 * If `encoding` is not supplied, the default of `'utf8'` is used.
1292 * If `mode` is not supplied, the default of `0o666` is used.
1293 * If `mode` is a string, it is parsed as an octal integer.
1294 * If `flag` is not supplied, the default of `'a'` is used.
1295 */
1296export function appendFile(file: PathLike | number, data: any, options?: WriteFileOptions): Promise<void>;
1297
1298/**
1299 * Watch for changes on `filename`. The callback `listener` will be called each time the file is accessed.
1300 */
1301export function watchFile(
1302 filename: PathLike,
1303 options: { persistent?: boolean | undefined; interval?: number | undefined } | undefined,
1304 listener: (curr: Stats, prev: Stats) => void,
1305): void;
1306
1307/**
1308 * Watch for changes on `filename`. The callback `listener` will be called each time the file is accessed.
1309 * @param filename A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
1310 * URL support is _experimental_.
1311 */
1312export function watchFile(filename: PathLike, listener: (curr: Stats, prev: Stats) => void): void;
1313
1314/**
1315 * Stop watching for changes on `filename`.
1316 * @param filename A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
1317 * URL support is _experimental_.
1318 */
1319export function unwatchFile(filename: PathLike, listener?: (curr: Stats, prev: Stats) => void): void;
1320
1321/**
1322 * Watch for changes on `filename`, where `filename` is either a file or a directory, returning an `FSWatcher`.
1323 * @param filename A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
1324 * URL support is _experimental_.
1325 * @param options Either the encoding for the filename provided to the listener, or an object optionally specifying encoding, persistent, and recursive options.
1326 * If `encoding` is not supplied, the default of `'utf8'` is used.
1327 * If `persistent` is not supplied, the default of `true` is used.
1328 * If `recursive` is not supplied, the default of `false` is used.
1329 */
1330export function watch(
1331 filename: PathLike,
1332 options:
1333 | {
1334 encoding?: BufferEncoding | null | undefined;
1335 persistent?: boolean | undefined;
1336 recursive?: boolean | undefined;
1337 }
1338 | BufferEncoding
1339 | undefined
1340 | null,
1341 listener?: (event: string, filename: string) => void,
1342): FSWatcher;
1343
1344/**
1345 * Watch for changes on `filename`, where `filename` is either a file or a directory, returning an `FSWatcher`.
1346 * @param filename A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
1347 * URL support is _experimental_.
1348 * @param options Either the encoding for the filename provided to the listener, or an object optionally specifying encoding, persistent, and recursive options.
1349 * If `encoding` is not supplied, the default of `'utf8'` is used.
1350 * If `persistent` is not supplied, the default of `true` is used.
1351 * If `recursive` is not supplied, the default of `false` is used.
1352 */
1353export function watch(
1354 filename: PathLike,
1355 options: { encoding: "buffer"; persistent?: boolean | undefined; recursive?: boolean | undefined } | "buffer",
1356 listener?: (event: string, filename: Buffer) => void,
1357): FSWatcher;
1358
1359/**
1360 * Watch for changes on `filename`, where `filename` is either a file or a directory, returning an `FSWatcher`.
1361 * @param filename A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
1362 * URL support is _experimental_.
1363 * @param options Either the encoding for the filename provided to the listener, or an object optionally specifying encoding, persistent, and recursive options.
1364 * If `encoding` is not supplied, the default of `'utf8'` is used.
1365 * If `persistent` is not supplied, the default of `true` is used.
1366 * If `recursive` is not supplied, the default of `false` is used.
1367 */
1368export function watch(
1369 filename: PathLike,
1370 options:
1371 | { encoding?: string | null | undefined; persistent?: boolean | undefined; recursive?: boolean | undefined }
1372 | string
1373 | null,
1374 listener?: (event: string, filename: string | Buffer) => void,
1375): FSWatcher;
1376
1377/**
1378 * Watch for changes on `filename`, where `filename` is either a file or a directory, returning an `FSWatcher`.
1379 * @param filename A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
1380 * URL support is _experimental_.
1381 */
1382export function watch(filename: PathLike, listener?: (event: string, filename: string) => any): FSWatcher;
1383
1384/**
1385 * Test whether or not the given path exists by checking with the file system.
1386 *
1387 * @deprecated
1388 * @param path A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
1389 * URL support is _experimental_.
1390 */
1391export function exists(path: PathLike, callback: (err: NodeJS.ErrnoException | null, exists: boolean) => void): void;
1392
1393/**
1394 * Test whether or not the given path exists by checking with the file system.
1395 *
1396 * @param path A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
1397 * URL support is _experimental_.
1398 */
1399export function exists(path: PathLike): Promise<boolean>;
1400
1401/**
1402 * Tests a user's permissions for the file specified by `path`.
1403 *
1404 * @param path A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
1405 * URL support is _experimental_.
1406 * @param mode An optional integer that specifies the accessibility checks to be performed.
1407 */
1408export function access(path: PathLike, mode: number | undefined, callback: NoParamCallback): void;
1409
1410/**
1411 * Tests a user's permissions for the file specified by `path`.
1412 *
1413 * @param path A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
1414 * URL support is _experimental_.
1415 */
1416export function access(path: PathLike, callback: NoParamCallback): void;
1417
1418/**
1419 * Tests a user's permissions for the file specified by `path`.
1420 *
1421 * @param path A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
1422 * URL support is _experimental_.
1423 * @param mode An optional integer that specifies the accessibility checks to be performed.
1424 */
1425export function access(path: PathLike, mode?: number): Promise<void>;
1426
1427/**
1428 * Asynchronous `fdatasync(2)`.
1429 *
1430 * Synchronize a file's in-core state with storage device.
1431 *
1432 * @param fd A file descriptor.
1433 */
1434export function fdatasync(fd: number, callback: NoParamCallback): void;
1435
1436/**
1437 * Asynchronous `fdatasync(2)`.
1438 *
1439 * Synchronize a file's in-core state with storage device.
1440 *
1441 * @param fd A file descriptor.
1442 */
1443export function fdatasync(fd: number): Promise<void>;
1444
1445/**
1446 * Asynchronously copies src to dest.
1447 *
1448 * By default, dest is overwritten if it already exists.
1449 * No arguments other than a possible exception are given to the callback function.
1450 * Node.js makes no guarantees about the atomicity of the copy operation.
1451 * If an error occurs after the destination file has been opened for writing, Node.js will attempt
1452 * to remove the destination.
1453 *
1454 * @param src A path to the source file.
1455 * @param dest A path to the destination file.
1456 */
1457export function copyFile(src: PathLike, dest: PathLike, callback: NoParamCallback): void;
1458
1459/**
1460 * Asynchronously copies src to dest.
1461 *
1462 * By default, dest is overwritten if it already exists.
1463 * No arguments other than a possible exception are given to the callback function.
1464 * Node.js makes no guarantees about the atomicity of the copy operation.
1465 * If an error occurs after the destination file has been opened for writing, Node.js will attempt
1466 * to remove the destination.
1467 *
1468 * @param src A path to the source file.
1469 * @param dest A path to the destination file.
1470 * @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.
1471 */
1472export function copyFile(src: PathLike, dest: PathLike, flags: number, callback: NoParamCallback): void;
1473
1474/**
1475 * Asynchronously copies src to dest.
1476 *
1477 * By default, dest is overwritten if it already exists.
1478 * No arguments other than a possible exception are given to the callback function.
1479 * Node.js makes no guarantees about the atomicity of the copy operation.
1480 * If an error occurs after the destination file has been opened for writing, Node.js will attempt
1481 * to remove the destination.
1482 *
1483 * @param src A path to the source file.
1484 * @param dest A path to the destination file.
1485 * @param flags An optional integer that specifies the behavior of the copy operation.
1486 * The only supported flag is fs.constants.COPYFILE_EXCL,
1487 * which causes the copy operation to fail if dest already exists.
1488 */
1489export function copyFile(src: PathLike, dest: PathLike, flags?: number): Promise<void>;
1490
1491/**
1492 * Write an array of ArrayBufferViews to the file specified by fd using writev().
1493 *
1494 * Position is the offset from the beginning of the file where this data should be written.
1495 * It is unsafe to use fs.writev() multiple times on the same file without waiting for the callback. For this scenario, use fs.createWriteStream().
1496 * On Linux, positional writes don't work when the file is opened in append mode.
1497 * The kernel ignores the position argument and always appends the data to the end of the file.
1498 */
1499export function writev(
1500 fd: number,
1501 buffers: NodeJS.ArrayBufferView[],
1502 cb: (err: NodeJS.ErrnoException | null, bytesWritten: number, buffers: NodeJS.ArrayBufferView[]) => void,
1503): void;
1504
1505export function writev(
1506 fd: number,
1507 buffers: NodeJS.ArrayBufferView[],
1508 position: number,
1509 cb: (err: NodeJS.ErrnoException | null, bytesWritten: number, buffers: NodeJS.ArrayBufferView[]) => void,
1510): void;
1511
1512export function writev(
1513 fd: number,
1514 buffers: NodeJS.ArrayBufferView[],
1515 position?: number,
1516): Promise<[number, NodeJS.ArrayBufferView[]]>;