UNPKG

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