UNPKG

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