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