UNPKG

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