UNPKG

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