UNPKG

56.2 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 NoParamCallback,
8 PathLike,
9 RmDirOptions,
10 WriteFileOptions,
11 Stats,
12 symlink as symlinkNS,
13 MakeDirectoryOptions,
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 } | 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 } | 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 } | 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 } | 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 } | 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 } | 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 } | 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 } | string | null
512): Promise<string | Buffer>;
513
514export namespace realpath {
515 function native(
516 path: PathLike,
517 options: { encoding?: BufferEncoding | null } | 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 } | 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 } | 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 } | 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 } | 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 } | 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 } | 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 } | 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 } | 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 } | "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; withFileTypes?: false } | 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; 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 } | 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 }
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; withFileTypes?: false } | 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(path: PathLike, options: { encoding?: string | null; withFileTypes: true }): Promise<Dirent[]>;
824
825/**
826 * Asynchronous `close(2)`.
827 *
828 * close a file descriptor.
829 *
830 * @param fd A file descriptor.
831 */
832export function close(fd: number, callback: NoParamCallback): void;
833
834/**
835 * Asynchronous `close(2)`.
836 *
837 * close a file descriptor.
838 *
839 * @param fd A file descriptor.
840 */
841export function close(fd: number): Promise<void>;
842
843/**
844 * Asynchronous `open(2)`.
845 *
846 * open and possibly create a file.
847 *
848 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
849 * @param mode A file mode. If a string is passed, it is parsed as an octal integer. If not supplied, defaults to `0o666`.
850 */
851export function open(
852 path: PathLike,
853 flags: string | number,
854 mode: string | number | null | undefined,
855 callback: (err: NodeJS.ErrnoException | null, fd: number) => void
856): void;
857
858/**
859 * Asynchronous `open(2)`.
860 *
861 * open and possibly create a file. If the file is created, its mode will be `0o666`.
862 *
863 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
864 */
865export function open(
866 path: PathLike,
867 flags: string | number,
868 callback: (err: NodeJS.ErrnoException | null, fd: number) => void
869): void;
870
871/**
872 * Asynchronous `open(2)`.
873 *
874 * open and possibly create a file.
875 *
876 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
877 * @param mode A file mode. If a string is passed, it is parsed as an octal integer. If not supplied, defaults to `0o666`.
878 */
879export function open(path: PathLike, flags: string | number, mode?: string | number | null): Promise<number>;
880
881/**
882 * Change the file timestamps of the file referenced by the supplied path.
883 *
884 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
885 * @param atime The last access time. If a string is provided, it will be coerced to number.
886 * @param mtime The last modified time. If a string is provided, it will be coerced to number.
887 */
888export function utimes(
889 path: PathLike,
890 atime: string | number | Date,
891 mtime: string | number | Date,
892 callback: NoParamCallback
893): void;
894
895/**
896 * Change the file timestamps of the file referenced by the supplied path.
897 *
898 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
899 * @param atime The last access time. If a string is provided, it will be coerced to number.
900 * @param mtime The last modified time. If a string is provided, it will be coerced to number.
901 */
902export function utimes(path: PathLike, atime: string | number | Date, mtime: string | number | Date): Promise<void>;
903
904/**
905 * Change the file timestamps of a file referenced by the supplied file descriptor.
906 *
907 * @param fd A file descriptor.
908 * @param atime The last access time. If a string is provided, it will be coerced to number.
909 * @param mtime The last modified time. If a string is provided, it will be coerced to number.
910 */
911export function futimes(
912 fd: number,
913 atime: string | number | Date,
914 mtime: string | number | Date,
915 callback: NoParamCallback
916): void;
917
918/**
919 * Change the file timestamps of a file referenced by the supplied file descriptor.
920 *
921 * @param fd A file descriptor.
922 * @param atime The last access time. If a string is provided, it will be coerced to number.
923 * @param mtime The last modified time. If a string is provided, it will be coerced to number.
924 */
925export function futimes(fd: number, atime: string | number | Date, mtime: string | number | Date): Promise<void>;
926
927/**
928 * Asynchronous `fsync(2)`.
929 *
930 * synchronize a file's in-core state with the underlying storage device.
931 *
932 * @param fd A file descriptor.
933 */
934export function fsync(fd: number, callback: NoParamCallback): void;
935
936/**
937 * Asynchronous `fsync(2)`.
938 *
939 * synchronize a file's in-core state with the underlying storage device.
940 *
941 * @param fd A file descriptor.
942 */
943export function fsync(fd: number): Promise<void>;
944
945/**
946 * Write `buffer` to the file specified by `fd`.
947 *
948 * @param fd A file descriptor.
949 * @param offset The part of the buffer to be written. If not supplied, defaults to `0`.
950 * @param length The number of bytes to write. If not supplied, defaults to `buffer.length - offset`.
951 * @param position The offset from the beginning of the file where this data should be written. If not supplied, defaults to the current position.
952 */
953export function write<TBuffer extends NodeJS.ArrayBufferView>(
954 fd: number,
955 buffer: TBuffer,
956 offset: number | null | undefined,
957 length: number | null | undefined,
958 position: number | null | undefined,
959 callback: (err: NodeJS.ErrnoException | null, written: number, buffer: TBuffer) => void
960): void;
961
962/**
963 * Write `buffer` to the file specified by `fd`.
964 *
965 * @param fd A file descriptor.
966 * @param offset The part of the buffer to be written. If not supplied, defaults to `0`.
967 * @param length The number of bytes to write. If not supplied, defaults to `buffer.length - offset`.
968 */
969export function write<TBuffer extends NodeJS.ArrayBufferView>(
970 fd: number,
971 buffer: TBuffer,
972 offset: number | null | undefined,
973 length: number | null | undefined,
974 callback: (err: NodeJS.ErrnoException | null, written: number, buffer: TBuffer) => void
975): void;
976
977/**
978 * Write `buffer` to the file specified by `fd`.
979 *
980 * @param fd A file descriptor.
981 * @param offset The part of the buffer to be written. If not supplied, defaults to `0`.
982 */
983export function write<TBuffer extends NodeJS.ArrayBufferView>(
984 fd: number,
985 buffer: TBuffer,
986 offset: number | null | undefined,
987 callback: (err: NodeJS.ErrnoException | null, written: number, buffer: TBuffer) => void
988): void;
989
990/**
991 * Write `buffer` to the file specified by `fd`.
992 *
993 * @param fd A file descriptor.
994 */
995export function write<TBuffer extends NodeJS.ArrayBufferView>(
996 fd: number,
997 buffer: TBuffer,
998 callback: (err: NodeJS.ErrnoException | null, written: number, buffer: TBuffer) => void
999): void;
1000
1001/**
1002 * Write `buffer` to the file specified by `fd`.
1003 *
1004 * @param fd A file descriptor.
1005 * @param offset The part of the buffer to be written. If not supplied, defaults to `0`.
1006 * @param length The number of bytes to write. If not supplied, defaults to `buffer.length - offset`.
1007 * @param position The offset from the beginning of the file where this data should be written. If not supplied, defaults to the current position.
1008 */
1009export function write<TBuffer extends NodeJS.ArrayBufferView>(
1010 fd: number,
1011 buffer?: TBuffer,
1012 offset?: number,
1013 length?: number,
1014 position?: number | null
1015): Promise<[number, TBuffer]>;
1016
1017/**
1018 * Write `data` to the file specified by `fd`.
1019 *
1020 * @param fd A file descriptor.
1021 * @param string A string to write. If something other than a string is supplied it will be coerced to a string.
1022 * @param position The offset from the beginning of the file where this data should be written. If not supplied, defaults to the current position.
1023 * @param encoding The expected string encoding.
1024 */
1025export function write(
1026 fd: number,
1027 data: any,
1028 position: number | null | undefined,
1029 encoding: string | null | undefined,
1030 callback: (err: NodeJS.ErrnoException | null, written: number, str: string) => void
1031): void;
1032
1033/**
1034 * Write `data` to the file specified by `fd`.
1035 *
1036 * @param fd A file descriptor.
1037 * @param string A string to write. If something other than a string is supplied it will be coerced to a string.
1038 * @param position The offset from the beginning of the file where this data should be written. If not supplied, defaults to the current position.
1039 */
1040export function write(
1041 fd: number,
1042 data: any,
1043 position: number | null | undefined,
1044 callback: (err: NodeJS.ErrnoException | null, written: number, str: string) => void
1045): void;
1046
1047/**
1048 * Write `data` to the file specified by `fd`.
1049 *
1050 * @param fd A file descriptor.
1051 * @param string A string to write. If something other than a string is supplied it will be coerced to a string.
1052 */
1053export function write(
1054 fd: number,
1055 data: any,
1056 callback: (err: NodeJS.ErrnoException | null, written: number, str: string) => void
1057): void;
1058
1059/**
1060 * Write `data` to the file specified by `fd`.
1061 *
1062 * @param fd A file descriptor.
1063 * @param string A string to write. If something other than a string is supplied it will be coerced to a string.
1064 * @param position The offset from the beginning of the file where this data should be written. If not supplied, defaults to the current position.
1065 * @param encoding The expected string encoding.
1066 */
1067export function write(
1068 fd: number,
1069 string: any,
1070 position?: number | null,
1071 encoding?: string | null
1072): Promise<[number, string]>;
1073
1074/**
1075 * Read data from the file specified by `fd`.
1076 *
1077 * @param fd A file descriptor.
1078 * @param buffer The buffer that the data will be written to.
1079 * @param offset The offset in the buffer at which to start writing.
1080 * @param length The number of bytes to read.
1081 * @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.
1082 */
1083export function read<TBuffer extends NodeJS.ArrayBufferView>(
1084 fd: number,
1085 buffer: TBuffer,
1086 offset: number,
1087 length: number,
1088 position: number | null,
1089 callback: (err: NodeJS.ErrnoException | null, bytesRead: number, buffer: TBuffer) => void
1090): void;
1091
1092/**
1093 * Read data from the file specified by `fd`.
1094 *
1095 * @param fd A file descriptor.
1096 * @param buffer The buffer that the data will be written to.
1097 * @param offset The offset in the buffer at which to start writing.
1098 * @param length The number of bytes to read.
1099 * @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.
1100 */
1101export function read<TBuffer extends NodeJS.ArrayBufferView>(
1102 fd: number,
1103 buffer: TBuffer,
1104 offset: number,
1105 length: number,
1106 position: number | null
1107): Promise<[number, TBuffer]>;
1108
1109/**
1110 * Asynchronously reads the entire contents of a file.
1111 *
1112 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1113 * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
1114 * @param options An object that may contain an optional flag.
1115 * If a flag is not provided, it defaults to `'r'`.
1116 */
1117export function readFile(
1118 path: PathLike | number,
1119 options: { encoding?: null; flag?: string } | null | undefined,
1120 callback: (err: NodeJS.ErrnoException | null, data: Buffer) => void
1121): void;
1122
1123/**
1124 * Asynchronously reads the entire contents of a file.
1125 *
1126 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1127 * URL support is _experimental_.
1128 * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
1129 * @param options Either the encoding for the result, or an object that contains the encoding and an optional flag.
1130 * If a flag is not provided, it defaults to `'r'`.
1131 */
1132export function readFile(
1133 path: PathLike | number,
1134 options: { encoding: string; flag?: string } | string,
1135 callback: (err: NodeJS.ErrnoException | null, data: string) => void
1136): void;
1137
1138/**
1139 * Asynchronously reads the entire contents of a file.
1140 *
1141 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1142 * URL support is _experimental_.
1143 * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
1144 * @param options Either the encoding for the result, or an object that contains the encoding and an optional flag.
1145 * If a flag is not provided, it defaults to `'r'`.
1146 */
1147export function readFile(
1148 path: PathLike | number,
1149 options: { encoding?: string | null; flag?: string } | string | null | undefined,
1150 callback: (err: NodeJS.ErrnoException | null, data: string | Buffer) => void
1151): void;
1152
1153/**
1154 * Asynchronously reads the entire contents of a file.
1155 *
1156 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1157 * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
1158 */
1159export function readFile(
1160 path: PathLike | number,
1161 callback: (err: NodeJS.ErrnoException | null, data: Buffer) => void
1162): void;
1163
1164/**
1165 * Asynchronously reads the entire contents of a file.
1166 *
1167 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1168 * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
1169 * @param options An object that may contain an optional flag.
1170 * If a flag is not provided, it defaults to `'r'`.
1171 */
1172export function readFile(path: PathLike | number, options?: { encoding?: null; flag?: string } | null): Promise<Buffer>;
1173
1174/**
1175 * Asynchronously reads the entire contents of a file.
1176 *
1177 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1178 * URL support is _experimental_.
1179 * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
1180 * @param options Either the encoding for the result, or an object that contains the encoding and an optional flag.
1181 * If a flag is not provided, it defaults to `'r'`.
1182 */
1183export function readFile(
1184 path: PathLike | number,
1185 options: { encoding: string; flag?: string } | string
1186): Promise<string>;
1187
1188/**
1189 * Asynchronously reads the entire contents of a file.
1190 *
1191 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1192 * URL support is _experimental_.
1193 * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
1194 * @param options Either the encoding for the result, or an object that contains the encoding and an optional flag.
1195 * If a flag is not provided, it defaults to `'r'`.
1196 */
1197export function readFile(
1198 path: PathLike | number,
1199 options?: { encoding?: string | null; flag?: string } | string | null
1200): Promise<string | Buffer>;
1201
1202/**
1203 * Asynchronously writes data to a file, replacing the file if it already exists.
1204 *
1205 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1206 * URL support is _experimental_.
1207 * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
1208 * @param data The data to write. If something other than a Buffer or Uint8Array is provided, the value is coerced to a string.
1209 * @param options Either the encoding for the file, or an object optionally specifying the encoding, file mode, and flag.
1210 * If `encoding` is not supplied, the default of `'utf8'` is used.
1211 * If `mode` is not supplied, the default of `0o666` is used.
1212 * If `mode` is a string, it is parsed as an octal integer.
1213 * If `flag` is not supplied, the default of `'w'` is used.
1214 */
1215export function writeFile(
1216 path: PathLike | number,
1217 data: any,
1218 options: WriteFileOptions,
1219 callback: NoParamCallback
1220): void;
1221
1222/**
1223 * Asynchronously writes data to a file, replacing the file if it already exists.
1224 *
1225 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1226 * URL support is _experimental_.
1227 * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
1228 * @param data The data to write. If something other than a Buffer or Uint8Array is provided, the value is coerced to a string.
1229 */
1230export function writeFile(path: PathLike | number, data: any, callback: NoParamCallback): void;
1231
1232/**
1233 * Asynchronously writes data to a file, replacing the file if it already exists.
1234 *
1235 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1236 * URL support is _experimental_.
1237 * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
1238 * @param data The data to write. If something other than a Buffer or Uint8Array is provided, the value is coerced to a string.
1239 * @param options Either the encoding for the file, or an object optionally specifying the encoding, file mode, and flag.
1240 * If `encoding` is not supplied, the default of `'utf8'` is used.
1241 * If `mode` is not supplied, the default of `0o666` is used.
1242 * If `mode` is a string, it is parsed as an octal integer.
1243 * If `flag` is not supplied, the default of `'w'` is used.
1244 */
1245export function writeFile(path: PathLike | number, data: any, options?: WriteFileOptions): Promise<void>;
1246
1247/**
1248 * Asynchronously append data to a file, creating the file if it does not yet exist.
1249 *
1250 * @param file A path to a file. If a URL is provided, it must use the `file:` protocol.
1251 * URL support is _experimental_.
1252 * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
1253 * @param data The data to write. If something other than a Buffer or Uint8Array is provided, the value is coerced to a string.
1254 * @param options Either the encoding for the file, or an object optionally specifying the encoding, file mode, and flag.
1255 * If `encoding` is not supplied, the default of `'utf8'` is used.
1256 * If `mode` is not supplied, the default of `0o666` is used.
1257 * If `mode` is a string, it is parsed as an octal integer.
1258 * If `flag` is not supplied, the default of `'a'` is used.
1259 */
1260export function appendFile(
1261 file: PathLike | number,
1262 data: any,
1263 options: WriteFileOptions,
1264 callback: NoParamCallback
1265): void;
1266
1267/**
1268 * Asynchronously append data to a file, creating the file if it does not yet exist.
1269 *
1270 * @param file A path to a file. If a URL is provided, it must use the `file:` protocol.
1271 * URL support is _experimental_.
1272 * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
1273 * @param data The data to write. If something other than a Buffer or Uint8Array is provided, the value is coerced to a string.
1274 */
1275export function appendFile(file: PathLike | number, data: any, callback: NoParamCallback): void;
1276
1277/**
1278 * Asynchronously append data to a file, creating the file if it does not yet exist.
1279 *
1280 * @param file A path to a file. If a URL is provided, it must use the `file:` protocol.
1281 * URL support is _experimental_.
1282 * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
1283 * @param data The data to write. If something other than a Buffer or Uint8Array is provided, the value is coerced to a string.
1284 * @param options Either the encoding for the file, or an object optionally specifying the encoding, file mode, and flag.
1285 * If `encoding` is not supplied, the default of `'utf8'` is used.
1286 * If `mode` is not supplied, the default of `0o666` is used.
1287 * If `mode` is a string, it is parsed as an octal integer.
1288 * If `flag` is not supplied, the default of `'a'` is used.
1289 */
1290export function appendFile(file: PathLike | number, data: any, options?: WriteFileOptions): Promise<void>;
1291
1292/**
1293 * Watch for changes on `filename`. The callback `listener` will be called each time the file is accessed.
1294 */
1295export function watchFile(
1296 filename: PathLike,
1297 options: { persistent?: boolean; interval?: number } | undefined,
1298 listener: (curr: Stats, prev: Stats) => void
1299): void;
1300
1301/**
1302 * Watch for changes on `filename`. The callback `listener` will be called each time the file is accessed.
1303 * @param filename A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
1304 * URL support is _experimental_.
1305 */
1306export function watchFile(filename: PathLike, listener: (curr: Stats, prev: Stats) => void): void;
1307
1308/**
1309 * Stop watching for changes on `filename`.
1310 * @param filename A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
1311 * URL support is _experimental_.
1312 */
1313export function unwatchFile(filename: PathLike, listener?: (curr: Stats, prev: Stats) => void): void;
1314
1315/**
1316 * Watch for changes on `filename`, where `filename` is either a file or a directory, returning an `FSWatcher`.
1317 * @param filename A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
1318 * URL support is _experimental_.
1319 * @param options Either the encoding for the filename provided to the listener, or an object optionally specifying encoding, persistent, and recursive options.
1320 * If `encoding` is not supplied, the default of `'utf8'` is used.
1321 * If `persistent` is not supplied, the default of `true` is used.
1322 * If `recursive` is not supplied, the default of `false` is used.
1323 */
1324export function watch(
1325 filename: PathLike,
1326 options:
1327 { encoding?: BufferEncoding | null; persistent?: boolean; recursive?: boolean } |
1328 BufferEncoding |
1329 undefined |
1330 null,
1331 listener?: (event: string, filename: string) => void
1332): FSWatcher;
1333
1334/**
1335 * Watch for changes on `filename`, where `filename` is either a file or a directory, returning an `FSWatcher`.
1336 * @param filename A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
1337 * URL support is _experimental_.
1338 * @param options Either the encoding for the filename provided to the listener, or an object optionally specifying encoding, persistent, and recursive options.
1339 * If `encoding` is not supplied, the default of `'utf8'` is used.
1340 * If `persistent` is not supplied, the default of `true` is used.
1341 * If `recursive` is not supplied, the default of `false` is used.
1342 */
1343export function watch(
1344 filename: PathLike,
1345 options: { encoding: "buffer"; persistent?: boolean; recursive?: boolean } | "buffer",
1346 listener?: (event: string, filename: Buffer) => void
1347): FSWatcher;
1348
1349/**
1350 * Watch for changes on `filename`, where `filename` is either a file or a directory, returning an `FSWatcher`.
1351 * @param filename A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
1352 * URL support is _experimental_.
1353 * @param options Either the encoding for the filename provided to the listener, or an object optionally specifying encoding, persistent, and recursive options.
1354 * If `encoding` is not supplied, the default of `'utf8'` is used.
1355 * If `persistent` is not supplied, the default of `true` is used.
1356 * If `recursive` is not supplied, the default of `false` is used.
1357 */
1358export function watch(
1359 filename: PathLike,
1360 options: { encoding?: string | null; persistent?: boolean; recursive?: boolean } | string | null,
1361 listener?: (event: string, filename: string | Buffer) => void
1362): FSWatcher;
1363
1364/**
1365 * Watch for changes on `filename`, where `filename` is either a file or a directory, returning an `FSWatcher`.
1366 * @param filename A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
1367 * URL support is _experimental_.
1368 */
1369export function watch(filename: PathLike, listener?: (event: string, filename: string) => any): FSWatcher;
1370
1371/**
1372 * Test whether or not the given path exists by checking with the file system.
1373 *
1374 * @deprecated
1375 * @param path A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
1376 * URL support is _experimental_.
1377 */
1378export function exists(path: PathLike, callback: (err: NodeJS.ErrnoException | null, exists: boolean) => void): void;
1379
1380/**
1381 * Test whether or not the given path exists by checking with the file system.
1382 *
1383 * @param path A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
1384 * URL support is _experimental_.
1385 */
1386export function exists(path: PathLike): Promise<boolean>;
1387
1388/**
1389 * Tests a user's permissions for the file specified by `path`.
1390 *
1391 * @param path A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
1392 * URL support is _experimental_.
1393 * @param mode An optional integer that specifies the accessibility checks to be performed.
1394 */
1395export function access(path: PathLike, mode: number | undefined, callback: NoParamCallback): void;
1396
1397/**
1398 * Tests a user's permissions for the file specified by `path`.
1399 *
1400 * @param path A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
1401 * URL support is _experimental_.
1402 */
1403export function access(path: PathLike, callback: NoParamCallback): void;
1404
1405/**
1406 * Tests a user's permissions for the file specified by `path`.
1407 *
1408 * @param path A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
1409 * URL support is _experimental_.
1410 * @param mode An optional integer that specifies the accessibility checks to be performed.
1411 */
1412export function access(path: PathLike, mode?: number): Promise<void>;
1413
1414/**
1415 * Asynchronous `fdatasync(2)`.
1416 *
1417 * Synchronize a file's in-core state with storage device.
1418 *
1419 * @param fd A file descriptor.
1420 */
1421export function fdatasync(fd: number, callback: NoParamCallback): void;
1422
1423/**
1424 * Asynchronous `fdatasync(2)`.
1425 *
1426 * Synchronize a file's in-core state with storage device.
1427 *
1428 * @param fd A file descriptor.
1429 */
1430export function fdatasync(fd: number): Promise<void>;
1431
1432/**
1433 * Asynchronously copies src to dest.
1434 *
1435 * By default, dest is overwritten if it already exists.
1436 * No arguments other than a possible exception are given to the callback function.
1437 * Node.js makes no guarantees about the atomicity of the copy operation.
1438 * If an error occurs after the destination file has been opened for writing, Node.js will attempt
1439 * to remove the destination.
1440 *
1441 * @param src A path to the source file.
1442 * @param dest A path to the destination file.
1443 */
1444export function copyFile(src: PathLike, dest: PathLike, callback: NoParamCallback): void;
1445
1446/**
1447 * Asynchronously copies src to dest.
1448 *
1449 * By default, dest is overwritten if it already exists.
1450 * No arguments other than a possible exception are given to the callback function.
1451 * Node.js makes no guarantees about the atomicity of the copy operation.
1452 * If an error occurs after the destination file has been opened for writing, Node.js will attempt
1453 * to remove the destination.
1454 *
1455 * @param src A path to the source file.
1456 * @param dest A path to the destination file.
1457 * @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.
1458 */
1459export function copyFile(src: PathLike, dest: PathLike, flags: number, callback: NoParamCallback): void;
1460
1461/**
1462 * Asynchronously copies src to dest.
1463 *
1464 * By default, dest is overwritten if it already exists.
1465 * No arguments other than a possible exception are given to the callback function.
1466 * Node.js makes no guarantees about the atomicity of the copy operation.
1467 * If an error occurs after the destination file has been opened for writing, Node.js will attempt
1468 * to remove the destination.
1469 *
1470 * @param src A path to the source file.
1471 * @param dest A path to the destination file.
1472 * @param flags An optional integer that specifies the behavior of the copy operation.
1473 * The only supported flag is fs.constants.COPYFILE_EXCL,
1474 * which causes the copy operation to fail if dest already exists.
1475 */
1476export function copyFile(src: PathLike, dest: PathLike, flags?: number): Promise<void>;
1477
1478/**
1479 * Write an array of ArrayBufferViews to the file specified by fd using writev().
1480 *
1481 * Position is the offset from the beginning of the file where this data should be written.
1482 * It is unsafe to use fs.writev() multiple times on the same file without waiting for the callback. For this scenario, use fs.createWriteStream().
1483 * On Linux, positional writes don't work when the file is opened in append mode.
1484 * The kernel ignores the position argument and always appends the data to the end of the file.
1485 */
1486export function writev(
1487 fd: number,
1488 buffers: NodeJS.ArrayBufferView[],
1489 cb: (err: NodeJS.ErrnoException | null, bytesWritten: number, buffers: NodeJS.ArrayBufferView[]) => void
1490): void;
1491
1492export function writev(
1493 fd: number,
1494 buffers: NodeJS.ArrayBufferView[],
1495 position: number,
1496 cb: (err: NodeJS.ErrnoException | null, bytesWritten: number, buffers: NodeJS.ArrayBufferView[]) => void
1497): void;
1498
1499export function writev(
1500 fd: number,
1501 buffers: NodeJS.ArrayBufferView[],
1502 position?: number
1503): Promise<[number, NodeJS.ArrayBufferView[]]>;