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 * The amount of time in milliseconds to wait between retries.
749 * This option is ignored if the `recursive` option is not `true`.
750 * @default 100
751 */
752 retryDelay?: number;
753 /**
754 * If an `EBUSY`, `EMFILE`, `ENFILE`, `ENOTEMPTY`, or
755 * `EPERM` error is encountered, Node.js will retry the operation with a linear
756 * backoff wait of `retryDelay` ms longer on each try. This option represents the
757 * number of retries. This option is ignored if the `recursive` option is not
758 * `true`.
759 * @default 0
760 */
761 maxRetries?: number;
762 }
763
764 /**
765 * Asynchronous rmdir(2) - delete a directory.
766 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
767 */
768 function rmdir(path: PathLike, callback: NoParamCallback): void;
769 function rmdir(path: PathLike, options: RmDirAsyncOptions, callback: NoParamCallback): void;
770
771 // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
772 namespace rmdir {
773 /**
774 * Asynchronous rmdir(2) - delete a directory.
775 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
776 */
777 function __promisify__(path: PathLike, options?: RmDirAsyncOptions): Promise<void>;
778 }
779
780 /**
781 * Synchronous rmdir(2) - delete a directory.
782 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
783 */
784 function rmdirSync(path: PathLike, options?: RmDirOptions): void;
785
786 interface MakeDirectoryOptions {
787 /**
788 * Indicates whether parent folders should be created.
789 * @default false
790 */
791 recursive?: boolean;
792 /**
793 * A file mode. If a string is passed, it is parsed as an octal integer. If not specified
794 * @default 0o777.
795 */
796 mode?: number;
797 }
798
799 /**
800 * Asynchronous mkdir(2) - create a directory.
801 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
802 * @param options Either the file mode, or an object optionally specifying the file mode and whether parent folders
803 * should be created. If a string is passed, it is parsed as an octal integer. If not specified, defaults to `0o777`.
804 */
805 function mkdir(path: PathLike, options: number | string | MakeDirectoryOptions | undefined | null, callback: NoParamCallback): void;
806
807 /**
808 * Asynchronous mkdir(2) - create a directory with a mode of `0o777`.
809 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
810 */
811 function mkdir(path: PathLike, callback: NoParamCallback): void;
812
813 // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
814 namespace mkdir {
815 /**
816 * Asynchronous mkdir(2) - create a directory.
817 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
818 * @param options Either the file mode, or an object optionally specifying the file mode and whether parent folders
819 * should be created. If a string is passed, it is parsed as an octal integer. If not specified, defaults to `0o777`.
820 */
821 function __promisify__(path: PathLike, options?: number | string | MakeDirectoryOptions | null): Promise<void>;
822 }
823
824 /**
825 * Synchronous mkdir(2) - create a directory.
826 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
827 * @param options Either the file mode, or an object optionally specifying the file mode and whether parent folders
828 * should be created. If a string is passed, it is parsed as an octal integer. If not specified, defaults to `0o777`.
829 */
830 function mkdirSync(path: PathLike, options?: number | string | MakeDirectoryOptions | null): void;
831
832 /**
833 * Asynchronously creates a unique temporary directory.
834 * Generates six random characters to be appended behind a required prefix to create a unique temporary directory.
835 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
836 */
837 function mkdtemp(prefix: string, options: { encoding?: BufferEncoding | null } | BufferEncoding | undefined | null, callback: (err: NodeJS.ErrnoException | null, folder: string) => void): void;
838
839 /**
840 * Asynchronously creates a unique temporary directory.
841 * Generates six random characters to be appended behind a required prefix to create a unique temporary directory.
842 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
843 */
844 function mkdtemp(prefix: string, options: "buffer" | { encoding: "buffer" }, callback: (err: NodeJS.ErrnoException | null, folder: Buffer) => void): void;
845
846 /**
847 * Asynchronously creates a unique temporary directory.
848 * Generates six random characters to be appended behind a required prefix to create a unique temporary directory.
849 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
850 */
851 function mkdtemp(prefix: string, options: { encoding?: string | null } | string | undefined | null, callback: (err: NodeJS.ErrnoException | null, folder: string | Buffer) => void): void;
852
853 /**
854 * Asynchronously creates a unique temporary directory.
855 * Generates six random characters to be appended behind a required prefix to create a unique temporary directory.
856 */
857 function mkdtemp(prefix: string, callback: (err: NodeJS.ErrnoException | null, folder: string) => void): void;
858
859 // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
860 namespace mkdtemp {
861 /**
862 * Asynchronously creates a unique temporary directory.
863 * Generates six random characters to be appended behind a required prefix to create a unique temporary directory.
864 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
865 */
866 function __promisify__(prefix: string, options?: { encoding?: BufferEncoding | null } | BufferEncoding | null): Promise<string>;
867
868 /**
869 * Asynchronously creates a unique temporary directory.
870 * Generates six random characters to be appended behind a required prefix to create a unique temporary directory.
871 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
872 */
873 function __promisify__(prefix: string, options: { encoding: "buffer" } | "buffer"): Promise<Buffer>;
874
875 /**
876 * Asynchronously creates a unique temporary directory.
877 * Generates six random characters to be appended behind a required prefix to create a unique temporary directory.
878 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
879 */
880 function __promisify__(prefix: string, options?: { encoding?: string | null } | string | null): Promise<string | Buffer>;
881 }
882
883 /**
884 * Synchronously creates a unique temporary directory.
885 * Generates six random characters to be appended behind a required prefix to create a unique temporary directory.
886 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
887 */
888 function mkdtempSync(prefix: string, options?: { encoding?: BufferEncoding | null } | BufferEncoding | null): string;
889
890 /**
891 * Synchronously creates a unique temporary directory.
892 * Generates six random characters to be appended behind a required prefix to create a unique temporary directory.
893 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
894 */
895 function mkdtempSync(prefix: string, options: { encoding: "buffer" } | "buffer"): Buffer;
896
897 /**
898 * Synchronously creates a unique temporary directory.
899 * Generates six random characters to be appended behind a required prefix to create a unique temporary directory.
900 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
901 */
902 function mkdtempSync(prefix: string, options?: { encoding?: string | null } | string | null): string | Buffer;
903
904 /**
905 * Asynchronous readdir(3) - read a directory.
906 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
907 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
908 */
909 function readdir(
910 path: PathLike,
911 options: { encoding: BufferEncoding | null; withFileTypes?: false } | BufferEncoding | undefined | null,
912 callback: (err: NodeJS.ErrnoException | null, files: string[]) => void,
913 ): void;
914
915 /**
916 * Asynchronous readdir(3) - read a directory.
917 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
918 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
919 */
920 function readdir(path: PathLike, options: { encoding: "buffer"; withFileTypes?: false } | "buffer", callback: (err: NodeJS.ErrnoException | null, files: Buffer[]) => void): void;
921
922 /**
923 * Asynchronous readdir(3) - read a directory.
924 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
925 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
926 */
927 function readdir(
928 path: PathLike,
929 options: { encoding?: string | null; withFileTypes?: false } | string | undefined | null,
930 callback: (err: NodeJS.ErrnoException | null, files: string[] | Buffer[]) => void,
931 ): void;
932
933 /**
934 * Asynchronous readdir(3) - read a directory.
935 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
936 */
937 function readdir(path: PathLike, callback: (err: NodeJS.ErrnoException | null, files: string[]) => void): void;
938
939 /**
940 * Asynchronous readdir(3) - read a directory.
941 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
942 * @param options If called with `withFileTypes: true` the result data will be an array of Dirent.
943 */
944 function readdir(path: PathLike, options: { encoding?: string | null; withFileTypes: true }, callback: (err: NodeJS.ErrnoException | null, files: Dirent[]) => void): void;
945
946 // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
947 namespace readdir {
948 /**
949 * Asynchronous readdir(3) - read a directory.
950 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
951 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
952 */
953 function __promisify__(path: PathLike, options?: { encoding: BufferEncoding | null; withFileTypes?: false } | BufferEncoding | null): Promise<string[]>;
954
955 /**
956 * Asynchronous readdir(3) - read a directory.
957 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
958 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
959 */
960 function __promisify__(path: PathLike, options: "buffer" | { encoding: "buffer"; withFileTypes?: false }): Promise<Buffer[]>;
961
962 /**
963 * Asynchronous readdir(3) - read a directory.
964 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
965 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
966 */
967 function __promisify__(path: PathLike, options?: { encoding?: string | null; withFileTypes?: false } | string | null): Promise<string[] | Buffer[]>;
968
969 /**
970 * Asynchronous readdir(3) - read a directory.
971 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
972 * @param options If called with `withFileTypes: true` the result data will be an array of Dirent
973 */
974 function __promisify__(path: PathLike, options: { encoding?: string | null; withFileTypes: true }): Promise<Dirent[]>;
975 }
976
977 /**
978 * Synchronous readdir(3) - read a directory.
979 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
980 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
981 */
982 function readdirSync(path: PathLike, options?: { encoding: BufferEncoding | null; withFileTypes?: false } | BufferEncoding | null): string[];
983
984 /**
985 * Synchronous readdir(3) - read a directory.
986 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
987 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
988 */
989 function readdirSync(path: PathLike, options: { encoding: "buffer"; withFileTypes?: false } | "buffer"): Buffer[];
990
991 /**
992 * Synchronous readdir(3) - read a directory.
993 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
994 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
995 */
996 function readdirSync(path: PathLike, options?: { encoding?: string | null; withFileTypes?: false } | string | null): string[] | Buffer[];
997
998 /**
999 * Synchronous readdir(3) - read a directory.
1000 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1001 * @param options If called with `withFileTypes: true` the result data will be an array of Dirent.
1002 */
1003 function readdirSync(path: PathLike, options: { encoding?: string | null; withFileTypes: true }): Dirent[];
1004
1005 /**
1006 * Asynchronous close(2) - close a file descriptor.
1007 * @param fd A file descriptor.
1008 */
1009 function close(fd: number, callback: NoParamCallback): void;
1010
1011 // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
1012 namespace close {
1013 /**
1014 * Asynchronous close(2) - close a file descriptor.
1015 * @param fd A file descriptor.
1016 */
1017 function __promisify__(fd: number): Promise<void>;
1018 }
1019
1020 /**
1021 * Synchronous close(2) - close a file descriptor.
1022 * @param fd A file descriptor.
1023 */
1024 function closeSync(fd: number): void;
1025
1026 /**
1027 * Asynchronous open(2) - open and possibly create a file.
1028 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1029 * @param mode A file mode. If a string is passed, it is parsed as an octal integer. If not supplied, defaults to `0o666`.
1030 */
1031 function open(path: PathLike, flags: string | number, mode: string | number | undefined | null, callback: (err: NodeJS.ErrnoException | null, fd: number) => void): void;
1032
1033 /**
1034 * Asynchronous open(2) - open and possibly create a file. If the file is created, its mode will be `0o666`.
1035 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1036 */
1037 function open(path: PathLike, flags: string | number, callback: (err: NodeJS.ErrnoException | null, fd: number) => void): void;
1038
1039 // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
1040 namespace open {
1041 /**
1042 * Asynchronous open(2) - open and possibly create a file.
1043 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1044 * @param mode A file mode. If a string is passed, it is parsed as an octal integer. If not supplied, defaults to `0o666`.
1045 */
1046 function __promisify__(path: PathLike, flags: string | number, mode?: string | number | null): Promise<number>;
1047 }
1048
1049 /**
1050 * Synchronous open(2) - open and possibly create a file, returning a file descriptor..
1051 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1052 * @param mode A file mode. If a string is passed, it is parsed as an octal integer. If not supplied, defaults to `0o666`.
1053 */
1054 function openSync(path: PathLike, flags: string | number, mode?: string | number | null): number;
1055
1056 /**
1057 * Asynchronously change file timestamps of the file referenced by the supplied path.
1058 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1059 * @param atime The last access time. If a string is provided, it will be coerced to number.
1060 * @param mtime The last modified time. If a string is provided, it will be coerced to number.
1061 */
1062 function utimes(path: PathLike, atime: string | number | Date, mtime: string | number | Date, callback: NoParamCallback): void;
1063
1064 // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
1065 namespace utimes {
1066 /**
1067 * Asynchronously change file timestamps of the file referenced by the supplied path.
1068 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1069 * @param atime The last access time. If a string is provided, it will be coerced to number.
1070 * @param mtime The last modified time. If a string is provided, it will be coerced to number.
1071 */
1072 function __promisify__(path: PathLike, atime: string | number | Date, mtime: string | number | Date): Promise<void>;
1073 }
1074
1075 /**
1076 * Synchronously change file timestamps of the file referenced by the supplied path.
1077 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1078 * @param atime The last access time. If a string is provided, it will be coerced to number.
1079 * @param mtime The last modified time. If a string is provided, it will be coerced to number.
1080 */
1081 function utimesSync(path: PathLike, atime: string | number | Date, mtime: string | number | Date): void;
1082
1083 /**
1084 * Asynchronously change file timestamps of the file referenced by the supplied file descriptor.
1085 * @param fd A file descriptor.
1086 * @param atime The last access time. If a string is provided, it will be coerced to number.
1087 * @param mtime The last modified time. If a string is provided, it will be coerced to number.
1088 */
1089 function futimes(fd: number, atime: string | number | Date, mtime: string | number | Date, callback: NoParamCallback): void;
1090
1091 // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
1092 namespace futimes {
1093 /**
1094 * Asynchronously change file timestamps of the file referenced by the supplied file descriptor.
1095 * @param fd A file descriptor.
1096 * @param atime The last access time. If a string is provided, it will be coerced to number.
1097 * @param mtime The last modified time. If a string is provided, it will be coerced to number.
1098 */
1099 function __promisify__(fd: number, atime: string | number | Date, mtime: string | number | Date): Promise<void>;
1100 }
1101
1102 /**
1103 * Synchronously change file timestamps of the file referenced by the supplied file descriptor.
1104 * @param fd A file descriptor.
1105 * @param atime The last access time. If a string is provided, it will be coerced to number.
1106 * @param mtime The last modified time. If a string is provided, it will be coerced to number.
1107 */
1108 function futimesSync(fd: number, atime: string | number | Date, mtime: string | number | Date): void;
1109
1110 /**
1111 * Asynchronous fsync(2) - synchronize a file's in-core state with the underlying storage device.
1112 * @param fd A file descriptor.
1113 */
1114 function fsync(fd: number, callback: NoParamCallback): void;
1115
1116 // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
1117 namespace fsync {
1118 /**
1119 * Asynchronous fsync(2) - synchronize a file's in-core state with the underlying storage device.
1120 * @param fd A file descriptor.
1121 */
1122 function __promisify__(fd: number): Promise<void>;
1123 }
1124
1125 /**
1126 * Synchronous fsync(2) - synchronize a file's in-core state with the underlying storage device.
1127 * @param fd A file descriptor.
1128 */
1129 function fsyncSync(fd: number): void;
1130
1131 /**
1132 * Asynchronously writes `buffer` to the file referenced by the supplied file descriptor.
1133 * @param fd A file descriptor.
1134 * @param offset The part of the buffer to be written. If not supplied, defaults to `0`.
1135 * @param length The number of bytes to write. If not supplied, defaults to `buffer.length - offset`.
1136 * @param position The offset from the beginning of the file where this data should be written. If not supplied, defaults to the current position.
1137 */
1138 function write<TBuffer extends NodeJS.ArrayBufferView>(
1139 fd: number,
1140 buffer: TBuffer,
1141 offset: number | undefined | null,
1142 length: number | undefined | null,
1143 position: number | undefined | null,
1144 callback: (err: NodeJS.ErrnoException | null, written: number, buffer: TBuffer) => void,
1145 ): void;
1146
1147 /**
1148 * Asynchronously writes `buffer` to the file referenced by the supplied file descriptor.
1149 * @param fd A file descriptor.
1150 * @param offset The part of the buffer to be written. If not supplied, defaults to `0`.
1151 * @param length The number of bytes to write. If not supplied, defaults to `buffer.length - offset`.
1152 */
1153 function write<TBuffer extends NodeJS.ArrayBufferView>(
1154 fd: number,
1155 buffer: TBuffer,
1156 offset: number | undefined | null,
1157 length: number | undefined | null,
1158 callback: (err: NodeJS.ErrnoException | null, written: number, buffer: TBuffer) => void,
1159 ): void;
1160
1161 /**
1162 * Asynchronously writes `buffer` to the file referenced by the supplied file descriptor.
1163 * @param fd A file descriptor.
1164 * @param offset The part of the buffer to be written. If not supplied, defaults to `0`.
1165 */
1166 function write<TBuffer extends NodeJS.ArrayBufferView>(
1167 fd: number,
1168 buffer: TBuffer,
1169 offset: number | undefined | null,
1170 callback: (err: NodeJS.ErrnoException | null, written: number, buffer: TBuffer) => void
1171 ): void;
1172
1173 /**
1174 * Asynchronously writes `buffer` to the file referenced by the supplied file descriptor.
1175 * @param fd A file descriptor.
1176 */
1177 function write<TBuffer extends NodeJS.ArrayBufferView>(fd: number, buffer: TBuffer, callback: (err: NodeJS.ErrnoException | null, written: number, buffer: TBuffer) => void): void;
1178
1179 /**
1180 * Asynchronously writes `string` to the file referenced by the supplied file descriptor.
1181 * @param fd A file descriptor.
1182 * @param string A string to write. If something other than a string is supplied it will be coerced to a string.
1183 * @param position The offset from the beginning of the file where this data should be written. If not supplied, defaults to the current position.
1184 * @param encoding The expected string encoding.
1185 */
1186 function write(
1187 fd: number,
1188 string: any,
1189 position: number | undefined | null,
1190 encoding: string | undefined | null,
1191 callback: (err: NodeJS.ErrnoException | null, written: number, str: string) => void,
1192 ): void;
1193
1194 /**
1195 * Asynchronously writes `string` to the file referenced by the supplied file descriptor.
1196 * @param fd A file descriptor.
1197 * @param string A string to write. If something other than a string is supplied it will be coerced to a string.
1198 * @param position The offset from the beginning of the file where this data should be written. If not supplied, defaults to the current position.
1199 */
1200 function write(fd: number, string: any, position: number | undefined | null, callback: (err: NodeJS.ErrnoException | null, written: number, str: string) => void): void;
1201
1202 /**
1203 * Asynchronously writes `string` to the file referenced by the supplied file descriptor.
1204 * @param fd A file descriptor.
1205 * @param string A string to write. If something other than a string is supplied it will be coerced to a string.
1206 */
1207 function write(fd: number, string: any, callback: (err: NodeJS.ErrnoException | null, written: number, str: string) => void): void;
1208
1209 // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
1210 namespace write {
1211 /**
1212 * Asynchronously writes `buffer` to the file referenced by the supplied file descriptor.
1213 * @param fd A file descriptor.
1214 * @param offset The part of the buffer to be written. If not supplied, defaults to `0`.
1215 * @param length The number of bytes to write. If not supplied, defaults to `buffer.length - offset`.
1216 * @param position The offset from the beginning of the file where this data should be written. If not supplied, defaults to the current position.
1217 */
1218 function __promisify__<TBuffer extends NodeJS.ArrayBufferView>(
1219 fd: number,
1220 buffer?: TBuffer,
1221 offset?: number,
1222 length?: number,
1223 position?: number | null,
1224 ): Promise<{ bytesWritten: number, buffer: TBuffer }>;
1225
1226 /**
1227 * Asynchronously writes `string` to the file referenced by the supplied file descriptor.
1228 * @param fd A file descriptor.
1229 * @param string A string to write. If something other than a string is supplied it will be coerced to a string.
1230 * @param position The offset from the beginning of the file where this data should be written. If not supplied, defaults to the current position.
1231 * @param encoding The expected string encoding.
1232 */
1233 function __promisify__(fd: number, string: any, position?: number | null, encoding?: string | null): Promise<{ bytesWritten: number, buffer: string }>;
1234 }
1235
1236 /**
1237 * Synchronously writes `buffer` to the file referenced by the supplied file descriptor, returning the number of bytes written.
1238 * @param fd A file descriptor.
1239 * @param offset The part of the buffer to be written. If not supplied, defaults to `0`.
1240 * @param length The number of bytes to write. If not supplied, defaults to `buffer.length - offset`.
1241 * @param position The offset from the beginning of the file where this data should be written. If not supplied, defaults to the current position.
1242 */
1243 function writeSync(fd: number, buffer: NodeJS.ArrayBufferView, offset?: number | null, length?: number | null, position?: number | null): number;
1244
1245 /**
1246 * Synchronously writes `string` to the file referenced by the supplied file descriptor, returning the number of bytes written.
1247 * @param fd A file descriptor.
1248 * @param string A string to write. If something other than a string is supplied it will be coerced to a string.
1249 * @param position The offset from the beginning of the file where this data should be written. If not supplied, defaults to the current position.
1250 * @param encoding The expected string encoding.
1251 */
1252 function writeSync(fd: number, string: any, position?: number | null, encoding?: string | null): number;
1253
1254 /**
1255 * Asynchronously reads data from the file referenced by the supplied file descriptor.
1256 * @param fd A file descriptor.
1257 * @param buffer The buffer that the data will be written to.
1258 * @param offset The offset in the buffer at which to start writing.
1259 * @param length The number of bytes to read.
1260 * @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.
1261 */
1262 function read<TBuffer extends NodeJS.ArrayBufferView>(
1263 fd: number,
1264 buffer: TBuffer,
1265 offset: number,
1266 length: number,
1267 position: number | null,
1268 callback: (err: NodeJS.ErrnoException | null, bytesRead: number, buffer: TBuffer) => void,
1269 ): void;
1270
1271 // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
1272 namespace read {
1273 /**
1274 * @param fd A file descriptor.
1275 * @param buffer The buffer that the data will be written to.
1276 * @param offset The offset in the buffer at which to start writing.
1277 * @param length The number of bytes to read.
1278 * @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.
1279 */
1280 function __promisify__<TBuffer extends NodeJS.ArrayBufferView>(
1281 fd: number,
1282 buffer: TBuffer,
1283 offset: number,
1284 length: number,
1285 position: number | null
1286 ): Promise<{ bytesRead: number, buffer: TBuffer }>;
1287 }
1288
1289 /**
1290 * Synchronously reads data from the file referenced by the supplied file descriptor, returning the number of bytes read.
1291 * @param fd A file descriptor.
1292 * @param buffer The buffer that the data will be written to.
1293 * @param offset The offset in the buffer at which to start writing.
1294 * @param length The number of bytes to read.
1295 * @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.
1296 */
1297 function readSync(fd: number, buffer: NodeJS.ArrayBufferView, offset: number, length: number, position: number | null): number;
1298
1299 /**
1300 * Asynchronously reads the entire contents of a file.
1301 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1302 * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
1303 * @param options An object that may contain an optional flag.
1304 * If a flag is not provided, it defaults to `'r'`.
1305 */
1306 function readFile(path: PathLike | number, options: { encoding?: null; flag?: string; } | undefined | null, callback: (err: NodeJS.ErrnoException | null, data: Buffer) => void): void;
1307
1308 /**
1309 * Asynchronously reads the entire contents of a file.
1310 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1311 * URL support is _experimental_.
1312 * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
1313 * @param options Either the encoding for the result, or an object that contains the encoding and an optional flag.
1314 * If a flag is not provided, it defaults to `'r'`.
1315 */
1316 function readFile(path: PathLike | number, options: { encoding: string; flag?: string; } | string, callback: (err: NodeJS.ErrnoException | null, data: string) => void): void;
1317
1318 /**
1319 * Asynchronously reads the entire contents of a file.
1320 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1321 * URL support is _experimental_.
1322 * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
1323 * @param options Either the encoding for the result, or an object that contains the encoding and an optional flag.
1324 * If a flag is not provided, it defaults to `'r'`.
1325 */
1326 function readFile(
1327 path: PathLike | number,
1328 options: { encoding?: string | null; flag?: string; } | string | undefined | null,
1329 callback: (err: NodeJS.ErrnoException | null, data: string | Buffer) => void,
1330 ): void;
1331
1332 /**
1333 * Asynchronously reads the entire contents of a file.
1334 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1335 * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
1336 */
1337 function readFile(path: PathLike | number, callback: (err: NodeJS.ErrnoException | null, data: Buffer) => void): void;
1338
1339 // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
1340 namespace readFile {
1341 /**
1342 * Asynchronously reads the entire contents of a file.
1343 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1344 * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
1345 * @param options An object that may contain an optional flag.
1346 * If a flag is not provided, it defaults to `'r'`.
1347 */
1348 function __promisify__(path: PathLike | number, options?: { encoding?: null; flag?: string; } | null): Promise<Buffer>;
1349
1350 /**
1351 * Asynchronously reads the entire contents of a file.
1352 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1353 * URL support is _experimental_.
1354 * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
1355 * @param options Either the encoding for the result, or an object that contains the encoding and an optional flag.
1356 * If a flag is not provided, it defaults to `'r'`.
1357 */
1358 function __promisify__(path: PathLike | number, options: { encoding: string; flag?: string; } | string): Promise<string>;
1359
1360 /**
1361 * Asynchronously reads the entire contents of a file.
1362 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1363 * URL support is _experimental_.
1364 * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
1365 * @param options Either the encoding for the result, or an object that contains the encoding and an optional flag.
1366 * If a flag is not provided, it defaults to `'r'`.
1367 */
1368 function __promisify__(path: PathLike | number, options?: { encoding?: string | null; flag?: string; } | string | null): Promise<string | Buffer>;
1369 }
1370
1371 /**
1372 * Synchronously reads the entire contents of a file.
1373 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1374 * URL support is _experimental_.
1375 * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
1376 * @param options An object that may contain an optional flag. If a flag is not provided, it defaults to `'r'`.
1377 */
1378 function readFileSync(path: PathLike | number, options?: { encoding?: null; flag?: string; } | null): Buffer;
1379
1380 /**
1381 * Synchronously reads the entire contents of a file.
1382 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1383 * URL support is _experimental_.
1384 * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
1385 * @param options Either the encoding for the result, or an object that contains the encoding and an optional flag.
1386 * If a flag is not provided, it defaults to `'r'`.
1387 */
1388 function readFileSync(path: PathLike | number, options: { encoding: string; flag?: string; } | string): string;
1389
1390 /**
1391 * Synchronously reads the entire contents of a file.
1392 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1393 * URL support is _experimental_.
1394 * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
1395 * @param options Either the encoding for the result, or an object that contains the encoding and an optional flag.
1396 * If a flag is not provided, it defaults to `'r'`.
1397 */
1398 function readFileSync(path: PathLike | number, options?: { encoding?: string | null; flag?: string; } | string | null): string | Buffer;
1399
1400 type WriteFileOptions = { encoding?: string | null; mode?: number | string; flag?: string; } | string | null;
1401
1402 /**
1403 * Asynchronously writes data to a file, replacing the file if it already exists.
1404 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1405 * URL support is _experimental_.
1406 * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
1407 * @param data The data to write. If something other than a Buffer or Uint8Array is provided, the value is coerced to a string.
1408 * @param options Either the encoding for the file, or an object optionally specifying the encoding, file mode, and flag.
1409 * If `encoding` is not supplied, the default of `'utf8'` is used.
1410 * If `mode` is not supplied, the default of `0o666` is used.
1411 * If `mode` is a string, it is parsed as an octal integer.
1412 * If `flag` is not supplied, the default of `'w'` is used.
1413 */
1414 function writeFile(path: PathLike | number, data: any, options: WriteFileOptions, callback: NoParamCallback): void;
1415
1416 /**
1417 * Asynchronously writes data to a file, replacing the file if it already exists.
1418 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1419 * URL support is _experimental_.
1420 * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
1421 * @param data The data to write. If something other than a Buffer or Uint8Array is provided, the value is coerced to a string.
1422 */
1423 function writeFile(path: PathLike | number, data: any, callback: NoParamCallback): void;
1424
1425 // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
1426 namespace writeFile {
1427 /**
1428 * Asynchronously writes data to a file, replacing the file if it already exists.
1429 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1430 * URL support is _experimental_.
1431 * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
1432 * @param data The data to write. If something other than a Buffer or Uint8Array is provided, the value is coerced to a string.
1433 * @param options Either the encoding for the file, or an object optionally specifying the encoding, file mode, and flag.
1434 * If `encoding` is not supplied, the default of `'utf8'` is used.
1435 * If `mode` is not supplied, the default of `0o666` is used.
1436 * If `mode` is a string, it is parsed as an octal integer.
1437 * If `flag` is not supplied, the default of `'w'` is used.
1438 */
1439 function __promisify__(path: PathLike | number, data: any, options?: WriteFileOptions): Promise<void>;
1440 }
1441
1442 /**
1443 * Synchronously writes data to a file, replacing the file if it already exists.
1444 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1445 * URL support is _experimental_.
1446 * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
1447 * @param data The data to write. If something other than a Buffer or Uint8Array is provided, the value is coerced to a string.
1448 * @param options Either the encoding for the file, or an object optionally specifying the encoding, file mode, and flag.
1449 * If `encoding` is not supplied, the default of `'utf8'` is used.
1450 * If `mode` is not supplied, the default of `0o666` is used.
1451 * If `mode` is a string, it is parsed as an octal integer.
1452 * If `flag` is not supplied, the default of `'w'` is used.
1453 */
1454 function writeFileSync(path: PathLike | number, data: any, options?: WriteFileOptions): void;
1455
1456 /**
1457 * Asynchronously append data to a file, creating the file if it does not exist.
1458 * @param file A path to a file. If a URL is provided, it must use the `file:` protocol.
1459 * URL support is _experimental_.
1460 * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
1461 * @param data The data to write. If something other than a Buffer or Uint8Array is provided, the value is coerced to a string.
1462 * @param options Either the encoding for the file, or an object optionally specifying the encoding, file mode, and flag.
1463 * If `encoding` is not supplied, the default of `'utf8'` is used.
1464 * If `mode` is not supplied, the default of `0o666` is used.
1465 * If `mode` is a string, it is parsed as an octal integer.
1466 * If `flag` is not supplied, the default of `'a'` is used.
1467 */
1468 function appendFile(file: PathLike | number, data: any, options: WriteFileOptions, callback: NoParamCallback): void;
1469
1470 /**
1471 * Asynchronously append data to a file, creating the file if it does not exist.
1472 * @param file A path to a file. If a URL is provided, it must use the `file:` protocol.
1473 * URL support is _experimental_.
1474 * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
1475 * @param data The data to write. If something other than a Buffer or Uint8Array is provided, the value is coerced to a string.
1476 */
1477 function appendFile(file: PathLike | number, data: any, callback: NoParamCallback): void;
1478
1479 // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
1480 namespace appendFile {
1481 /**
1482 * Asynchronously append data to a file, creating the file if it does not exist.
1483 * @param file A path to a file. If a URL is provided, it must use the `file:` protocol.
1484 * URL support is _experimental_.
1485 * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
1486 * @param data The data to write. If something other than a Buffer or Uint8Array is provided, the value is coerced to a string.
1487 * @param options Either the encoding for the file, or an object optionally specifying the encoding, file mode, and flag.
1488 * If `encoding` is not supplied, the default of `'utf8'` is used.
1489 * If `mode` is not supplied, the default of `0o666` is used.
1490 * If `mode` is a string, it is parsed as an octal integer.
1491 * If `flag` is not supplied, the default of `'a'` is used.
1492 */
1493 function __promisify__(file: PathLike | number, data: any, options?: WriteFileOptions): Promise<void>;
1494 }
1495
1496 /**
1497 * Synchronously append data to a file, creating the file if it does not exist.
1498 * @param file A path to a file. If a URL is provided, it must use the `file:` protocol.
1499 * URL support is _experimental_.
1500 * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
1501 * @param data The data to write. If something other than a Buffer or Uint8Array is provided, the value is coerced to a string.
1502 * @param options Either the encoding for the file, or an object optionally specifying the encoding, file mode, and flag.
1503 * If `encoding` is not supplied, the default of `'utf8'` is used.
1504 * If `mode` is not supplied, the default of `0o666` is used.
1505 * If `mode` is a string, it is parsed as an octal integer.
1506 * If `flag` is not supplied, the default of `'a'` is used.
1507 */
1508 function appendFileSync(file: PathLike | number, data: any, options?: WriteFileOptions): void;
1509
1510 /**
1511 * Watch for changes on `filename`. The callback `listener` will be called each time the file is accessed.
1512 */
1513 function watchFile(filename: PathLike, options: { persistent?: boolean; interval?: number; } | undefined, listener: (curr: Stats, prev: Stats) => void): void;
1514
1515 /**
1516 * Watch for changes on `filename`. The callback `listener` will be called each time the file is accessed.
1517 * @param filename A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
1518 * URL support is _experimental_.
1519 */
1520 function watchFile(filename: PathLike, listener: (curr: Stats, prev: Stats) => void): void;
1521
1522 /**
1523 * Stop watching for changes on `filename`.
1524 * @param filename A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
1525 * URL support is _experimental_.
1526 */
1527 function unwatchFile(filename: PathLike, listener?: (curr: Stats, prev: Stats) => void): void;
1528
1529 /**
1530 * Watch for changes on `filename`, where `filename` is either a file or a directory, returning an `FSWatcher`.
1531 * @param filename A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
1532 * URL support is _experimental_.
1533 * @param options Either the encoding for the filename provided to the listener, or an object optionally specifying encoding, persistent, and recursive options.
1534 * If `encoding` is not supplied, the default of `'utf8'` is used.
1535 * If `persistent` is not supplied, the default of `true` is used.
1536 * If `recursive` is not supplied, the default of `false` is used.
1537 */
1538 function watch(
1539 filename: PathLike,
1540 options: { encoding?: BufferEncoding | null, persistent?: boolean, recursive?: boolean } | BufferEncoding | undefined | null,
1541 listener?: (event: string, filename: string) => void,
1542 ): FSWatcher;
1543
1544 /**
1545 * Watch for changes on `filename`, where `filename` is either a file or a directory, returning an `FSWatcher`.
1546 * @param filename A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
1547 * URL support is _experimental_.
1548 * @param options Either the encoding for the filename provided to the listener, or an object optionally specifying encoding, persistent, and recursive options.
1549 * If `encoding` is not supplied, the default of `'utf8'` is used.
1550 * If `persistent` is not supplied, the default of `true` is used.
1551 * If `recursive` is not supplied, the default of `false` is used.
1552 */
1553 function watch(filename: PathLike, options: { encoding: "buffer", persistent?: boolean, recursive?: boolean } | "buffer", listener?: (event: string, filename: Buffer) => void): FSWatcher;
1554
1555 /**
1556 * Watch for changes on `filename`, where `filename` is either a file or a directory, returning an `FSWatcher`.
1557 * @param filename A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
1558 * URL support is _experimental_.
1559 * @param options Either the encoding for the filename provided to the listener, or an object optionally specifying encoding, persistent, and recursive options.
1560 * If `encoding` is not supplied, the default of `'utf8'` is used.
1561 * If `persistent` is not supplied, the default of `true` is used.
1562 * If `recursive` is not supplied, the default of `false` is used.
1563 */
1564 function watch(
1565 filename: PathLike,
1566 options: { encoding?: string | null, persistent?: boolean, recursive?: boolean } | string | null,
1567 listener?: (event: string, filename: string | Buffer) => void,
1568 ): FSWatcher;
1569
1570 /**
1571 * Watch for changes on `filename`, where `filename` is either a file or a directory, returning an `FSWatcher`.
1572 * @param filename A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
1573 * URL support is _experimental_.
1574 */
1575 function watch(filename: PathLike, listener?: (event: string, filename: string) => any): FSWatcher;
1576
1577 /**
1578 * Asynchronously tests whether or not the given path exists by checking with the file system.
1579 * @deprecated
1580 * @param path A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
1581 * URL support is _experimental_.
1582 */
1583 function exists(path: PathLike, callback: (exists: boolean) => void): void;
1584
1585 // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
1586 namespace exists {
1587 /**
1588 * @param path A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
1589 * URL support is _experimental_.
1590 */
1591 function __promisify__(path: PathLike): Promise<boolean>;
1592 }
1593
1594 /**
1595 * Synchronously tests whether or not the given path exists by checking with the file system.
1596 * @param path A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
1597 * URL support is _experimental_.
1598 */
1599 function existsSync(path: PathLike): boolean;
1600
1601 namespace constants {
1602 // File Access Constants
1603
1604 /** Constant for fs.access(). File is visible to the calling process. */
1605 const F_OK: number;
1606
1607 /** Constant for fs.access(). File can be read by the calling process. */
1608 const R_OK: number;
1609
1610 /** Constant for fs.access(). File can be written by the calling process. */
1611 const W_OK: number;
1612
1613 /** Constant for fs.access(). File can be executed by the calling process. */
1614 const X_OK: number;
1615
1616 // File Copy Constants
1617
1618 /** Constant for fs.copyFile. Flag indicating the destination file should not be overwritten if it already exists. */
1619 const COPYFILE_EXCL: number;
1620
1621 /**
1622 * Constant for fs.copyFile. copy operation will attempt to create a copy-on-write reflink.
1623 * If the underlying platform does not support copy-on-write, then a fallback copy mechanism is used.
1624 */
1625 const COPYFILE_FICLONE: number;
1626
1627 /**
1628 * Constant for fs.copyFile. Copy operation will attempt to create a copy-on-write reflink.
1629 * If the underlying platform does not support copy-on-write, then the operation will fail with an error.
1630 */
1631 const COPYFILE_FICLONE_FORCE: number;
1632
1633 // File Open Constants
1634
1635 /** Constant for fs.open(). Flag indicating to open a file for read-only access. */
1636 const O_RDONLY: number;
1637
1638 /** Constant for fs.open(). Flag indicating to open a file for write-only access. */
1639 const O_WRONLY: number;
1640
1641 /** Constant for fs.open(). Flag indicating to open a file for read-write access. */
1642 const O_RDWR: number;
1643
1644 /** Constant for fs.open(). Flag indicating to create the file if it does not already exist. */
1645 const O_CREAT: number;
1646
1647 /** Constant for fs.open(). Flag indicating that opening a file should fail if the O_CREAT flag is set and the file already exists. */
1648 const O_EXCL: number;
1649
1650 /**
1651 * Constant for fs.open(). Flag indicating that if path identifies a terminal device,
1652 * opening the path shall not cause that terminal to become the controlling terminal for the process
1653 * (if the process does not already have one).
1654 */
1655 const O_NOCTTY: number;
1656
1657 /** 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. */
1658 const O_TRUNC: number;
1659
1660 /** Constant for fs.open(). Flag indicating that data will be appended to the end of the file. */
1661 const O_APPEND: number;
1662
1663 /** Constant for fs.open(). Flag indicating that the open should fail if the path is not a directory. */
1664 const O_DIRECTORY: number;
1665
1666 /**
1667 * constant for fs.open().
1668 * Flag indicating reading accesses to the file system will no longer result in
1669 * an update to the atime information associated with the file.
1670 * This flag is available on Linux operating systems only.
1671 */
1672 const O_NOATIME: number;
1673
1674 /** Constant for fs.open(). Flag indicating that the open should fail if the path is a symbolic link. */
1675 const O_NOFOLLOW: number;
1676
1677 /** Constant for fs.open(). Flag indicating that the file is opened for synchronous I/O. */
1678 const O_SYNC: number;
1679
1680 /** Constant for fs.open(). Flag indicating that the file is opened for synchronous I/O with write operations waiting for data integrity. */
1681 const O_DSYNC: number;
1682
1683 /** Constant for fs.open(). Flag indicating to open the symbolic link itself rather than the resource it is pointing to. */
1684 const O_SYMLINK: number;
1685
1686 /** Constant for fs.open(). When set, an attempt will be made to minimize caching effects of file I/O. */
1687 const O_DIRECT: number;
1688
1689 /** Constant for fs.open(). Flag indicating to open the file in nonblocking mode when possible. */
1690 const O_NONBLOCK: number;
1691
1692 // File Type Constants
1693
1694 /** Constant for fs.Stats mode property for determining a file's type. Bit mask used to extract the file type code. */
1695 const S_IFMT: number;
1696
1697 /** Constant for fs.Stats mode property for determining a file's type. File type constant for a regular file. */
1698 const S_IFREG: number;
1699
1700 /** Constant for fs.Stats mode property for determining a file's type. File type constant for a directory. */
1701 const S_IFDIR: number;
1702
1703 /** Constant for fs.Stats mode property for determining a file's type. File type constant for a character-oriented device file. */
1704 const S_IFCHR: number;
1705
1706 /** Constant for fs.Stats mode property for determining a file's type. File type constant for a block-oriented device file. */
1707 const S_IFBLK: number;
1708
1709 /** Constant for fs.Stats mode property for determining a file's type. File type constant for a FIFO/pipe. */
1710 const S_IFIFO: number;
1711
1712 /** Constant for fs.Stats mode property for determining a file's type. File type constant for a symbolic link. */
1713 const S_IFLNK: number;
1714
1715 /** Constant for fs.Stats mode property for determining a file's type. File type constant for a socket. */
1716 const S_IFSOCK: number;
1717
1718 // File Mode Constants
1719
1720 /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating readable, writable and executable by owner. */
1721 const S_IRWXU: number;
1722
1723 /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating readable by owner. */
1724 const S_IRUSR: number;
1725
1726 /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating writable by owner. */
1727 const S_IWUSR: number;
1728
1729 /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating executable by owner. */
1730 const S_IXUSR: number;
1731
1732 /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating readable, writable and executable by group. */
1733 const S_IRWXG: number;
1734
1735 /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating readable by group. */
1736 const S_IRGRP: number;
1737
1738 /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating writable by group. */
1739 const S_IWGRP: number;
1740
1741 /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating executable by group. */
1742 const S_IXGRP: number;
1743
1744 /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating readable, writable and executable by others. */
1745 const S_IRWXO: number;
1746
1747 /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating readable by others. */
1748 const S_IROTH: number;
1749
1750 /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating writable by others. */
1751 const S_IWOTH: number;
1752
1753 /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating executable by others. */
1754 const S_IXOTH: number;
1755
1756 /**
1757 * When set, a memory file mapping is used to access the file. This flag
1758 * is available on Windows operating systems only. On other operating systems,
1759 * this flag is ignored.
1760 */
1761 const UV_FS_O_FILEMAP: number;
1762 }
1763
1764 /**
1765 * Asynchronously tests a user's permissions for the file specified by path.
1766 * @param path A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
1767 * URL support is _experimental_.
1768 */
1769 function access(path: PathLike, mode: number | undefined, callback: NoParamCallback): void;
1770
1771 /**
1772 * Asynchronously tests a user's permissions for the file specified by path.
1773 * @param path A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
1774 * URL support is _experimental_.
1775 */
1776 function access(path: PathLike, callback: NoParamCallback): void;
1777
1778 // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
1779 namespace access {
1780 /**
1781 * Asynchronously tests a user's permissions for the file specified by path.
1782 * @param path A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
1783 * URL support is _experimental_.
1784 */
1785 function __promisify__(path: PathLike, mode?: number): Promise<void>;
1786 }
1787
1788 /**
1789 * Synchronously tests a user's permissions for the file specified by path.
1790 * @param path A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
1791 * URL support is _experimental_.
1792 */
1793 function accessSync(path: PathLike, mode?: number): void;
1794
1795 /**
1796 * Returns a new `ReadStream` object.
1797 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1798 * URL support is _experimental_.
1799 */
1800 function createReadStream(path: PathLike, options?: string | {
1801 flags?: string;
1802 encoding?: string;
1803 fd?: number;
1804 mode?: number;
1805 autoClose?: boolean;
1806 /**
1807 * @default false
1808 */
1809 emitClose?: boolean;
1810 start?: number;
1811 end?: number;
1812 highWaterMark?: number;
1813 }): ReadStream;
1814
1815 /**
1816 * Returns a new `WriteStream` object.
1817 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1818 * URL support is _experimental_.
1819 */
1820 function createWriteStream(path: PathLike, options?: string | {
1821 flags?: string;
1822 encoding?: string;
1823 fd?: number;
1824 mode?: number;
1825 autoClose?: boolean;
1826 emitClose?: 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}