UNPKG

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