UNPKG

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