UNPKG

167 kBTypeScriptView Raw
1/**
2 * The `fs` module enables interacting with the file system in a
3 * way modeled on standard POSIX functions.
4 *
5 * To use the promise-based APIs:
6 *
7 * ```js
8 * // Using ESM Module syntax:
9 * import * as fs from 'fs/promises';
10 * ```
11 *
12 * ```js
13 * // Using CommonJS syntax:
14 * const fs = require('fs/promises');
15 * ```
16 *
17 * To use the callback and sync APIs:
18 *
19 * ```js
20 * // Using ESM Module syntax:
21 * import * as fs from 'fs';
22 * ```
23 *
24 * ```js
25 * // Using CommonJS syntax:
26 * const fs = require('fs');
27 * ```
28 *
29 * All file system operations have synchronous, callback, and promise-based
30 * forms, and are accessible using both CommonJS syntax and ES6 Modules (ESM).
31 * @see [source](https://github.com/nodejs/node/blob/v16.4.2/lib/fs.js)
32 */
33declare module 'fs' {
34 import * as stream from 'node:stream';
35 import { Abortable, EventEmitter } from 'node:events';
36 import { URL } from 'node:url';
37 import * as promises from 'node:fs/promises';
38 export { promises };
39 /**
40 * Valid types for path values in "fs".
41 */
42 export type PathLike = string | Buffer | URL;
43 export type PathOrFileDescriptor = PathLike | number;
44 export type TimeLike = string | number | Date;
45 export type NoParamCallback = (err: NodeJS.ErrnoException | null) => void;
46 export type BufferEncodingOption =
47 | 'buffer'
48 | {
49 encoding: 'buffer';
50 };
51 export interface ObjectEncodingOptions {
52 encoding?: BufferEncoding | null | undefined;
53 }
54 export type EncodingOption = ObjectEncodingOptions | BufferEncoding | undefined | null;
55 export type OpenMode = number | string;
56 export type Mode = number | string;
57 export interface StatsBase<T> {
58 isFile(): boolean;
59 isDirectory(): boolean;
60 isBlockDevice(): boolean;
61 isCharacterDevice(): boolean;
62 isSymbolicLink(): boolean;
63 isFIFO(): boolean;
64 isSocket(): boolean;
65 dev: T;
66 ino: T;
67 mode: T;
68 nlink: T;
69 uid: T;
70 gid: T;
71 rdev: T;
72 size: T;
73 blksize: T;
74 blocks: T;
75 atimeMs: T;
76 mtimeMs: T;
77 ctimeMs: T;
78 birthtimeMs: T;
79 atime: Date;
80 mtime: Date;
81 ctime: Date;
82 birthtime: Date;
83 }
84 export interface Stats extends StatsBase<number> {}
85 /**
86 * A `<fs.Stats>` object provides information about a file.
87 *
88 * Objects returned from {@link stat}, {@link lstat} and {@link fstat} and
89 * their synchronous counterparts are of this type.
90 * If `bigint` in the `options` passed to those methods is true, the numeric values
91 * will be `bigint` instead of `number`, and the object will contain additional
92 * nanosecond-precision properties suffixed with `Ns`.
93 *
94 * ```console
95 * Stats {
96 * dev: 2114,
97 * ino: 48064969,
98 * mode: 33188,
99 * nlink: 1,
100 * uid: 85,
101 * gid: 100,
102 * rdev: 0,
103 * size: 527,
104 * blksize: 4096,
105 * blocks: 8,
106 * atimeMs: 1318289051000.1,
107 * mtimeMs: 1318289051000.1,
108 * ctimeMs: 1318289051000.1,
109 * birthtimeMs: 1318289051000.1,
110 * atime: Mon, 10 Oct 2011 23:24:11 GMT,
111 * mtime: Mon, 10 Oct 2011 23:24:11 GMT,
112 * ctime: Mon, 10 Oct 2011 23:24:11 GMT,
113 * birthtime: Mon, 10 Oct 2011 23:24:11 GMT }
114 * ```
115 *
116 * `bigint` version:
117 *
118 * ```console
119 * BigIntStats {
120 * dev: 2114n,
121 * ino: 48064969n,
122 * mode: 33188n,
123 * nlink: 1n,
124 * uid: 85n,
125 * gid: 100n,
126 * rdev: 0n,
127 * size: 527n,
128 * blksize: 4096n,
129 * blocks: 8n,
130 * atimeMs: 1318289051000n,
131 * mtimeMs: 1318289051000n,
132 * ctimeMs: 1318289051000n,
133 * birthtimeMs: 1318289051000n,
134 * atimeNs: 1318289051000000000n,
135 * mtimeNs: 1318289051000000000n,
136 * ctimeNs: 1318289051000000000n,
137 * birthtimeNs: 1318289051000000000n,
138 * atime: Mon, 10 Oct 2011 23:24:11 GMT,
139 * mtime: Mon, 10 Oct 2011 23:24:11 GMT,
140 * ctime: Mon, 10 Oct 2011 23:24:11 GMT,
141 * birthtime: Mon, 10 Oct 2011 23:24:11 GMT }
142 * ```
143 * @since v0.1.21
144 */
145 export class Stats {}
146 /**
147 * A representation of a directory entry, which can be a file or a subdirectory
148 * within the directory, as returned by reading from an `<fs.Dir>`. The
149 * directory entry is a combination of the file name and file type pairs.
150 *
151 * Additionally, when {@link readdir} or {@link readdirSync} is called with
152 * the `withFileTypes` option set to `true`, the resulting array is filled with `<fs.Dirent>` objects, rather than strings or `<Buffer>` s.
153 * @since v10.10.0
154 */
155 export class Dirent {
156 /**
157 * Returns `true` if the `<fs.Dirent>` object describes a regular file.
158 * @since v10.10.0
159 */
160 isFile(): boolean;
161 /**
162 * Returns `true` if the `<fs.Dirent>` object describes a file system
163 * directory.
164 * @since v10.10.0
165 */
166 isDirectory(): boolean;
167 /**
168 * Returns `true` if the `<fs.Dirent>` object describes a block device.
169 * @since v10.10.0
170 */
171 isBlockDevice(): boolean;
172 /**
173 * Returns `true` if the `<fs.Dirent>` object describes a character device.
174 * @since v10.10.0
175 */
176 isCharacterDevice(): boolean;
177 /**
178 * Returns `true` if the `<fs.Dirent>` object describes a symbolic link.
179 * @since v10.10.0
180 */
181 isSymbolicLink(): boolean;
182 /**
183 * Returns `true` if the `<fs.Dirent>` object describes a first-in-first-out
184 * (FIFO) pipe.
185 * @since v10.10.0
186 */
187 isFIFO(): boolean;
188 /**
189 * Returns `true` if the `<fs.Dirent>` object describes a socket.
190 * @since v10.10.0
191 */
192 isSocket(): boolean;
193 /**
194 * The file name that this `<fs.Dirent>` object refers to. The type of this
195 * value is determined by the `options.encoding` passed to {@link readdir} or {@link readdirSync}.
196 * @since v10.10.0
197 */
198 name: string;
199 }
200 /**
201 * A class representing a directory stream.
202 *
203 * Created by {@link opendir}, {@link opendirSync}, or {@link romises.opendir}.
204 *
205 * ```js
206 * import { opendir } from 'fs/promises';
207 *
208 * try {
209 * const dir = await opendir('./');
210 * for await (const dirent of dir)
211 * console.log(dirent.name);
212 * } catch (err) {
213 * console.error(err);
214 * }
215 * ```
216 *
217 * When using the async iterator, the `<fs.Dir>` object will be automatically
218 * closed after the iterator exits.
219 * @since v12.12.0
220 */
221 export class Dir implements AsyncIterable<Dirent> {
222 /**
223 * The read-only path of this directory as was provided to {@link opendir},{@link opendirSync}, or {@link romises.opendir}.
224 * @since v12.12.0
225 */
226 readonly path: string;
227 /**
228 * Asynchronously iterates over the directory via `readdir(3)` until all entries have been read.
229 */
230 [Symbol.asyncIterator](): AsyncIterableIterator<Dirent>;
231 /**
232 * Asynchronously close the directory's underlying resource handle.
233 * Subsequent reads will result in errors.
234 *
235 * A promise is returned that will be resolved after the resource has been
236 * closed.
237 * @since v12.12.0
238 */
239 close(): Promise<void>;
240 close(cb: NoParamCallback): void;
241 /**
242 * Synchronously close the directory's underlying resource handle.
243 * Subsequent reads will result in errors.
244 * @since v12.12.0
245 */
246 closeSync(): void;
247 /**
248 * Asynchronously read the next directory entry via [`readdir(3)`](http://man7.org/linux/man-pages/man3/readdir.3.html) as an `<fs.Dirent>`.
249 *
250 * A promise is returned that will be resolved with an `<fs.Dirent>`, or `null`if there are no more directory entries to read.
251 *
252 * Directory entries returned by this function are in no particular order as
253 * provided by the operating system's underlying directory mechanisms.
254 * Entries added or removed while iterating over the directory might not be
255 * included in the iteration results.
256 * @since v12.12.0
257 * @return containing {fs.Dirent|null}
258 */
259 read(): Promise<Dirent | null>;
260 read(cb: (err: NodeJS.ErrnoException | null, dirEnt: Dirent | null) => void): void;
261 /**
262 * Synchronously read the next directory entry as an `<fs.Dirent>`. See the
263 * POSIX [`readdir(3)`](http://man7.org/linux/man-pages/man3/readdir.3.html) documentation for more detail.
264 *
265 * If there are no more directory entries to read, `null` will be returned.
266 *
267 * Directory entries returned by this function are in no particular order as
268 * provided by the operating system's underlying directory mechanisms.
269 * Entries added or removed while iterating over the directory might not be
270 * included in the iteration results.
271 * @since v12.12.0
272 */
273 readSync(): Dirent | null;
274 }
275 export interface FSWatcher extends EventEmitter {
276 /**
277 * Stop watching for changes on the given `<fs.FSWatcher>`. Once stopped, the `<fs.FSWatcher>` object is no longer usable.
278 * @since v0.5.8
279 */
280 close(): void;
281 /**
282 * events.EventEmitter
283 * 1. change
284 * 2. error
285 */
286 addListener(event: string, listener: (...args: any[]) => void): this;
287 addListener(event: 'change', listener: (eventType: string, filename: string | Buffer) => void): this;
288 addListener(event: 'error', listener: (error: Error) => void): this;
289 addListener(event: 'close', listener: () => void): this;
290 on(event: string, listener: (...args: any[]) => void): this;
291 on(event: 'change', listener: (eventType: string, filename: string | Buffer) => void): this;
292 on(event: 'error', listener: (error: Error) => void): this;
293 on(event: 'close', listener: () => void): this;
294 once(event: string, listener: (...args: any[]) => void): this;
295 once(event: 'change', listener: (eventType: string, filename: string | Buffer) => void): this;
296 once(event: 'error', listener: (error: Error) => void): this;
297 once(event: 'close', listener: () => void): this;
298 prependListener(event: string, listener: (...args: any[]) => void): this;
299 prependListener(event: 'change', listener: (eventType: string, filename: string | Buffer) => void): this;
300 prependListener(event: 'error', listener: (error: Error) => void): this;
301 prependListener(event: 'close', listener: () => void): this;
302 prependOnceListener(event: string, listener: (...args: any[]) => void): this;
303 prependOnceListener(event: 'change', listener: (eventType: string, filename: string | Buffer) => void): this;
304 prependOnceListener(event: 'error', listener: (error: Error) => void): this;
305 prependOnceListener(event: 'close', listener: () => void): this;
306 }
307 /**
308 * Instances of `<fs.ReadStream>` are created and returned using the {@link createReadStream} function.
309 * @since v0.1.93
310 */
311 export class ReadStream extends stream.Readable {
312 close(): void;
313 /**
314 * The number of bytes that have been read so far.
315 * @since v6.4.0
316 */
317 bytesRead: number;
318 /**
319 * The path to the file the stream is reading from as specified in the first
320 * argument to `fs.createReadStream()`. If `path` is passed as a string, then`readStream.path` will be a string. If `path` is passed as a `<Buffer>`, then`readStream.path` will be a
321 * `<Buffer>`.
322 * @since v0.1.93
323 */
324 path: string | Buffer;
325 /**
326 * This property is `true` if the underlying file has not been opened yet,
327 * i.e. before the `'ready'` event is emitted.
328 * @since v11.2.0, v10.16.0
329 */
330 pending: boolean;
331 /**
332 * events.EventEmitter
333 * 1. open
334 * 2. close
335 * 3. ready
336 */
337 addListener(event: 'close', listener: () => void): this;
338 addListener(event: 'data', listener: (chunk: Buffer | string) => void): this;
339 addListener(event: 'end', listener: () => void): this;
340 addListener(event: 'error', listener: (err: Error) => void): this;
341 addListener(event: 'open', listener: (fd: number) => void): this;
342 addListener(event: 'pause', listener: () => void): this;
343 addListener(event: 'readable', listener: () => void): this;
344 addListener(event: 'ready', listener: () => void): this;
345 addListener(event: 'resume', listener: () => void): this;
346 addListener(event: string | symbol, listener: (...args: any[]) => void): this;
347 on(event: 'close', listener: () => void): this;
348 on(event: 'data', listener: (chunk: Buffer | string) => void): this;
349 on(event: 'end', listener: () => void): this;
350 on(event: 'error', listener: (err: Error) => void): this;
351 on(event: 'open', listener: (fd: number) => void): this;
352 on(event: 'pause', listener: () => void): this;
353 on(event: 'readable', listener: () => void): this;
354 on(event: 'ready', listener: () => void): this;
355 on(event: 'resume', listener: () => void): this;
356 on(event: string | symbol, listener: (...args: any[]) => void): this;
357 once(event: 'close', listener: () => void): this;
358 once(event: 'data', listener: (chunk: Buffer | string) => void): this;
359 once(event: 'end', listener: () => void): this;
360 once(event: 'error', listener: (err: Error) => void): this;
361 once(event: 'open', listener: (fd: number) => void): this;
362 once(event: 'pause', listener: () => void): this;
363 once(event: 'readable', listener: () => void): this;
364 once(event: 'ready', listener: () => void): this;
365 once(event: 'resume', listener: () => void): this;
366 once(event: string | symbol, listener: (...args: any[]) => void): this;
367 prependListener(event: 'close', listener: () => void): this;
368 prependListener(event: 'data', listener: (chunk: Buffer | string) => void): this;
369 prependListener(event: 'end', listener: () => void): this;
370 prependListener(event: 'error', listener: (err: Error) => void): this;
371 prependListener(event: 'open', listener: (fd: number) => void): this;
372 prependListener(event: 'pause', listener: () => void): this;
373 prependListener(event: 'readable', listener: () => void): this;
374 prependListener(event: 'ready', listener: () => void): this;
375 prependListener(event: 'resume', listener: () => void): this;
376 prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
377 prependOnceListener(event: 'close', listener: () => void): this;
378 prependOnceListener(event: 'data', listener: (chunk: Buffer | string) => void): this;
379 prependOnceListener(event: 'end', listener: () => void): this;
380 prependOnceListener(event: 'error', listener: (err: Error) => void): this;
381 prependOnceListener(event: 'open', listener: (fd: number) => void): this;
382 prependOnceListener(event: 'pause', listener: () => void): this;
383 prependOnceListener(event: 'readable', listener: () => void): this;
384 prependOnceListener(event: 'ready', listener: () => void): this;
385 prependOnceListener(event: 'resume', listener: () => void): this;
386 prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
387 }
388 /**
389 * * Extends `<stream.Writable>`
390 *
391 * Instances of `<fs.WriteStream>` are created and returned using the {@link createWriteStream} function.
392 * @since v0.1.93
393 */
394 export class WriteStream extends stream.Writable {
395 /**
396 * Closes `writeStream`. Optionally accepts a
397 * callback that will be executed once the `writeStream`is closed.
398 * @since v0.9.4
399 */
400 close(): void;
401 /**
402 * The number of bytes written so far. Does not include data that is still queued
403 * for writing.
404 * @since v0.4.7
405 */
406 bytesWritten: number;
407 /**
408 * The path to the file the stream is writing to as specified in the first
409 * argument to {@link createWriteStream}. If `path` is passed as a string, then`writeStream.path` will be a string. If `path` is passed as a `<Buffer>`, then`writeStream.path` will be a
410 * `<Buffer>`.
411 * @since v0.1.93
412 */
413 path: string | Buffer;
414 /**
415 * This property is `true` if the underlying file has not been opened yet,
416 * i.e. before the `'ready'` event is emitted.
417 * @since v11.2.0
418 */
419 pending: boolean;
420 /**
421 * events.EventEmitter
422 * 1. open
423 * 2. close
424 * 3. ready
425 */
426 addListener(event: 'close', listener: () => void): this;
427 addListener(event: 'drain', listener: () => void): this;
428 addListener(event: 'error', listener: (err: Error) => void): this;
429 addListener(event: 'finish', listener: () => void): this;
430 addListener(event: 'open', listener: (fd: number) => void): this;
431 addListener(event: 'pipe', listener: (src: stream.Readable) => void): this;
432 addListener(event: 'ready', listener: () => void): this;
433 addListener(event: 'unpipe', listener: (src: stream.Readable) => void): this;
434 addListener(event: string | symbol, listener: (...args: any[]) => void): this;
435 on(event: 'close', listener: () => void): this;
436 on(event: 'drain', listener: () => void): this;
437 on(event: 'error', listener: (err: Error) => void): this;
438 on(event: 'finish', listener: () => void): this;
439 on(event: 'open', listener: (fd: number) => void): this;
440 on(event: 'pipe', listener: (src: stream.Readable) => void): this;
441 on(event: 'ready', listener: () => void): this;
442 on(event: 'unpipe', listener: (src: stream.Readable) => void): this;
443 on(event: string | symbol, listener: (...args: any[]) => void): this;
444 once(event: 'close', listener: () => void): this;
445 once(event: 'drain', listener: () => void): this;
446 once(event: 'error', listener: (err: Error) => void): this;
447 once(event: 'finish', listener: () => void): this;
448 once(event: 'open', listener: (fd: number) => void): this;
449 once(event: 'pipe', listener: (src: stream.Readable) => void): this;
450 once(event: 'ready', listener: () => void): this;
451 once(event: 'unpipe', listener: (src: stream.Readable) => void): this;
452 once(event: string | symbol, listener: (...args: any[]) => void): this;
453 prependListener(event: 'close', listener: () => void): this;
454 prependListener(event: 'drain', listener: () => void): this;
455 prependListener(event: 'error', listener: (err: Error) => void): this;
456 prependListener(event: 'finish', listener: () => void): this;
457 prependListener(event: 'open', listener: (fd: number) => void): this;
458 prependListener(event: 'pipe', listener: (src: stream.Readable) => void): this;
459 prependListener(event: 'ready', listener: () => void): this;
460 prependListener(event: 'unpipe', listener: (src: stream.Readable) => void): this;
461 prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
462 prependOnceListener(event: 'close', listener: () => void): this;
463 prependOnceListener(event: 'drain', listener: () => void): this;
464 prependOnceListener(event: 'error', listener: (err: Error) => void): this;
465 prependOnceListener(event: 'finish', listener: () => void): this;
466 prependOnceListener(event: 'open', listener: (fd: number) => void): this;
467 prependOnceListener(event: 'pipe', listener: (src: stream.Readable) => void): this;
468 prependOnceListener(event: 'ready', listener: () => void): this;
469 prependOnceListener(event: 'unpipe', listener: (src: stream.Readable) => void): this;
470 prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
471 }
472 /**
473 * Asynchronously rename file at `oldPath` to the pathname provided
474 * as `newPath`. In the case that `newPath` already exists, it will
475 * be overwritten. If there is a directory at `newPath`, an error will
476 * be raised instead. No arguments other than a possible exception are
477 * given to the completion callback.
478 *
479 * See also: [`rename(2)`](http://man7.org/linux/man-pages/man2/rename.2.html).
480 *
481 * ```js
482 * import { rename } from 'fs';
483 *
484 * rename('oldFile.txt', 'newFile.txt', (err) => {
485 * if (err) throw err;
486 * console.log('Rename complete!');
487 * });
488 * ```
489 * @since v0.0.2
490 */
491 export function rename(oldPath: PathLike, newPath: PathLike, callback: NoParamCallback): void;
492 export namespace rename {
493 /**
494 * Asynchronous rename(2) - Change the name or location of a file or directory.
495 * @param oldPath A path to a file. If a URL is provided, it must use the `file:` protocol.
496 * URL support is _experimental_.
497 * @param newPath A path to a file. If a URL is provided, it must use the `file:` protocol.
498 * URL support is _experimental_.
499 */
500 function __promisify__(oldPath: PathLike, newPath: PathLike): Promise<void>;
501 }
502 /**
503 * Renames the file from `oldPath` to `newPath`. Returns `undefined`.
504 *
505 * See the POSIX [`rename(2)`](http://man7.org/linux/man-pages/man2/rename.2.html) documentation for more details.
506 * @since v0.1.21
507 */
508 export function renameSync(oldPath: PathLike, newPath: PathLike): void;
509 /**
510 * Truncates the file. No arguments other than a possible exception are
511 * given to the completion callback. A file descriptor can also be passed as the
512 * first argument. In this case, `fs.ftruncate()` is called.
513 *
514 * Passing a file descriptor is deprecated and may result in an error being thrown
515 * in the future.
516 *
517 * See the POSIX [`truncate(2)`](http://man7.org/linux/man-pages/man2/truncate.2.html) documentation for more details.
518 * @since v0.8.6
519 * @param [len=0]
520 */
521 export function truncate(path: PathLike, len: number | undefined | null, callback: NoParamCallback): void;
522 /**
523 * Asynchronous truncate(2) - Truncate a file to a specified length.
524 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
525 */
526 export function truncate(path: PathLike, callback: NoParamCallback): void;
527 export namespace truncate {
528 /**
529 * Asynchronous truncate(2) - Truncate a file to a specified length.
530 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
531 * @param len If not specified, defaults to `0`.
532 */
533 function __promisify__(path: PathLike, len?: number | null): Promise<void>;
534 }
535 /**
536 * Truncates the file. Returns `undefined`. A file descriptor can also be
537 * passed as the first argument. In this case, `fs.ftruncateSync()` is called.
538 *
539 * Passing a file descriptor is deprecated and may result in an error being thrown
540 * in the future.
541 * @since v0.8.6
542 * @param [len=0]
543 */
544 export function truncateSync(path: PathLike, len?: number | null): void;
545 /**
546 * Truncates the file descriptor. No arguments other than a possible exception are
547 * given to the completion callback.
548 *
549 * See the POSIX [`ftruncate(2)`](http://man7.org/linux/man-pages/man2/ftruncate.2.html) documentation for more detail.
550 *
551 * If the file referred to by the file descriptor was larger than `len` bytes, only
552 * the first `len` bytes will be retained in the file.
553 *
554 * For example, the following program retains only the first four bytes of the
555 * file:
556 *
557 * ```js
558 * import { open, close, ftruncate } from 'fs';
559 *
560 * function closeFd(fd) {
561 * close(fd, (err) => {
562 * if (err) throw err;
563 * });
564 * }
565 *
566 * open('temp.txt', 'r+', (err, fd) => {
567 * if (err) throw err;
568 *
569 * try {
570 * ftruncate(fd, 4, (err) => {
571 * closeFd(fd);
572 * if (err) throw err;
573 * });
574 * } catch (err) {
575 * closeFd(fd);
576 * if (err) throw err;
577 * }
578 * });
579 * ```
580 *
581 * If the file previously was shorter than `len` bytes, it is extended, and the
582 * extended part is filled with null bytes (`'\0'`):
583 *
584 * If `len` is negative then `0` will be used.
585 * @since v0.8.6
586 * @param [len=0]
587 */
588 export function ftruncate(fd: number, len: number | undefined | null, callback: NoParamCallback): void;
589 /**
590 * Asynchronous ftruncate(2) - Truncate a file to a specified length.
591 * @param fd A file descriptor.
592 */
593 export function ftruncate(fd: number, callback: NoParamCallback): void;
594 export namespace ftruncate {
595 /**
596 * Asynchronous ftruncate(2) - Truncate a file to a specified length.
597 * @param fd A file descriptor.
598 * @param len If not specified, defaults to `0`.
599 */
600 function __promisify__(fd: number, len?: number | null): Promise<void>;
601 }
602 /**
603 * Truncates the file descriptor. Returns `undefined`.
604 *
605 * For detailed information, see the documentation of the asynchronous version of
606 * this API: {@link ftruncate}.
607 * @since v0.8.6
608 * @param [len=0]
609 */
610 export function ftruncateSync(fd: number, len?: number | null): void;
611 /**
612 * Asynchronously changes owner and group of a file. No arguments other than a
613 * possible exception are given to the completion callback.
614 *
615 * See the POSIX [`chown(2)`](http://man7.org/linux/man-pages/man2/chown.2.html) documentation for more detail.
616 * @since v0.1.97
617 */
618 export function chown(path: PathLike, uid: number, gid: number, callback: NoParamCallback): void;
619 export namespace chown {
620 /**
621 * Asynchronous chown(2) - Change ownership of a file.
622 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
623 */
624 function __promisify__(path: PathLike, uid: number, gid: number): Promise<void>;
625 }
626 /**
627 * Synchronously changes owner and group of a file. Returns `undefined`.
628 * This is the synchronous version of {@link chown}.
629 *
630 * See the POSIX [`chown(2)`](http://man7.org/linux/man-pages/man2/chown.2.html) documentation for more detail.
631 * @since v0.1.97
632 */
633 export function chownSync(path: PathLike, uid: number, gid: number): void;
634 /**
635 * Sets the owner of the file. No arguments other than a possible exception are
636 * given to the completion callback.
637 *
638 * See the POSIX [`fchown(2)`](http://man7.org/linux/man-pages/man2/fchown.2.html) documentation for more detail.
639 * @since v0.4.7
640 */
641 export function fchown(fd: number, uid: number, gid: number, callback: NoParamCallback): void;
642 export namespace fchown {
643 /**
644 * Asynchronous fchown(2) - Change ownership of a file.
645 * @param fd A file descriptor.
646 */
647 function __promisify__(fd: number, uid: number, gid: number): Promise<void>;
648 }
649 /**
650 * Sets the owner of the file. Returns `undefined`.
651 *
652 * See the POSIX [`fchown(2)`](http://man7.org/linux/man-pages/man2/fchown.2.html) documentation for more detail.
653 * @since v0.4.7
654 * @param uid The file's new owner's user id.
655 * @param gid The file's new group's group id.
656 */
657 export function fchownSync(fd: number, uid: number, gid: number): void;
658 /**
659 * Set the owner of the symbolic link. No arguments other than a possible
660 * exception are given to the completion callback.
661 *
662 * See the POSIX [`lchown(2)`](http://man7.org/linux/man-pages/man2/lchown.2.html) documentation for more detail.
663 */
664 export function lchown(path: PathLike, uid: number, gid: number, callback: NoParamCallback): void;
665 export namespace lchown {
666 /**
667 * Asynchronous lchown(2) - Change ownership of a file. Does not dereference symbolic links.
668 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
669 */
670 function __promisify__(path: PathLike, uid: number, gid: number): Promise<void>;
671 }
672 /**
673 * Set the owner for the path. Returns `undefined`.
674 *
675 * See the POSIX [`lchown(2)`](http://man7.org/linux/man-pages/man2/lchown.2.html) documentation for more details.
676 * @param uid The file's new owner's user id.
677 * @param gid The file's new group's group id.
678 */
679 export function lchownSync(path: PathLike, uid: number, gid: number): void;
680 /**
681 * Changes the access and modification times of a file in the same way as {@link utimes}, with the difference that if the path refers to a symbolic
682 * link, then the link is not dereferenced: instead, the timestamps of the
683 * symbolic link itself are changed.
684 *
685 * No arguments other than a possible exception are given to the completion
686 * callback.
687 * @since v14.5.0, v12.19.0
688 */
689 export function lutimes(path: PathLike, atime: TimeLike, mtime: TimeLike, callback: NoParamCallback): void;
690 export namespace lutimes {
691 /**
692 * Changes the access and modification times of a file in the same way as `fsPromises.utimes()`,
693 * with the difference that if the path refers to a symbolic link, then the link is not
694 * dereferenced: instead, the timestamps of the symbolic link itself are changed.
695 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
696 * @param atime The last access time. If a string is provided, it will be coerced to number.
697 * @param mtime The last modified time. If a string is provided, it will be coerced to number.
698 */
699 function __promisify__(path: PathLike, atime: TimeLike, mtime: TimeLike): Promise<void>;
700 }
701 /**
702 * Change the file system timestamps of the symbolic link referenced by `path`.
703 * Returns `undefined`, or throws an exception when parameters are incorrect or
704 * the operation fails. This is the synchronous version of {@link lutimes}.
705 * @since v14.5.0, v12.19.0
706 */
707 export function lutimesSync(path: PathLike, atime: TimeLike, mtime: TimeLike): void;
708 /**
709 * Asynchronously changes the permissions of a file. No arguments other than a
710 * possible exception are given to the completion callback.
711 *
712 * See the POSIX [`chmod(2)`](http://man7.org/linux/man-pages/man2/chmod.2.html) documentation for more detail.
713 *
714 * ```js
715 * import { chmod } from 'fs';
716 *
717 * chmod('my_file.txt', 0o775, (err) => {
718 * if (err) throw err;
719 * console.log('The permissions for file "my_file.txt" have been changed!');
720 * });
721 * ```
722 * @since v0.1.30
723 */
724 export function chmod(path: PathLike, mode: Mode, callback: NoParamCallback): void;
725 export namespace chmod {
726 /**
727 * Asynchronous chmod(2) - Change permissions of a file.
728 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
729 * @param mode A file mode. If a string is passed, it is parsed as an octal integer.
730 */
731 function __promisify__(path: PathLike, mode: Mode): Promise<void>;
732 }
733 /**
734 * For detailed information, see the documentation of the asynchronous version of
735 * this API: {@link chmod}.
736 *
737 * See the POSIX [`chmod(2)`](http://man7.org/linux/man-pages/man2/chmod.2.html) documentation for more detail.
738 * @since v0.6.7
739 */
740 export function chmodSync(path: PathLike, mode: Mode): void;
741 /**
742 * Sets the permissions on the file. No arguments other than a possible exception
743 * are given to the completion callback.
744 *
745 * See the POSIX [`fchmod(2)`](http://man7.org/linux/man-pages/man2/fchmod.2.html) documentation for more detail.
746 * @since v0.4.7
747 */
748 export function fchmod(fd: number, mode: Mode, callback: NoParamCallback): void;
749 export namespace fchmod {
750 /**
751 * Asynchronous fchmod(2) - Change permissions of a file.
752 * @param fd A file descriptor.
753 * @param mode A file mode. If a string is passed, it is parsed as an octal integer.
754 */
755 function __promisify__(fd: number, mode: Mode): Promise<void>;
756 }
757 /**
758 * Sets the permissions on the file. Returns `undefined`.
759 *
760 * See the POSIX [`fchmod(2)`](http://man7.org/linux/man-pages/man2/fchmod.2.html) documentation for more detail.
761 * @since v0.4.7
762 */
763 export function fchmodSync(fd: number, mode: Mode): void;
764 /**
765 * Changes the permissions on a symbolic link. No arguments other than a possible
766 * exception are given to the completion callback.
767 *
768 * This method is only implemented on macOS.
769 *
770 * See the POSIX [`lchmod(2)`](https://www.freebsd.org/cgi/man.cgi?query=lchmod&sektion=2) documentation for more detail.
771 * @deprecated Since v0.4.7
772 */
773 export function lchmod(path: PathLike, mode: Mode, callback: NoParamCallback): void;
774 export namespace lchmod {
775 /**
776 * Asynchronous lchmod(2) - Change permissions of a file. Does not dereference symbolic links.
777 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
778 * @param mode A file mode. If a string is passed, it is parsed as an octal integer.
779 */
780 function __promisify__(path: PathLike, mode: Mode): Promise<void>;
781 }
782 /**
783 * Changes the permissions on a symbolic link. Returns `undefined`.
784 *
785 * This method is only implemented on macOS.
786 *
787 * See the POSIX [`lchmod(2)`](https://www.freebsd.org/cgi/man.cgi?query=lchmod&sektion=2) documentation for more detail.
788 * @deprecated Since v0.4.7
789 */
790 export function lchmodSync(path: PathLike, mode: Mode): void;
791 /**
792 * Asynchronous [`stat(2)`](http://man7.org/linux/man-pages/man2/stat.2.html). The callback gets two arguments `(err, stats)` where`stats` is an `<fs.Stats>` object.
793 *
794 * In case of an error, the `err.code` will be one of `Common System Errors`.
795 *
796 * Using `fs.stat()` to check for the existence of a file before calling`fs.open()`, `fs.readFile()` or `fs.writeFile()` is not recommended.
797 * Instead, user code should open/read/write the file directly and handle the
798 * error raised if the file is not available.
799 *
800 * To check if a file exists without manipulating it afterwards, {@link access} is recommended.
801 *
802 * For example, given the following directory structure:
803 *
804 * ```text
805 * - txtDir
806 * -- file.txt
807 * - app.js
808 * ```
809 *
810 * The next program will check for the stats of the given paths:
811 *
812 * ```js
813 * import { stat } from 'fs';
814 *
815 * const pathsToCheck = ['./txtDir', './txtDir/file.txt'];
816 *
817 * for (let i = 0; i < pathsToCheck.length; i++) {
818 * stat(pathsToCheck[i], (err, stats) => {
819 * console.log(stats.isDirectory());
820 * console.log(stats);
821 * });
822 * }
823 * ```
824 *
825 * The resulting output will resemble:
826 *
827 * ```console
828 * true
829 * Stats {
830 * dev: 16777220,
831 * mode: 16877,
832 * nlink: 3,
833 * uid: 501,
834 * gid: 20,
835 * rdev: 0,
836 * blksize: 4096,
837 * ino: 14214262,
838 * size: 96,
839 * blocks: 0,
840 * atimeMs: 1561174653071.963,
841 * mtimeMs: 1561174614583.3518,
842 * ctimeMs: 1561174626623.5366,
843 * birthtimeMs: 1561174126937.2893,
844 * atime: 2019-06-22T03:37:33.072Z,
845 * mtime: 2019-06-22T03:36:54.583Z,
846 * ctime: 2019-06-22T03:37:06.624Z,
847 * birthtime: 2019-06-22T03:28:46.937Z
848 * }
849 * false
850 * Stats {
851 * dev: 16777220,
852 * mode: 33188,
853 * nlink: 1,
854 * uid: 501,
855 * gid: 20,
856 * rdev: 0,
857 * blksize: 4096,
858 * ino: 14214074,
859 * size: 8,
860 * blocks: 8,
861 * atimeMs: 1561174616618.8555,
862 * mtimeMs: 1561174614584,
863 * ctimeMs: 1561174614583.8145,
864 * birthtimeMs: 1561174007710.7478,
865 * atime: 2019-06-22T03:36:56.619Z,
866 * mtime: 2019-06-22T03:36:54.584Z,
867 * ctime: 2019-06-22T03:36:54.584Z,
868 * birthtime: 2019-06-22T03:26:47.711Z
869 * }
870 * ```
871 * @since v0.0.2
872 */
873 export function stat(path: PathLike, callback: (err: NodeJS.ErrnoException | null, stats: Stats) => void): void;
874 export function stat(
875 path: PathLike,
876 options:
877 | (StatOptions & {
878 bigint?: false | undefined;
879 })
880 | undefined,
881 callback: (err: NodeJS.ErrnoException | null, stats: Stats) => void
882 ): void;
883 export function stat(
884 path: PathLike,
885 options: StatOptions & {
886 bigint: true;
887 },
888 callback: (err: NodeJS.ErrnoException | null, stats: BigIntStats) => void
889 ): void;
890 export function stat(path: PathLike, options: StatOptions | undefined, callback: (err: NodeJS.ErrnoException | null, stats: Stats | BigIntStats) => void): void;
891 export namespace stat {
892 /**
893 * Asynchronous stat(2) - Get file status.
894 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
895 */
896 function __promisify__(
897 path: PathLike,
898 options?: StatOptions & {
899 bigint?: false | undefined;
900 }
901 ): Promise<Stats>;
902 function __promisify__(
903 path: PathLike,
904 options: StatOptions & {
905 bigint: true;
906 }
907 ): Promise<BigIntStats>;
908 function __promisify__(path: PathLike, options?: StatOptions): Promise<Stats | BigIntStats>;
909 }
910 export interface StatSyncFn<TDescriptor = PathLike> extends Function {
911 (path: TDescriptor, options?: undefined): Stats;
912 (
913 path: TDescriptor,
914 options?: StatOptions & {
915 bigint?: false | undefined;
916 throwIfNoEntry: false;
917 }
918 ): Stats | undefined;
919 (
920 path: TDescriptor,
921 options: StatOptions & {
922 bigint: true;
923 throwIfNoEntry: false;
924 }
925 ): BigIntStats | undefined;
926 (
927 path: TDescriptor,
928 options?: StatOptions & {
929 bigint?: false | undefined;
930 }
931 ): Stats;
932 (
933 path: TDescriptor,
934 options: StatOptions & {
935 bigint: true;
936 }
937 ): BigIntStats;
938 (
939 path: TDescriptor,
940 options: StatOptions & {
941 bigint: boolean;
942 throwIfNoEntry?: false | undefined;
943 }
944 ): Stats | BigIntStats;
945 (path: TDescriptor, options?: StatOptions): Stats | BigIntStats | undefined;
946 }
947 /**
948 * Synchronous stat(2) - Get file status.
949 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
950 */
951 export const statSync: StatSyncFn;
952 /**
953 * Invokes the callback with the `<fs.Stats>` for the file descriptor.
954 *
955 * See the POSIX [`fstat(2)`](http://man7.org/linux/man-pages/man2/fstat.2.html) documentation for more detail.
956 * @since v0.1.95
957 */
958 export function fstat(fd: number, callback: (err: NodeJS.ErrnoException | null, stats: Stats) => void): void;
959 export function fstat(
960 fd: number,
961 options:
962 | (StatOptions & {
963 bigint?: false | undefined;
964 })
965 | undefined,
966 callback: (err: NodeJS.ErrnoException | null, stats: Stats) => void
967 ): void;
968 export function fstat(
969 fd: number,
970 options: StatOptions & {
971 bigint: true;
972 },
973 callback: (err: NodeJS.ErrnoException | null, stats: BigIntStats) => void
974 ): void;
975 export function fstat(fd: number, options: StatOptions | undefined, callback: (err: NodeJS.ErrnoException | null, stats: Stats | BigIntStats) => void): void;
976 export namespace fstat {
977 /**
978 * Asynchronous fstat(2) - Get file status.
979 * @param fd A file descriptor.
980 */
981 function __promisify__(
982 fd: number,
983 options?: StatOptions & {
984 bigint?: false | undefined;
985 }
986 ): Promise<Stats>;
987 function __promisify__(
988 fd: number,
989 options: StatOptions & {
990 bigint: true;
991 }
992 ): Promise<BigIntStats>;
993 function __promisify__(fd: number, options?: StatOptions): Promise<Stats | BigIntStats>;
994 }
995 /**
996 * Synchronous fstat(2) - Get file status.
997 * @param fd A file descriptor.
998 */
999 export const fstatSync: StatSyncFn<number>;
1000 /**
1001 * Retrieves the `<fs.Stats>` for the symbolic link referred to by the path.
1002 * The callback gets two arguments `(err, stats)` where `stats` is a `<fs.Stats>` object. `lstat()` is identical to `stat()`, except that if `path` is a symbolic
1003 * link, then the link itself is stat-ed, not the file that it refers to.
1004 *
1005 * See the POSIX [`lstat(2)`](http://man7.org/linux/man-pages/man2/lstat.2.html) documentation for more details.
1006 * @since v0.1.30
1007 */
1008 export function lstat(path: PathLike, callback: (err: NodeJS.ErrnoException | null, stats: Stats) => void): void;
1009 export function lstat(
1010 path: PathLike,
1011 options:
1012 | (StatOptions & {
1013 bigint?: false | undefined;
1014 })
1015 | undefined,
1016 callback: (err: NodeJS.ErrnoException | null, stats: Stats) => void
1017 ): void;
1018 export function lstat(
1019 path: PathLike,
1020 options: StatOptions & {
1021 bigint: true;
1022 },
1023 callback: (err: NodeJS.ErrnoException | null, stats: BigIntStats) => void
1024 ): void;
1025 export function lstat(path: PathLike, options: StatOptions | undefined, callback: (err: NodeJS.ErrnoException | null, stats: Stats | BigIntStats) => void): void;
1026 export namespace lstat {
1027 /**
1028 * Asynchronous lstat(2) - Get file status. Does not dereference symbolic links.
1029 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1030 */
1031 function __promisify__(
1032 path: PathLike,
1033 options?: StatOptions & {
1034 bigint?: false | undefined;
1035 }
1036 ): Promise<Stats>;
1037 function __promisify__(
1038 path: PathLike,
1039 options: StatOptions & {
1040 bigint: true;
1041 }
1042 ): Promise<BigIntStats>;
1043 function __promisify__(path: PathLike, options?: StatOptions): Promise<Stats | BigIntStats>;
1044 }
1045 /**
1046 * Synchronous lstat(2) - Get file status. Does not dereference symbolic links.
1047 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1048 */
1049 export const lstatSync: StatSyncFn;
1050 /**
1051 * Creates a new link from the `existingPath` to the `newPath`. See the POSIX[`link(2)`](http://man7.org/linux/man-pages/man2/link.2.html) documentation for more detail. No arguments other than a
1052 * possible
1053 * exception are given to the completion callback.
1054 * @since v0.1.31
1055 */
1056 export function link(existingPath: PathLike, newPath: PathLike, callback: NoParamCallback): void;
1057 export namespace link {
1058 /**
1059 * Asynchronous link(2) - Create a new link (also known as a hard link) to an existing file.
1060 * @param existingPath A path to a file. If a URL is provided, it must use the `file:` protocol.
1061 * @param newPath A path to a file. If a URL is provided, it must use the `file:` protocol.
1062 */
1063 function __promisify__(existingPath: PathLike, newPath: PathLike): Promise<void>;
1064 }
1065 /**
1066 * Creates a new link from the `existingPath` to the `newPath`. See the POSIX[`link(2)`](http://man7.org/linux/man-pages/man2/link.2.html) documentation for more detail. Returns `undefined`.
1067 * @since v0.1.31
1068 */
1069 export function linkSync(existingPath: PathLike, newPath: PathLike): void;
1070 /**
1071 * Creates the link called `path` pointing to `target`. No arguments other than a
1072 * possible exception are given to the completion callback.
1073 *
1074 * See the POSIX [`symlink(2)`](http://man7.org/linux/man-pages/man2/symlink.2.html) documentation for more details.
1075 *
1076 * The `type` argument is only available on Windows and ignored on other platforms.
1077 * It can be set to `'dir'`, `'file'`, or `'junction'`. If the `type` argument is
1078 * not set, Node.js will autodetect `target` type and use `'file'` or `'dir'`. If
1079 * the `target` does not exist, `'file'` will be used. Windows junction points
1080 * require the destination path to be absolute. When using `'junction'`, the`target` argument will automatically be normalized to absolute path.
1081 *
1082 * Relative targets are relative to the link’s parent directory.
1083 *
1084 * ```js
1085 * import { symlink } from 'fs';
1086 *
1087 * symlink('./mew', './example/mewtwo', callback);
1088 * ```
1089 *
1090 * The above example creates a symbolic link `mewtwo` in the `example` which points
1091 * to `mew` in the same directory:
1092 *
1093 * ```bash
1094 * $ tree example/
1095 * example/
1096 * ├── mew
1097 * └── mewtwo -> ./mew
1098 * ```
1099 * @since v0.1.31
1100 */
1101 export function symlink(target: PathLike, path: PathLike, type: symlink.Type | undefined | null, callback: NoParamCallback): void;
1102 /**
1103 * Asynchronous symlink(2) - Create a new symbolic link to an existing file.
1104 * @param target A path to an existing file. If a URL is provided, it must use the `file:` protocol.
1105 * @param path A path to the new symlink. If a URL is provided, it must use the `file:` protocol.
1106 */
1107 export function symlink(target: PathLike, path: PathLike, callback: NoParamCallback): void;
1108 export namespace symlink {
1109 /**
1110 * Asynchronous symlink(2) - Create a new symbolic link to an existing file.
1111 * @param target A path to an existing file. If a URL is provided, it must use the `file:` protocol.
1112 * @param path A path to the new symlink. If a URL is provided, it must use the `file:` protocol.
1113 * @param type May be set to `'dir'`, `'file'`, or `'junction'` (default is `'file'`) and is only available on Windows (ignored on other platforms).
1114 * When using `'junction'`, the `target` argument will automatically be normalized to an absolute path.
1115 */
1116 function __promisify__(target: PathLike, path: PathLike, type?: string | null): Promise<void>;
1117 type Type = 'dir' | 'file' | 'junction';
1118 }
1119 /**
1120 * Returns `undefined`.
1121 *
1122 * For detailed information, see the documentation of the asynchronous version of
1123 * this API: {@link symlink}.
1124 * @since v0.1.31
1125 */
1126 export function symlinkSync(target: PathLike, path: PathLike, type?: symlink.Type | null): void;
1127 /**
1128 * Reads the contents of the symbolic link referred to by `path`. The callback gets
1129 * two arguments `(err, linkString)`.
1130 *
1131 * See the POSIX [`readlink(2)`](http://man7.org/linux/man-pages/man2/readlink.2.html) documentation for more details.
1132 *
1133 * The optional `options` argument can be a string specifying an encoding, or an
1134 * object with an `encoding` property specifying the character encoding to use for
1135 * the link path passed to the callback. If the `encoding` is set to `'buffer'`,
1136 * the link path returned will be passed as a `<Buffer>` object.
1137 * @since v0.1.31
1138 */
1139 export function readlink(path: PathLike, options: EncodingOption, callback: (err: NodeJS.ErrnoException | null, linkString: string) => void): void;
1140 /**
1141 * Asynchronous readlink(2) - read value of a symbolic link.
1142 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1143 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
1144 */
1145 export function readlink(path: PathLike, options: BufferEncodingOption, callback: (err: NodeJS.ErrnoException | null, linkString: Buffer) => void): void;
1146 /**
1147 * Asynchronous readlink(2) - read value of a symbolic link.
1148 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1149 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
1150 */
1151 export function readlink(path: PathLike, options: EncodingOption, callback: (err: NodeJS.ErrnoException | null, linkString: string | Buffer) => void): void;
1152 /**
1153 * Asynchronous readlink(2) - read value of a symbolic link.
1154 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1155 */
1156 export function readlink(path: PathLike, callback: (err: NodeJS.ErrnoException | null, linkString: string) => void): void;
1157 export namespace readlink {
1158 /**
1159 * Asynchronous readlink(2) - read value of a symbolic link.
1160 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1161 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
1162 */
1163 function __promisify__(path: PathLike, options?: EncodingOption): Promise<string>;
1164 /**
1165 * Asynchronous readlink(2) - read value of a symbolic link.
1166 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1167 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
1168 */
1169 function __promisify__(path: PathLike, options: BufferEncodingOption): Promise<Buffer>;
1170 /**
1171 * Asynchronous readlink(2) - read value of a symbolic link.
1172 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1173 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
1174 */
1175 function __promisify__(path: PathLike, options?: EncodingOption): Promise<string | Buffer>;
1176 }
1177 /**
1178 * Returns the symbolic link's string value.
1179 *
1180 * See the POSIX [`readlink(2)`](http://man7.org/linux/man-pages/man2/readlink.2.html) documentation for more details.
1181 *
1182 * The optional `options` argument can be a string specifying an encoding, or an
1183 * object with an `encoding` property specifying the character encoding to use for
1184 * the link path returned. If the `encoding` is set to `'buffer'`,
1185 * the link path returned will be passed as a `<Buffer>` object.
1186 * @since v0.1.31
1187 */
1188 export function readlinkSync(path: PathLike, options?: EncodingOption): string;
1189 /**
1190 * Synchronous readlink(2) - read value of a symbolic link.
1191 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1192 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
1193 */
1194 export function readlinkSync(path: PathLike, options: BufferEncodingOption): Buffer;
1195 /**
1196 * Synchronous readlink(2) - read value of a symbolic link.
1197 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1198 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
1199 */
1200 export function readlinkSync(path: PathLike, options?: EncodingOption): string | Buffer;
1201 /**
1202 * Asynchronously computes the canonical pathname by resolving `.`, `..` and
1203 * symbolic links.
1204 *
1205 * A canonical pathname is not necessarily unique. Hard links and bind mounts can
1206 * expose a file system entity through many pathnames.
1207 *
1208 * This function behaves like [`realpath(3)`](http://man7.org/linux/man-pages/man3/realpath.3.html), with some exceptions:
1209 *
1210 * 1. No case conversion is performed on case-insensitive file systems.
1211 * 2. The maximum number of symbolic links is platform-independent and generally
1212 * (much) higher than what the native [`realpath(3)`](http://man7.org/linux/man-pages/man3/realpath.3.html) implementation supports.
1213 *
1214 * The `callback` gets two arguments `(err, resolvedPath)`. May use `process.cwd`to resolve relative paths.
1215 *
1216 * Only paths that can be converted to UTF8 strings are supported.
1217 *
1218 * The optional `options` argument can be a string specifying an encoding, or an
1219 * object with an `encoding` property specifying the character encoding to use for
1220 * the path passed to the callback. If the `encoding` is set to `'buffer'`,
1221 * the path returned will be passed as a `<Buffer>` object.
1222 *
1223 * If `path` resolves to a socket or a pipe, the function will return a system
1224 * dependent name for that object.
1225 * @since v0.1.31
1226 */
1227 export function realpath(path: PathLike, options: EncodingOption, callback: (err: NodeJS.ErrnoException | null, resolvedPath: string) => void): void;
1228 /**
1229 * Asynchronous realpath(3) - return the canonicalized absolute pathname.
1230 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1231 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
1232 */
1233 export function realpath(path: PathLike, options: BufferEncodingOption, callback: (err: NodeJS.ErrnoException | null, resolvedPath: Buffer) => void): void;
1234 /**
1235 * Asynchronous realpath(3) - return the canonicalized absolute pathname.
1236 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1237 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
1238 */
1239 export function realpath(path: PathLike, options: EncodingOption, callback: (err: NodeJS.ErrnoException | null, resolvedPath: string | Buffer) => void): void;
1240 /**
1241 * Asynchronous realpath(3) - return the canonicalized absolute pathname.
1242 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1243 */
1244 export function realpath(path: PathLike, callback: (err: NodeJS.ErrnoException | null, resolvedPath: string) => void): void;
1245 export namespace realpath {
1246 /**
1247 * Asynchronous realpath(3) - return the canonicalized absolute pathname.
1248 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1249 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
1250 */
1251 function __promisify__(path: PathLike, options?: EncodingOption): Promise<string>;
1252 /**
1253 * Asynchronous realpath(3) - return the canonicalized absolute pathname.
1254 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1255 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
1256 */
1257 function __promisify__(path: PathLike, options: BufferEncodingOption): Promise<Buffer>;
1258 /**
1259 * Asynchronous realpath(3) - return the canonicalized absolute pathname.
1260 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1261 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
1262 */
1263 function __promisify__(path: PathLike, options?: EncodingOption): Promise<string | Buffer>;
1264 /**
1265 * Asynchronous [`realpath(3)`](http://man7.org/linux/man-pages/man3/realpath.3.html).
1266 *
1267 * The `callback` gets two arguments `(err, resolvedPath)`.
1268 *
1269 * Only paths that can be converted to UTF8 strings are supported.
1270 *
1271 * The optional `options` argument can be a string specifying an encoding, or an
1272 * object with an `encoding` property specifying the character encoding to use for
1273 * the path passed to the callback. If the `encoding` is set to `'buffer'`,
1274 * the path returned will be passed as a `<Buffer>` object.
1275 *
1276 * On Linux, when Node.js is linked against musl libc, the procfs file system must
1277 * be mounted on `/proc` in order for this function to work. Glibc does not have
1278 * this restriction.
1279 * @since v9.2.0
1280 */
1281 function native(path: PathLike, options: EncodingOption, callback: (err: NodeJS.ErrnoException | null, resolvedPath: string) => void): void;
1282 function native(path: PathLike, options: BufferEncodingOption, callback: (err: NodeJS.ErrnoException | null, resolvedPath: Buffer) => void): void;
1283 function native(path: PathLike, options: EncodingOption, callback: (err: NodeJS.ErrnoException | null, resolvedPath: string | Buffer) => void): void;
1284 function native(path: PathLike, callback: (err: NodeJS.ErrnoException | null, resolvedPath: string) => void): void;
1285 }
1286 /**
1287 * Returns the resolved pathname.
1288 *
1289 * For detailed information, see the documentation of the asynchronous version of
1290 * this API: {@link realpath}.
1291 * @since v0.1.31
1292 */
1293 export function realpathSync(path: PathLike, options?: EncodingOption): string;
1294 /**
1295 * Synchronous realpath(3) - return the canonicalized absolute pathname.
1296 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1297 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
1298 */
1299 export function realpathSync(path: PathLike, options: BufferEncodingOption): Buffer;
1300 /**
1301 * Synchronous realpath(3) - return the canonicalized absolute pathname.
1302 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1303 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
1304 */
1305 export function realpathSync(path: PathLike, options?: EncodingOption): string | Buffer;
1306 export namespace realpathSync {
1307 function native(path: PathLike, options?: EncodingOption): string;
1308 function native(path: PathLike, options: BufferEncodingOption): Buffer;
1309 function native(path: PathLike, options?: EncodingOption): string | Buffer;
1310 }
1311 /**
1312 * Asynchronously removes a file or symbolic link. No arguments other than a
1313 * possible exception are given to the completion callback.
1314 *
1315 * ```js
1316 * import { unlink } from 'fs';
1317 * // Assuming that 'path/file.txt' is a regular file.
1318 * unlink('path/file.txt', (err) => {
1319 * if (err) throw err;
1320 * console.log('path/file.txt was deleted');
1321 * });
1322 * ```
1323 *
1324 * `fs.unlink()` will not work on a directory, empty or otherwise. To remove a
1325 * directory, use {@link rmdir}.
1326 *
1327 * See the POSIX [`unlink(2)`](http://man7.org/linux/man-pages/man2/unlink.2.html) documentation for more details.
1328 * @since v0.0.2
1329 */
1330 export function unlink(path: PathLike, callback: NoParamCallback): void;
1331 export namespace unlink {
1332 /**
1333 * Asynchronous unlink(2) - delete a name and possibly the file it refers to.
1334 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1335 */
1336 function __promisify__(path: PathLike): Promise<void>;
1337 }
1338 /**
1339 * Synchronous [`unlink(2)`](http://man7.org/linux/man-pages/man2/unlink.2.html). Returns `undefined`.
1340 * @since v0.1.21
1341 */
1342 export function unlinkSync(path: PathLike): void;
1343 export interface RmDirOptions {
1344 /**
1345 * If an `EBUSY`, `EMFILE`, `ENFILE`, `ENOTEMPTY`, or
1346 * `EPERM` error is encountered, Node.js will retry the operation with a linear
1347 * backoff wait of `retryDelay` ms longer on each try. This option represents the
1348 * number of retries. This option is ignored if the `recursive` option is not
1349 * `true`.
1350 * @default 0
1351 */
1352 maxRetries?: number | undefined;
1353 /**
1354 * @deprecated since v14.14.0 In future versions of Node.js and will trigger a warning
1355 * `fs.rmdir(path, { recursive: true })` will throw if `path` does not exist or is a file.
1356 * Use `fs.rm(path, { recursive: true, force: true })` instead.
1357 *
1358 * If `true`, perform a recursive directory removal. In
1359 * recursive mode soperations are retried on failure.
1360 * @default false
1361 */
1362 recursive?: boolean | undefined;
1363 /**
1364 * The amount of time in milliseconds to wait between retries.
1365 * This option is ignored if the `recursive` option is not `true`.
1366 * @default 100
1367 */
1368 retryDelay?: number | undefined;
1369 }
1370 /**
1371 * Asynchronous [`rmdir(2)`](http://man7.org/linux/man-pages/man2/rmdir.2.html). No arguments other than a possible exception are given
1372 * to the completion callback.
1373 *
1374 * Using `fs.rmdir()` on a file (not a directory) results in an `ENOENT` error on
1375 * Windows and an `ENOTDIR` error on POSIX.
1376 *
1377 * To get a behavior similar to the `rm -rf` Unix command, use {@link rm} with options `{ recursive: true, force: true }`.
1378 * @since v0.0.2
1379 */
1380 export function rmdir(path: PathLike, callback: NoParamCallback): void;
1381 export function rmdir(path: PathLike, options: RmDirOptions, callback: NoParamCallback): void;
1382 export namespace rmdir {
1383 /**
1384 * Asynchronous rmdir(2) - delete a directory.
1385 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1386 */
1387 function __promisify__(path: PathLike, options?: RmDirOptions): Promise<void>;
1388 }
1389 /**
1390 * Synchronous [`rmdir(2)`](http://man7.org/linux/man-pages/man2/rmdir.2.html). Returns `undefined`.
1391 *
1392 * Using `fs.rmdirSync()` on a file (not a directory) results in an `ENOENT` error
1393 * on Windows and an `ENOTDIR` error on POSIX.
1394 *
1395 * To get a behavior similar to the `rm -rf` Unix command, use {@link rmSync} with options `{ recursive: true, force: true }`.
1396 * @since v0.1.21
1397 */
1398 export function rmdirSync(path: PathLike, options?: RmDirOptions): void;
1399 export interface RmOptions {
1400 /**
1401 * When `true`, exceptions will be ignored if `path` does not exist.
1402 * @default false
1403 */
1404 force?: boolean | undefined;
1405 /**
1406 * If an `EBUSY`, `EMFILE`, `ENFILE`, `ENOTEMPTY`, or
1407 * `EPERM` error is encountered, Node.js will retry the operation with a linear
1408 * backoff wait of `retryDelay` ms longer on each try. This option represents the
1409 * number of retries. This option is ignored if the `recursive` option is not
1410 * `true`.
1411 * @default 0
1412 */
1413 maxRetries?: number | undefined;
1414 /**
1415 * If `true`, perform a recursive directory removal. In
1416 * recursive mode, operations are retried on failure.
1417 * @default false
1418 */
1419 recursive?: boolean | undefined;
1420 /**
1421 * The amount of time in milliseconds to wait between retries.
1422 * This option is ignored if the `recursive` option is not `true`.
1423 * @default 100
1424 */
1425 retryDelay?: number | undefined;
1426 }
1427 /**
1428 * Asynchronously removes files and directories (modeled on the standard POSIX `rm`utility). No arguments other than a possible exception are given to the
1429 * completion callback.
1430 * @since v14.14.0
1431 */
1432 export function rm(path: PathLike, callback: NoParamCallback): void;
1433 export function rm(path: PathLike, options: RmOptions, callback: NoParamCallback): void;
1434 export namespace rm {
1435 /**
1436 * Asynchronously removes files and directories (modeled on the standard POSIX `rm` utility).
1437 */
1438 function __promisify__(path: PathLike, options?: RmOptions): Promise<void>;
1439 }
1440 /**
1441 * Synchronously removes files and directories (modeled on the standard POSIX `rm`utility). Returns `undefined`.
1442 * @since v14.14.0
1443 */
1444 export function rmSync(path: PathLike, options?: RmOptions): void;
1445 export interface MakeDirectoryOptions {
1446 /**
1447 * Indicates whether parent folders should be created.
1448 * If a folder was created, the path to the first created folder will be returned.
1449 * @default false
1450 */
1451 recursive?: boolean | undefined;
1452 /**
1453 * A file mode. If a string is passed, it is parsed as an octal integer. If not specified
1454 * @default 0o777
1455 */
1456 mode?: Mode | undefined;
1457 }
1458 /**
1459 * Asynchronously creates a directory.
1460 *
1461 * The callback is given a possible exception and, if `recursive` is `true`, the
1462 * first directory path created, `(err, [path])`.`path` can still be `undefined` when `recursive` is `true`, if no directory was
1463 * created.
1464 *
1465 * The optional `options` argument can be an integer specifying `mode` (permission
1466 * and sticky bits), or an object with a `mode` property and a `recursive`property indicating whether parent directories should be created. Calling`fs.mkdir()` when `path` is a directory that
1467 * exists results in an error only
1468 * when `recursive` is false.
1469 *
1470 * ```js
1471 * import { mkdir } from 'fs';
1472 *
1473 * // Creates /tmp/a/apple, regardless of whether `/tmp` and /tmp/a exist.
1474 * mkdir('/tmp/a/apple', { recursive: true }, (err) => {
1475 * if (err) throw err;
1476 * });
1477 * ```
1478 *
1479 * On Windows, using `fs.mkdir()` on the root directory even with recursion will
1480 * result in an error:
1481 *
1482 * ```js
1483 * import { mkdir } from 'fs';
1484 *
1485 * mkdir('/', { recursive: true }, (err) => {
1486 * // => [Error: EPERM: operation not permitted, mkdir 'C:\']
1487 * });
1488 * ```
1489 *
1490 * See the POSIX [`mkdir(2)`](http://man7.org/linux/man-pages/man2/mkdir.2.html) documentation for more details.
1491 * @since v0.1.8
1492 */
1493 export function mkdir(
1494 path: PathLike,
1495 options: MakeDirectoryOptions & {
1496 recursive: true;
1497 },
1498 callback: (err: NodeJS.ErrnoException | null, path?: string) => void
1499 ): void;
1500 /**
1501 * Asynchronous mkdir(2) - create a directory.
1502 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1503 * @param options Either the file mode, or an object optionally specifying the file mode and whether parent folders
1504 * should be created. If a string is passed, it is parsed as an octal integer. If not specified, defaults to `0o777`.
1505 */
1506 export function mkdir(
1507 path: PathLike,
1508 options:
1509 | Mode
1510 | (MakeDirectoryOptions & {
1511 recursive?: false | undefined;
1512 })
1513 | null
1514 | undefined,
1515 callback: NoParamCallback
1516 ): void;
1517 /**
1518 * Asynchronous mkdir(2) - create a directory.
1519 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1520 * @param options Either the file mode, or an object optionally specifying the file mode and whether parent folders
1521 * should be created. If a string is passed, it is parsed as an octal integer. If not specified, defaults to `0o777`.
1522 */
1523 export function mkdir(path: PathLike, options: Mode | MakeDirectoryOptions | null | undefined, callback: (err: NodeJS.ErrnoException | null, path?: string) => void): void;
1524 /**
1525 * Asynchronous mkdir(2) - create a directory with a mode of `0o777`.
1526 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1527 */
1528 export function mkdir(path: PathLike, callback: NoParamCallback): void;
1529 export namespace mkdir {
1530 /**
1531 * Asynchronous mkdir(2) - create a directory.
1532 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1533 * @param options Either the file mode, or an object optionally specifying the file mode and whether parent folders
1534 * should be created. If a string is passed, it is parsed as an octal integer. If not specified, defaults to `0o777`.
1535 */
1536 function __promisify__(
1537 path: PathLike,
1538 options: MakeDirectoryOptions & {
1539 recursive: true;
1540 }
1541 ): Promise<string | undefined>;
1542 /**
1543 * Asynchronous mkdir(2) - create a directory.
1544 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1545 * @param options Either the file mode, or an object optionally specifying the file mode and whether parent folders
1546 * should be created. If a string is passed, it is parsed as an octal integer. If not specified, defaults to `0o777`.
1547 */
1548 function __promisify__(
1549 path: PathLike,
1550 options?:
1551 | Mode
1552 | (MakeDirectoryOptions & {
1553 recursive?: false | undefined;
1554 })
1555 | null
1556 ): Promise<void>;
1557 /**
1558 * Asynchronous mkdir(2) - create a directory.
1559 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1560 * @param options Either the file mode, or an object optionally specifying the file mode and whether parent folders
1561 * should be created. If a string is passed, it is parsed as an octal integer. If not specified, defaults to `0o777`.
1562 */
1563 function __promisify__(path: PathLike, options?: Mode | MakeDirectoryOptions | null): Promise<string | undefined>;
1564 }
1565 /**
1566 * Synchronously creates a directory. Returns `undefined`, or if `recursive` is`true`, the first directory path created.
1567 * This is the synchronous version of {@link mkdir}.
1568 *
1569 * See the POSIX [`mkdir(2)`](http://man7.org/linux/man-pages/man2/mkdir.2.html) documentation for more details.
1570 * @since v0.1.21
1571 */
1572 export function mkdirSync(
1573 path: PathLike,
1574 options: MakeDirectoryOptions & {
1575 recursive: true;
1576 }
1577 ): string | undefined;
1578 /**
1579 * Synchronous mkdir(2) - create a directory.
1580 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1581 * @param options Either the file mode, or an object optionally specifying the file mode and whether parent folders
1582 * should be created. If a string is passed, it is parsed as an octal integer. If not specified, defaults to `0o777`.
1583 */
1584 export function mkdirSync(
1585 path: PathLike,
1586 options?:
1587 | Mode
1588 | (MakeDirectoryOptions & {
1589 recursive?: false | undefined;
1590 })
1591 | null
1592 ): void;
1593 /**
1594 * Synchronous mkdir(2) - create a directory.
1595 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1596 * @param options Either the file mode, or an object optionally specifying the file mode and whether parent folders
1597 * should be created. If a string is passed, it is parsed as an octal integer. If not specified, defaults to `0o777`.
1598 */
1599 export function mkdirSync(path: PathLike, options?: Mode | MakeDirectoryOptions | null): string | undefined;
1600 /**
1601 * Creates a unique temporary directory.
1602 *
1603 * Generates six random characters to be appended behind a required`prefix` to create a unique temporary directory. Due to platform
1604 * inconsistencies, avoid trailing `X` characters in `prefix`. Some platforms,
1605 * notably the BSDs, can return more than six random characters, and replace
1606 * trailing `X` characters in `prefix` with random characters.
1607 *
1608 * The created directory path is passed as a string to the callback's second
1609 * parameter.
1610 *
1611 * The optional `options` argument can be a string specifying an encoding, or an
1612 * object with an `encoding` property specifying the character encoding to use.
1613 *
1614 * ```js
1615 * import { mkdtemp } from 'fs';
1616 *
1617 * mkdtemp(path.join(os.tmpdir(), 'foo-'), (err, directory) => {
1618 * if (err) throw err;
1619 * console.log(directory);
1620 * // Prints: /tmp/foo-itXde2 or C:\Users\...\AppData\Local\Temp\foo-itXde2
1621 * });
1622 * ```
1623 *
1624 * The `fs.mkdtemp()` method will append the six randomly selected characters
1625 * directly to the `prefix` string. For instance, given a directory `/tmp`, if the
1626 * intention is to create a temporary directory _within_`/tmp`, the `prefix`must end with a trailing platform-specific path separator
1627 * (`require('path').sep`).
1628 *
1629 * ```js
1630 * import { tmpdir } from 'os';
1631 * import { mkdtemp } from 'fs';
1632 *
1633 * // The parent directory for the new temporary directory
1634 * const tmpDir = tmpdir();
1635 *
1636 * // This method is *INCORRECT*:
1637 * mkdtemp(tmpDir, (err, directory) => {
1638 * if (err) throw err;
1639 * console.log(directory);
1640 * // Will print something similar to `/tmpabc123`.
1641 * // A new temporary directory is created at the file system root
1642 * // rather than *within* the /tmp directory.
1643 * });
1644 *
1645 * // This method is *CORRECT*:
1646 * import { sep } from 'path';
1647 * mkdtemp(`${tmpDir}${sep}`, (err, directory) => {
1648 * if (err) throw err;
1649 * console.log(directory);
1650 * // Will print something similar to `/tmp/abc123`.
1651 * // A new temporary directory is created within
1652 * // the /tmp directory.
1653 * });
1654 * ```
1655 * @since v5.10.0
1656 */
1657 export function mkdtemp(prefix: string, options: EncodingOption, callback: (err: NodeJS.ErrnoException | null, folder: string) => void): void;
1658 /**
1659 * Asynchronously creates a unique temporary directory.
1660 * Generates six random characters to be appended behind a required prefix to create a unique temporary directory.
1661 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
1662 */
1663 export function mkdtemp(
1664 prefix: string,
1665 options:
1666 | 'buffer'
1667 | {
1668 encoding: 'buffer';
1669 },
1670 callback: (err: NodeJS.ErrnoException | null, folder: Buffer) => void
1671 ): void;
1672 /**
1673 * Asynchronously creates a unique temporary directory.
1674 * Generates six random characters to be appended behind a required prefix to create a unique temporary directory.
1675 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
1676 */
1677 export function mkdtemp(prefix: string, options: EncodingOption, callback: (err: NodeJS.ErrnoException | null, folder: string | Buffer) => void): void;
1678 /**
1679 * Asynchronously creates a unique temporary directory.
1680 * Generates six random characters to be appended behind a required prefix to create a unique temporary directory.
1681 */
1682 export function mkdtemp(prefix: string, callback: (err: NodeJS.ErrnoException | null, folder: string) => void): void;
1683 export namespace mkdtemp {
1684 /**
1685 * Asynchronously creates a unique temporary directory.
1686 * Generates six random characters to be appended behind a required prefix to create a unique temporary directory.
1687 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
1688 */
1689 function __promisify__(prefix: string, options?: EncodingOption): Promise<string>;
1690 /**
1691 * Asynchronously creates a unique temporary directory.
1692 * Generates six random characters to be appended behind a required prefix to create a unique temporary directory.
1693 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
1694 */
1695 function __promisify__(prefix: string, options: BufferEncodingOption): Promise<Buffer>;
1696 /**
1697 * Asynchronously creates a unique temporary directory.
1698 * Generates six random characters to be appended behind a required prefix to create a unique temporary directory.
1699 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
1700 */
1701 function __promisify__(prefix: string, options?: EncodingOption): Promise<string | Buffer>;
1702 }
1703 /**
1704 * Returns the created directory path.
1705 *
1706 * For detailed information, see the documentation of the asynchronous version of
1707 * this API: {@link mkdtemp}.
1708 *
1709 * The optional `options` argument can be a string specifying an encoding, or an
1710 * object with an `encoding` property specifying the character encoding to use.
1711 * @since v5.10.0
1712 */
1713 export function mkdtempSync(prefix: string, options?: EncodingOption): string;
1714 /**
1715 * Synchronously creates a unique temporary directory.
1716 * Generates six random characters to be appended behind a required prefix to create a unique temporary directory.
1717 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
1718 */
1719 export function mkdtempSync(prefix: string, options: BufferEncodingOption): Buffer;
1720 /**
1721 * Synchronously creates a unique temporary directory.
1722 * Generates six random characters to be appended behind a required prefix to create a unique temporary directory.
1723 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
1724 */
1725 export function mkdtempSync(prefix: string, options?: EncodingOption): string | Buffer;
1726 /**
1727 * Reads the contents of a directory. The callback gets two arguments `(err, files)`where `files` is an array of the names of the files in the directory excluding`'.'` and `'..'`.
1728 *
1729 * See the POSIX [`readdir(3)`](http://man7.org/linux/man-pages/man3/readdir.3.html) documentation for more details.
1730 *
1731 * The optional `options` argument can be a string specifying an encoding, or an
1732 * object with an `encoding` property specifying the character encoding to use for
1733 * the filenames passed to the callback. If the `encoding` is set to `'buffer'`,
1734 * the filenames returned will be passed as `<Buffer>` objects.
1735 *
1736 * If `options.withFileTypes` is set to `true`, the `files` array will contain `<fs.Dirent>` objects.
1737 * @since v0.1.8
1738 */
1739 export function readdir(
1740 path: PathLike,
1741 options:
1742 | {
1743 encoding: BufferEncoding | null;
1744 withFileTypes?: false | undefined;
1745 }
1746 | BufferEncoding
1747 | undefined
1748 | null,
1749 callback: (err: NodeJS.ErrnoException | null, files: string[]) => void
1750 ): void;
1751 /**
1752 * Asynchronous readdir(3) - read a directory.
1753 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1754 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
1755 */
1756 export function readdir(
1757 path: PathLike,
1758 options:
1759 | {
1760 encoding: 'buffer';
1761 withFileTypes?: false | undefined;
1762 }
1763 | 'buffer',
1764 callback: (err: NodeJS.ErrnoException | null, files: Buffer[]) => void
1765 ): void;
1766 /**
1767 * Asynchronous readdir(3) - read a directory.
1768 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1769 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
1770 */
1771 export function readdir(
1772 path: PathLike,
1773 options:
1774 | (ObjectEncodingOptions & {
1775 withFileTypes?: false | undefined;
1776 })
1777 | BufferEncoding
1778 | undefined
1779 | null,
1780 callback: (err: NodeJS.ErrnoException | null, files: string[] | Buffer[]) => void
1781 ): void;
1782 /**
1783 * Asynchronous readdir(3) - read a directory.
1784 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1785 */
1786 export function readdir(path: PathLike, callback: (err: NodeJS.ErrnoException | null, files: string[]) => void): void;
1787 /**
1788 * Asynchronous readdir(3) - read a directory.
1789 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1790 * @param options If called with `withFileTypes: true` the result data will be an array of Dirent.
1791 */
1792 export function readdir(
1793 path: PathLike,
1794 options: ObjectEncodingOptions & {
1795 withFileTypes: true;
1796 },
1797 callback: (err: NodeJS.ErrnoException | null, files: Dirent[]) => void
1798 ): void;
1799 export namespace readdir {
1800 /**
1801 * Asynchronous readdir(3) - read a directory.
1802 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1803 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
1804 */
1805 function __promisify__(
1806 path: PathLike,
1807 options?:
1808 | {
1809 encoding: BufferEncoding | null;
1810 withFileTypes?: false | undefined;
1811 }
1812 | BufferEncoding
1813 | null
1814 ): Promise<string[]>;
1815 /**
1816 * Asynchronous readdir(3) - read a directory.
1817 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1818 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
1819 */
1820 function __promisify__(
1821 path: PathLike,
1822 options:
1823 | 'buffer'
1824 | {
1825 encoding: 'buffer';
1826 withFileTypes?: false | undefined;
1827 }
1828 ): Promise<Buffer[]>;
1829 /**
1830 * Asynchronous readdir(3) - read a directory.
1831 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1832 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
1833 */
1834 function __promisify__(
1835 path: PathLike,
1836 options?:
1837 | (ObjectEncodingOptions & {
1838 withFileTypes?: false | undefined;
1839 })
1840 | BufferEncoding
1841 | null
1842 ): Promise<string[] | Buffer[]>;
1843 /**
1844 * Asynchronous readdir(3) - read a directory.
1845 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1846 * @param options If called with `withFileTypes: true` the result data will be an array of Dirent
1847 */
1848 function __promisify__(
1849 path: PathLike,
1850 options: ObjectEncodingOptions & {
1851 withFileTypes: true;
1852 }
1853 ): Promise<Dirent[]>;
1854 }
1855 /**
1856 * Reads the contents of the directory.
1857 *
1858 * See the POSIX [`readdir(3)`](http://man7.org/linux/man-pages/man3/readdir.3.html) documentation for more details.
1859 *
1860 * The optional `options` argument can be a string specifying an encoding, or an
1861 * object with an `encoding` property specifying the character encoding to use for
1862 * the filenames returned. If the `encoding` is set to `'buffer'`,
1863 * the filenames returned will be passed as `<Buffer>` objects.
1864 *
1865 * If `options.withFileTypes` is set to `true`, the result will contain `<fs.Dirent>` objects.
1866 * @since v0.1.21
1867 */
1868 export function readdirSync(
1869 path: PathLike,
1870 options?:
1871 | {
1872 encoding: BufferEncoding | null;
1873 withFileTypes?: false | undefined;
1874 }
1875 | BufferEncoding
1876 | null
1877 ): string[];
1878 /**
1879 * Synchronous readdir(3) - read a directory.
1880 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1881 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
1882 */
1883 export function readdirSync(
1884 path: PathLike,
1885 options:
1886 | {
1887 encoding: 'buffer';
1888 withFileTypes?: false | undefined;
1889 }
1890 | 'buffer'
1891 ): Buffer[];
1892 /**
1893 * Synchronous readdir(3) - read a directory.
1894 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1895 * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
1896 */
1897 export function readdirSync(
1898 path: PathLike,
1899 options?:
1900 | (ObjectEncodingOptions & {
1901 withFileTypes?: false | undefined;
1902 })
1903 | BufferEncoding
1904 | null
1905 ): string[] | Buffer[];
1906 /**
1907 * Synchronous readdir(3) - read a directory.
1908 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1909 * @param options If called with `withFileTypes: true` the result data will be an array of Dirent.
1910 */
1911 export function readdirSync(
1912 path: PathLike,
1913 options: ObjectEncodingOptions & {
1914 withFileTypes: true;
1915 }
1916 ): Dirent[];
1917 /**
1918 * Closes the file descriptor. No arguments other than a possible exception are
1919 * given to the completion callback.
1920 *
1921 * Calling `fs.close()` on any file descriptor (`fd`) that is currently in use
1922 * through any other `fs` operation may lead to undefined behavior.
1923 *
1924 * See the POSIX [`close(2)`](http://man7.org/linux/man-pages/man2/close.2.html) documentation for more detail.
1925 * @since v0.0.2
1926 */
1927 export function close(fd: number, callback?: NoParamCallback): void;
1928 export namespace close {
1929 /**
1930 * Asynchronous close(2) - close a file descriptor.
1931 * @param fd A file descriptor.
1932 */
1933 function __promisify__(fd: number): Promise<void>;
1934 }
1935 /**
1936 * Closes the file descriptor. Returns `undefined`.
1937 *
1938 * Calling `fs.closeSync()` on any file descriptor (`fd`) that is currently in use
1939 * through any other `fs` operation may lead to undefined behavior.
1940 *
1941 * See the POSIX [`close(2)`](http://man7.org/linux/man-pages/man2/close.2.html) documentation for more detail.
1942 * @since v0.1.21
1943 */
1944 export function closeSync(fd: number): void;
1945 /**
1946 * Asynchronous file open. See the POSIX [`open(2)`](http://man7.org/linux/man-pages/man2/open.2.html) documentation for more details.
1947 *
1948 * `mode` sets the file mode (permission and sticky bits), but only if the file was
1949 * created. On Windows, only the write permission can be manipulated; see {@link chmod}.
1950 *
1951 * The callback gets two arguments `(err, fd)`.
1952 *
1953 * Some characters (`< > : " / \ | ? *`) are reserved under Windows as documented
1954 * by [Naming Files, Paths, and Namespaces](https://docs.microsoft.com/en-us/windows/desktop/FileIO/naming-a-file). Under NTFS, if the filename contains
1955 * a colon, Node.js will open a file system stream, as described by[this MSDN page](https://docs.microsoft.com/en-us/windows/desktop/FileIO/using-streams).
1956 *
1957 * Functions based on `fs.open()` exhibit this behavior as well:`fs.writeFile()`, `fs.readFile()`, etc.
1958 * @since v0.0.2
1959 * @param [flags='r'] See `support of file system `flags``.
1960 * @param [mode=0o666]
1961 */
1962 export function open(path: PathLike, flags: OpenMode, mode: Mode | undefined | null, callback: (err: NodeJS.ErrnoException | null, fd: number) => void): void;
1963 /**
1964 * Asynchronous open(2) - open and possibly create a file. If the file is created, its mode will be `0o666`.
1965 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1966 */
1967 export function open(path: PathLike, flags: OpenMode, callback: (err: NodeJS.ErrnoException | null, fd: number) => void): void;
1968 export namespace open {
1969 /**
1970 * Asynchronous open(2) - open and possibly create a file.
1971 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1972 * @param mode A file mode. If a string is passed, it is parsed as an octal integer. If not supplied, defaults to `0o666`.
1973 */
1974 function __promisify__(path: PathLike, flags: OpenMode, mode?: Mode | null): Promise<number>;
1975 }
1976 /**
1977 * Returns an integer representing the file descriptor.
1978 *
1979 * For detailed information, see the documentation of the asynchronous version of
1980 * this API: {@link open}.
1981 * @since v0.1.21
1982 * @param [flags='r']
1983 * @param [mode=0o666]
1984 */
1985 export function openSync(path: PathLike, flags: OpenMode, mode?: Mode | null): number;
1986 /**
1987 * Change the file system timestamps of the object referenced by `path`.
1988 *
1989 * The `atime` and `mtime` arguments follow these rules:
1990 *
1991 * * Values can be either numbers representing Unix epoch time in seconds,`Date`s, or a numeric string like `'123456789.0'`.
1992 * * If the value can not be converted to a number, or is `NaN`, `Infinity` or`-Infinity`, an `Error` will be thrown.
1993 * @since v0.4.2
1994 */
1995 export function utimes(path: PathLike, atime: TimeLike, mtime: TimeLike, callback: NoParamCallback): void;
1996 export namespace utimes {
1997 /**
1998 * Asynchronously change file timestamps of the file referenced by the supplied path.
1999 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
2000 * @param atime The last access time. If a string is provided, it will be coerced to number.
2001 * @param mtime The last modified time. If a string is provided, it will be coerced to number.
2002 */
2003 function __promisify__(path: PathLike, atime: TimeLike, mtime: TimeLike): Promise<void>;
2004 }
2005 /**
2006 * Returns `undefined`.
2007 *
2008 * For detailed information, see the documentation of the asynchronous version of
2009 * this API: {@link utimes}.
2010 * @since v0.4.2
2011 */
2012 export function utimesSync(path: PathLike, atime: TimeLike, mtime: TimeLike): void;
2013 /**
2014 * Change the file system timestamps of the object referenced by the supplied file
2015 * descriptor. See {@link utimes}.
2016 * @since v0.4.2
2017 */
2018 export function futimes(fd: number, atime: TimeLike, mtime: TimeLike, callback: NoParamCallback): void;
2019 export namespace futimes {
2020 /**
2021 * Asynchronously change file timestamps of the file referenced by the supplied file descriptor.
2022 * @param fd A file descriptor.
2023 * @param atime The last access time. If a string is provided, it will be coerced to number.
2024 * @param mtime The last modified time. If a string is provided, it will be coerced to number.
2025 */
2026 function __promisify__(fd: number, atime: TimeLike, mtime: TimeLike): Promise<void>;
2027 }
2028 /**
2029 * Synchronous version of {@link futimes}. Returns `undefined`.
2030 * @since v0.4.2
2031 */
2032 export function futimesSync(fd: number, atime: TimeLike, mtime: TimeLike): void;
2033 /**
2034 * Request that all data for the open file descriptor is flushed to the storage
2035 * device. The specific implementation is operating system and device specific.
2036 * Refer to the POSIX [`fsync(2)`](http://man7.org/linux/man-pages/man2/fsync.2.html) documentation for more detail. No arguments other
2037 * than a possible exception are given to the completion callback.
2038 * @since v0.1.96
2039 */
2040 export function fsync(fd: number, callback: NoParamCallback): void;
2041 export namespace fsync {
2042 /**
2043 * Asynchronous fsync(2) - synchronize a file's in-core state with the underlying storage device.
2044 * @param fd A file descriptor.
2045 */
2046 function __promisify__(fd: number): Promise<void>;
2047 }
2048 /**
2049 * Request that all data for the open file descriptor is flushed to the storage
2050 * device. The specific implementation is operating system and device specific.
2051 * Refer to the POSIX [`fsync(2)`](http://man7.org/linux/man-pages/man2/fsync.2.html) documentation for more detail. Returns `undefined`.
2052 * @since v0.1.96
2053 */
2054 export function fsyncSync(fd: number): void;
2055 /**
2056 * Write `buffer` to the file specified by `fd`. If `buffer` is a normal object, it
2057 * must have an own `toString` function property.
2058 *
2059 * `offset` determines the part of the buffer to be written, and `length` is
2060 * an integer specifying the number of bytes to write.
2061 *
2062 * `position` refers to the offset from the beginning of the file where this data
2063 * should be written. If `typeof position !== 'number'`, the data will be written
2064 * at the current position. See [`pwrite(2)`](http://man7.org/linux/man-pages/man2/pwrite.2.html).
2065 *
2066 * The callback will be given three arguments `(err, bytesWritten, buffer)` where`bytesWritten` specifies how many _bytes_ were written from `buffer`.
2067 *
2068 * If this method is invoked as its `util.promisify()` ed version, it returns
2069 * a promise for an `Object` with `bytesWritten` and `buffer` properties.
2070 *
2071 * It is unsafe to use `fs.write()` multiple times on the same file without waiting
2072 * for the callback. For this scenario, {@link createWriteStream} is
2073 * recommended.
2074 *
2075 * On Linux, positional writes don't work when the file is opened in append mode.
2076 * The kernel ignores the position argument and always appends the data to
2077 * the end of the file.
2078 * @since v0.0.2
2079 */
2080 export function write<TBuffer extends NodeJS.ArrayBufferView>(
2081 fd: number,
2082 buffer: TBuffer,
2083 offset: number | undefined | null,
2084 length: number | undefined | null,
2085 position: number | undefined | null,
2086 callback: (err: NodeJS.ErrnoException | null, written: number, buffer: TBuffer) => void
2087 ): void;
2088 /**
2089 * Asynchronously writes `buffer` to the file referenced by the supplied file descriptor.
2090 * @param fd A file descriptor.
2091 * @param offset The part of the buffer to be written. If not supplied, defaults to `0`.
2092 * @param length The number of bytes to write. If not supplied, defaults to `buffer.length - offset`.
2093 */
2094 export function write<TBuffer extends NodeJS.ArrayBufferView>(
2095 fd: number,
2096 buffer: TBuffer,
2097 offset: number | undefined | null,
2098 length: number | undefined | null,
2099 callback: (err: NodeJS.ErrnoException | null, written: number, buffer: TBuffer) => void
2100 ): void;
2101 /**
2102 * Asynchronously writes `buffer` to the file referenced by the supplied file descriptor.
2103 * @param fd A file descriptor.
2104 * @param offset The part of the buffer to be written. If not supplied, defaults to `0`.
2105 */
2106 export function write<TBuffer extends NodeJS.ArrayBufferView>(
2107 fd: number,
2108 buffer: TBuffer,
2109 offset: number | undefined | null,
2110 callback: (err: NodeJS.ErrnoException | null, written: number, buffer: TBuffer) => void
2111 ): void;
2112 /**
2113 * Asynchronously writes `buffer` to the file referenced by the supplied file descriptor.
2114 * @param fd A file descriptor.
2115 */
2116 export function write<TBuffer extends NodeJS.ArrayBufferView>(fd: number, buffer: TBuffer, callback: (err: NodeJS.ErrnoException | null, written: number, buffer: TBuffer) => void): void;
2117 /**
2118 * Asynchronously writes `string` to the file referenced by the supplied file descriptor.
2119 * @param fd A file descriptor.
2120 * @param string A string to write.
2121 * @param position The offset from the beginning of the file where this data should be written. If not supplied, defaults to the current position.
2122 * @param encoding The expected string encoding.
2123 */
2124 export function write(
2125 fd: number,
2126 string: string,
2127 position: number | undefined | null,
2128 encoding: BufferEncoding | undefined | null,
2129 callback: (err: NodeJS.ErrnoException | null, written: number, str: string) => void
2130 ): void;
2131 /**
2132 * Asynchronously writes `string` to the file referenced by the supplied file descriptor.
2133 * @param fd A file descriptor.
2134 * @param string A string to write.
2135 * @param position The offset from the beginning of the file where this data should be written. If not supplied, defaults to the current position.
2136 */
2137 export function write(fd: number, string: string, position: number | undefined | null, callback: (err: NodeJS.ErrnoException | null, written: number, str: string) => void): void;
2138 /**
2139 * Asynchronously writes `string` to the file referenced by the supplied file descriptor.
2140 * @param fd A file descriptor.
2141 * @param string A string to write.
2142 */
2143 export function write(fd: number, string: string, callback: (err: NodeJS.ErrnoException | null, written: number, str: string) => void): void;
2144 export namespace write {
2145 /**
2146 * Asynchronously writes `buffer` to the file referenced by the supplied file descriptor.
2147 * @param fd A file descriptor.
2148 * @param offset The part of the buffer to be written. If not supplied, defaults to `0`.
2149 * @param length The number of bytes to write. If not supplied, defaults to `buffer.length - offset`.
2150 * @param position The offset from the beginning of the file where this data should be written. If not supplied, defaults to the current position.
2151 */
2152 function __promisify__<TBuffer extends NodeJS.ArrayBufferView>(
2153 fd: number,
2154 buffer?: TBuffer,
2155 offset?: number,
2156 length?: number,
2157 position?: number | null
2158 ): Promise<{
2159 bytesWritten: number;
2160 buffer: TBuffer;
2161 }>;
2162 /**
2163 * Asynchronously writes `string` to the file referenced by the supplied file descriptor.
2164 * @param fd A file descriptor.
2165 * @param string A string to write.
2166 * @param position The offset from the beginning of the file where this data should be written. If not supplied, defaults to the current position.
2167 * @param encoding The expected string encoding.
2168 */
2169 function __promisify__(
2170 fd: number,
2171 string: string,
2172 position?: number | null,
2173 encoding?: BufferEncoding | null
2174 ): Promise<{
2175 bytesWritten: number;
2176 buffer: string;
2177 }>;
2178 }
2179 /**
2180 * For detailed information, see the documentation of the asynchronous version of
2181 * this API: {@link write}.
2182 * @since v0.1.21
2183 * @return The number of bytes written.
2184 */
2185 export function writeSync(fd: number, buffer: NodeJS.ArrayBufferView, offset?: number | null, length?: number | null, position?: number | null): number;
2186 /**
2187 * Synchronously writes `string` to the file referenced by the supplied file descriptor, returning the number of bytes written.
2188 * @param fd A file descriptor.
2189 * @param string A string to write.
2190 * @param position The offset from the beginning of the file where this data should be written. If not supplied, defaults to the current position.
2191 * @param encoding The expected string encoding.
2192 */
2193 export function writeSync(fd: number, string: string, position?: number | null, encoding?: BufferEncoding | null): number;
2194 export type ReadPosition = number | bigint;
2195 /**
2196 * Read data from the file specified by `fd`.
2197 *
2198 * The callback is given the three arguments, `(err, bytesRead, buffer)`.
2199 *
2200 * If the file is not modified concurrently, the end-of-file is reached when the
2201 * number of bytes read is zero.
2202 *
2203 * If this method is invoked as its `util.promisify()` ed version, it returns
2204 * a promise for an `Object` with `bytesRead` and `buffer` properties.
2205 * @since v0.0.2
2206 * @param [buffer=Buffer.alloc(16384)] The buffer that the data will be written to.
2207 * @param [offset=0] The position in `buffer` to write the data to.
2208 * @param [length=buffer.byteLength] The number of bytes to read.
2209 * @param position Specifies where to begin reading from in the file. If `position` is `null` or `-1 `, data will be read from the current file position, and the file position will be updated. If
2210 * `position` is an integer, the file position will be unchanged.
2211 */
2212 export function read<TBuffer extends NodeJS.ArrayBufferView>(
2213 fd: number,
2214 buffer: TBuffer,
2215 offset: number,
2216 length: number,
2217 position: ReadPosition | null,
2218 callback: (err: NodeJS.ErrnoException | null, bytesRead: number, buffer: TBuffer) => void
2219 ): void;
2220 export namespace read {
2221 /**
2222 * @param fd A file descriptor.
2223 * @param buffer The buffer that the data will be written to.
2224 * @param offset The offset in the buffer at which to start writing.
2225 * @param length The number of bytes to read.
2226 * @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.
2227 */
2228 function __promisify__<TBuffer extends NodeJS.ArrayBufferView>(
2229 fd: number,
2230 buffer: TBuffer,
2231 offset: number,
2232 length: number,
2233 position: number | null
2234 ): Promise<{
2235 bytesRead: number;
2236 buffer: TBuffer;
2237 }>;
2238 }
2239 export interface ReadSyncOptions {
2240 /**
2241 * @default 0
2242 */
2243 offset?: number | undefined;
2244 /**
2245 * @default `length of buffer`
2246 */
2247 length?: number | undefined;
2248 /**
2249 * @default null
2250 */
2251 position?: ReadPosition | null | undefined;
2252 }
2253 /**
2254 * Returns the number of `bytesRead`.
2255 *
2256 * For detailed information, see the documentation of the asynchronous version of
2257 * this API: {@link read}.
2258 * @since v0.1.21
2259 */
2260 export function readSync(fd: number, buffer: NodeJS.ArrayBufferView, offset: number, length: number, position: ReadPosition | null): number;
2261 /**
2262 * Similar to the above `fs.readSync` function, this version takes an optional `options` object.
2263 * If no `options` object is specified, it will default with the above values.
2264 */
2265 export function readSync(fd: number, buffer: NodeJS.ArrayBufferView, opts?: ReadSyncOptions): number;
2266 /**
2267 * Asynchronously reads the entire contents of a file.
2268 *
2269 * ```js
2270 * import { readFile } from 'fs';
2271 *
2272 * readFile('/etc/passwd', (err, data) => {
2273 * if (err) throw err;
2274 * console.log(data);
2275 * });
2276 * ```
2277 *
2278 * The callback is passed two arguments `(err, data)`, where `data` is the
2279 * contents of the file.
2280 *
2281 * If no encoding is specified, then the raw buffer is returned.
2282 *
2283 * If `options` is a string, then it specifies the encoding:
2284 *
2285 * ```js
2286 * import { readFile } from 'fs';
2287 *
2288 * readFile('/etc/passwd', 'utf8', callback);
2289 * ```
2290 *
2291 * When the path is a directory, the behavior of `fs.readFile()` and {@link readFileSync} is platform-specific. On macOS, Linux, and Windows, an
2292 * error will be returned. On FreeBSD, a representation of the directory's contents
2293 * will be returned.
2294 *
2295 * ```js
2296 * import { readFile } from 'fs';
2297 *
2298 * // macOS, Linux, and Windows
2299 * readFile('<directory>', (err, data) => {
2300 * // => [Error: EISDIR: illegal operation on a directory, read <directory>]
2301 * });
2302 *
2303 * // FreeBSD
2304 * readFile('<directory>', (err, data) => {
2305 * // => null, <data>
2306 * });
2307 * ```
2308 *
2309 * It is possible to abort an ongoing request using an `AbortSignal`. If a
2310 * request is aborted the callback is called with an `AbortError`:
2311 *
2312 * ```js
2313 * import { readFile } from 'fs';
2314 *
2315 * const controller = new AbortController();
2316 * const signal = controller.signal;
2317 * readFile(fileInfo[0].name, { signal }, (err, buf) => {
2318 * // ...
2319 * });
2320 * // When you want to abort the request
2321 * controller.abort();
2322 * ```
2323 *
2324 * The `fs.readFile()` function buffers the entire file. To minimize memory costs,
2325 * when possible prefer streaming via `fs.createReadStream()`.
2326 *
2327 * Aborting an ongoing request does not abort individual operating
2328 * system requests but rather the internal buffering `fs.readFile` performs.
2329 * @since v0.1.29
2330 * @param path filename or file descriptor
2331 */
2332 export function readFile(
2333 path: PathOrFileDescriptor,
2334 options:
2335 | ({
2336 encoding?: null | undefined;
2337 flag?: string | undefined;
2338 } & Abortable)
2339 | undefined
2340 | null,
2341 callback: (err: NodeJS.ErrnoException | null, data: Buffer) => void
2342 ): void;
2343 /**
2344 * Asynchronously reads the entire contents of a file.
2345 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
2346 * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
2347 * @param options Either the encoding for the result, or an object that contains the encoding and an optional flag.
2348 * If a flag is not provided, it defaults to `'r'`.
2349 */
2350 export function readFile(
2351 path: PathOrFileDescriptor,
2352 options:
2353 | ({
2354 encoding: BufferEncoding;
2355 flag?: string | undefined;
2356 } & Abortable)
2357 | string,
2358 callback: (err: NodeJS.ErrnoException | null, data: string) => void
2359 ): void;
2360 /**
2361 * Asynchronously reads the entire contents of a file.
2362 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
2363 * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
2364 * @param options Either the encoding for the result, or an object that contains the encoding and an optional flag.
2365 * If a flag is not provided, it defaults to `'r'`.
2366 */
2367 export function readFile(
2368 path: PathOrFileDescriptor,
2369 options:
2370 | (ObjectEncodingOptions & {
2371 flag?: string | undefined;
2372 } & Abortable)
2373 | string
2374 | undefined
2375 | null,
2376 callback: (err: NodeJS.ErrnoException | null, data: string | Buffer) => void
2377 ): void;
2378 /**
2379 * Asynchronously reads the entire contents of a file.
2380 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
2381 * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
2382 */
2383 export function readFile(path: PathOrFileDescriptor, callback: (err: NodeJS.ErrnoException | null, data: Buffer) => void): void;
2384 export namespace readFile {
2385 /**
2386 * Asynchronously reads the entire contents of a file.
2387 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
2388 * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
2389 * @param options An object that may contain an optional flag.
2390 * If a flag is not provided, it defaults to `'r'`.
2391 */
2392 function __promisify__(
2393 path: PathOrFileDescriptor,
2394 options?: {
2395 encoding?: null | undefined;
2396 flag?: string | undefined;
2397 } | null
2398 ): Promise<Buffer>;
2399 /**
2400 * Asynchronously reads the entire contents of a file.
2401 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
2402 * URL support is _experimental_.
2403 * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
2404 * @param options Either the encoding for the result, or an object that contains the encoding and an optional flag.
2405 * If a flag is not provided, it defaults to `'r'`.
2406 */
2407 function __promisify__(
2408 path: PathOrFileDescriptor,
2409 options:
2410 | {
2411 encoding: BufferEncoding;
2412 flag?: string | undefined;
2413 }
2414 | string
2415 ): Promise<string>;
2416 /**
2417 * Asynchronously reads the entire contents of a file.
2418 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
2419 * URL support is _experimental_.
2420 * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
2421 * @param options Either the encoding for the result, or an object that contains the encoding and an optional flag.
2422 * If a flag is not provided, it defaults to `'r'`.
2423 */
2424 function __promisify__(
2425 path: PathOrFileDescriptor,
2426 options?:
2427 | (ObjectEncodingOptions & {
2428 flag?: string | undefined;
2429 })
2430 | string
2431 | null
2432 ): Promise<string | Buffer>;
2433 }
2434 /**
2435 * Returns the contents of the `path`.
2436 *
2437 * For detailed information, see the documentation of the asynchronous version of
2438 * this API: {@link readFile}.
2439 *
2440 * If the `encoding` option is specified then this function returns a
2441 * string. Otherwise it returns a buffer.
2442 *
2443 * Similar to {@link readFile}, when the path is a directory, the behavior of`fs.readFileSync()` is platform-specific.
2444 *
2445 * ```js
2446 * import { readFileSync } from 'fs';
2447 *
2448 * // macOS, Linux, and Windows
2449 * readFileSync('<directory>');
2450 * // => [Error: EISDIR: illegal operation on a directory, read <directory>]
2451 *
2452 * // FreeBSD
2453 * readFileSync('<directory>'); // => <data>
2454 * ```
2455 * @since v0.1.8
2456 * @param path filename or file descriptor
2457 */
2458 export function readFileSync(
2459 path: PathOrFileDescriptor,
2460 options?: {
2461 encoding?: null | undefined;
2462 flag?: string | undefined;
2463 } | null
2464 ): Buffer;
2465 /**
2466 * Synchronously reads the entire contents of a file.
2467 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
2468 * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
2469 * @param options Either the encoding for the result, or an object that contains the encoding and an optional flag.
2470 * If a flag is not provided, it defaults to `'r'`.
2471 */
2472 export function readFileSync(
2473 path: PathOrFileDescriptor,
2474 options:
2475 | {
2476 encoding: BufferEncoding;
2477 flag?: string | undefined;
2478 }
2479 | BufferEncoding
2480 ): string;
2481 /**
2482 * Synchronously reads the entire contents of a file.
2483 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
2484 * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
2485 * @param options Either the encoding for the result, or an object that contains the encoding and an optional flag.
2486 * If a flag is not provided, it defaults to `'r'`.
2487 */
2488 export function readFileSync(
2489 path: PathOrFileDescriptor,
2490 options?:
2491 | (ObjectEncodingOptions & {
2492 flag?: string | undefined;
2493 })
2494 | BufferEncoding
2495 | null
2496 ): string | Buffer;
2497 export type WriteFileOptions =
2498 | (ObjectEncodingOptions &
2499 Abortable & {
2500 mode?: Mode | undefined;
2501 flag?: string | undefined;
2502 })
2503 | string
2504 | null;
2505 /**
2506 * When `file` is a filename, asynchronously writes data to the file, replacing the
2507 * file if it already exists. `data` can be a string or a buffer.
2508 *
2509 * When `file` is a file descriptor, the behavior is similar to calling`fs.write()` directly (which is recommended). See the notes below on using
2510 * a file descriptor.
2511 *
2512 * The `encoding` option is ignored if `data` is a buffer.
2513 * If `data` is a normal object, it must have an own `toString` function property.
2514 *
2515 * ```js
2516 * import { writeFile } from 'fs';
2517 *
2518 * const data = new Uint8Array(Buffer.from('Hello Node.js'));
2519 * writeFile('message.txt', data, (err) => {
2520 * if (err) throw err;
2521 * console.log('The file has been saved!');
2522 * });
2523 * ```
2524 *
2525 * If `options` is a string, then it specifies the encoding:
2526 *
2527 * ```js
2528 * import { writeFile } from 'fs';
2529 *
2530 * writeFile('message.txt', 'Hello Node.js', 'utf8', callback);
2531 * ```
2532 *
2533 * It is unsafe to use `fs.writeFile()` multiple times on the same file without
2534 * waiting for the callback. For this scenario, {@link createWriteStream} is
2535 * recommended.
2536 *
2537 * Similarly to `fs.readFile` \- `fs.writeFile` is a convenience method that
2538 * performs multiple `write` calls internally to write the buffer passed to it.
2539 * For performance sensitive code consider using {@link createWriteStream}.
2540 *
2541 * It is possible to use an `<AbortSignal>` to cancel an `fs.writeFile()`.
2542 * Cancelation is "best effort", and some amount of data is likely still
2543 * to be written.
2544 *
2545 * ```js
2546 * import { writeFile } from 'fs';
2547 *
2548 * const controller = new AbortController();
2549 * const { signal } = controller;
2550 * const data = new Uint8Array(Buffer.from('Hello Node.js'));
2551 * writeFile('message.txt', data, { signal }, (err) => {
2552 * // When a request is aborted - the callback is called with an AbortError
2553 * });
2554 * // When the request should be aborted
2555 * controller.abort();
2556 * ```
2557 *
2558 * Aborting an ongoing request does not abort individual operating
2559 * system requests but rather the internal buffering `fs.writeFile` performs.
2560 * @since v0.1.29
2561 * @param file filename or file descriptor
2562 */
2563 export function writeFile(file: PathOrFileDescriptor, data: string | NodeJS.ArrayBufferView, options: WriteFileOptions, callback: NoParamCallback): void;
2564 /**
2565 * Asynchronously writes data to a file, replacing the file if it already exists.
2566 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
2567 * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
2568 * @param data The data to write. If something other than a Buffer or Uint8Array is provided, the value is coerced to a string.
2569 */
2570 export function writeFile(path: PathOrFileDescriptor, data: string | NodeJS.ArrayBufferView, callback: NoParamCallback): void;
2571 export namespace writeFile {
2572 /**
2573 * Asynchronously writes data to a file, replacing the file if it already exists.
2574 * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
2575 * URL support is _experimental_.
2576 * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
2577 * @param data The data to write. If something other than a Buffer or Uint8Array is provided, the value is coerced to a string.
2578 * @param options Either the encoding for the file, or an object optionally specifying the encoding, file mode, and flag.
2579 * If `encoding` is not supplied, the default of `'utf8'` is used.
2580 * If `mode` is not supplied, the default of `0o666` is used.
2581 * If `mode` is a string, it is parsed as an octal integer.
2582 * If `flag` is not supplied, the default of `'w'` is used.
2583 */
2584 function __promisify__(path: PathOrFileDescriptor, data: string | NodeJS.ArrayBufferView, options?: WriteFileOptions): Promise<void>;
2585 }
2586 /**
2587 * Returns `undefined`.
2588 *
2589 * For detailed information, see the documentation of the asynchronous version of
2590 * this API: {@link writeFile}.
2591 * @since v0.1.29
2592 * @param file filename or file descriptor
2593 */
2594 export function writeFileSync(file: PathOrFileDescriptor, data: string | NodeJS.ArrayBufferView, options?: WriteFileOptions): void;
2595 /**
2596 * Asynchronously append data to a file, creating the file if it does not yet
2597 * exist. `data` can be a string or a `<Buffer>`.
2598 *
2599 * ```js
2600 * import { appendFile } from 'fs';
2601 *
2602 * appendFile('message.txt', 'data to append', (err) => {
2603 * if (err) throw err;
2604 * console.log('The "data to append" was appended to file!');
2605 * });
2606 * ```
2607 *
2608 * If `options` is a string, then it specifies the encoding:
2609 *
2610 * ```js
2611 * import { appendFile } from 'fs';
2612 *
2613 * appendFile('message.txt', 'data to append', 'utf8', callback);
2614 * ```
2615 *
2616 * The `path` may be specified as a numeric file descriptor that has been opened
2617 * for appending (using `fs.open()` or `fs.openSync()`). The file descriptor will
2618 * not be closed automatically.
2619 *
2620 * ```js
2621 * import { open, close, appendFile } from 'fs';
2622 *
2623 * function closeFd(fd) {
2624 * close(fd, (err) => {
2625 * if (err) throw err;
2626 * });
2627 * }
2628 *
2629 * open('message.txt', 'a', (err, fd) => {
2630 * if (err) throw err;
2631 *
2632 * try {
2633 * appendFile(fd, 'data to append', 'utf8', (err) => {
2634 * closeFd(fd);
2635 * if (err) throw err;
2636 * });
2637 * } catch (err) {
2638 * closeFd(fd);
2639 * throw err;
2640 * }
2641 * });
2642 * ```
2643 * @since v0.6.7
2644 * @param path filename or file descriptor
2645 */
2646 export function appendFile(path: PathOrFileDescriptor, data: string | Uint8Array, options: WriteFileOptions, callback: NoParamCallback): void;
2647 /**
2648 * Asynchronously append data to a file, creating the file if it does not exist.
2649 * @param file A path to a file. If a URL is provided, it must use the `file:` protocol.
2650 * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
2651 * @param data The data to write. If something other than a Buffer or Uint8Array is provided, the value is coerced to a string.
2652 */
2653 export function appendFile(file: PathOrFileDescriptor, data: string | Uint8Array, callback: NoParamCallback): void;
2654 export namespace appendFile {
2655 /**
2656 * Asynchronously append data to a file, creating the file if it does not exist.
2657 * @param file A path to a file. If a URL is provided, it must use the `file:` protocol.
2658 * URL support is _experimental_.
2659 * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
2660 * @param data The data to write. If something other than a Buffer or Uint8Array is provided, the value is coerced to a string.
2661 * @param options Either the encoding for the file, or an object optionally specifying the encoding, file mode, and flag.
2662 * If `encoding` is not supplied, the default of `'utf8'` is used.
2663 * If `mode` is not supplied, the default of `0o666` is used.
2664 * If `mode` is a string, it is parsed as an octal integer.
2665 * If `flag` is not supplied, the default of `'a'` is used.
2666 */
2667 function __promisify__(file: PathOrFileDescriptor, data: string | Uint8Array, options?: WriteFileOptions): Promise<void>;
2668 }
2669 /**
2670 * Synchronously append data to a file, creating the file if it does not yet
2671 * exist. `data` can be a string or a `<Buffer>`.
2672 *
2673 * ```js
2674 * import { appendFileSync } from 'fs';
2675 *
2676 * try {
2677 * appendFileSync('message.txt', 'data to append');
2678 * console.log('The "data to append" was appended to file!');
2679 * } catch (err) {
2680 * // Handle the error
2681 * }
2682 * ```
2683 *
2684 * If `options` is a string, then it specifies the encoding:
2685 *
2686 * ```js
2687 * import { appendFileSync } from 'fs';
2688 *
2689 * appendFileSync('message.txt', 'data to append', 'utf8');
2690 * ```
2691 *
2692 * The `path` may be specified as a numeric file descriptor that has been opened
2693 * for appending (using `fs.open()` or `fs.openSync()`). The file descriptor will
2694 * not be closed automatically.
2695 *
2696 * ```js
2697 * import { openSync, closeSync, appendFileSync } from 'fs';
2698 *
2699 * let fd;
2700 *
2701 * try {
2702 * fd = openSync('message.txt', 'a');
2703 * appendFileSync(fd, 'data to append', 'utf8');
2704 * } catch (err) {
2705 * // Handle the error
2706 * } finally {
2707 * if (fd !== undefined)
2708 * closeSync(fd);
2709 * }
2710 * ```
2711 * @since v0.6.7
2712 * @param path filename or file descriptor
2713 */
2714 export function appendFileSync(path: PathOrFileDescriptor, data: string | Uint8Array, options?: WriteFileOptions): void;
2715 /**
2716 * Watch for changes on `filename`. The callback `listener` will be called each
2717 * time the file is accessed.
2718 *
2719 * The `options` argument may be omitted. If provided, it should be an object. The`options` object may contain a boolean named `persistent` that indicates
2720 * whether the process should continue to run as long as files are being watched.
2721 * The `options` object may specify an `interval` property indicating how often the
2722 * target should be polled in milliseconds.
2723 *
2724 * The `listener` gets two arguments the current stat object and the previous
2725 * stat object:
2726 *
2727 * ```js
2728 * import { watchFile } from 'fs';
2729 *
2730 * watchFile('message.text', (curr, prev) => {
2731 * console.log(`the current mtime is: ${curr.mtime}`);
2732 * console.log(`the previous mtime was: ${prev.mtime}`);
2733 * });
2734 * ```
2735 *
2736 * These stat objects are instances of `fs.Stat`. If the `bigint` option is `true`,
2737 * the numeric values in these objects are specified as `BigInt`s.
2738 *
2739 * To be notified when the file was modified, not just accessed, it is necessary
2740 * to compare `curr.mtime` and `prev.mtime`.
2741 *
2742 * When an `fs.watchFile` operation results in an `ENOENT` error, it
2743 * will invoke the listener once, with all the fields zeroed (or, for dates, the
2744 * Unix Epoch). If the file is created later on, the listener will be called
2745 * again, with the latest stat objects. This is a change in functionality since
2746 * v0.10.
2747 *
2748 * Using {@link watch} is more efficient than `fs.watchFile` and`fs.unwatchFile`. `fs.watch` should be used instead of `fs.watchFile` and`fs.unwatchFile` when possible.
2749 *
2750 * When a file being watched by `fs.watchFile()` disappears and reappears,
2751 * then the contents of `previous` in the second callback event (the file's
2752 * reappearance) will be the same as the contents of `previous` in the first
2753 * callback event (its disappearance).
2754 *
2755 * This happens when:
2756 *
2757 * * the file is deleted, followed by a restore
2758 * * the file is renamed and then renamed a second time back to its original name
2759 * @since v0.1.31
2760 */
2761 export function watchFile(
2762 filename: PathLike,
2763 options:
2764 | {
2765 persistent?: boolean | undefined;
2766 interval?: number | undefined;
2767 }
2768 | undefined,
2769 listener: (curr: Stats, prev: Stats) => void
2770 ): void;
2771 /**
2772 * Watch for changes on `filename`. The callback `listener` will be called each time the file is accessed.
2773 * @param filename A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
2774 */
2775 export function watchFile(filename: PathLike, listener: (curr: Stats, prev: Stats) => void): void;
2776 /**
2777 * Stop watching for changes on `filename`. If `listener` is specified, only that
2778 * particular listener is removed. Otherwise, _all_ listeners are removed,
2779 * effectively stopping watching of `filename`.
2780 *
2781 * Calling `fs.unwatchFile()` with a filename that is not being watched is a
2782 * no-op, not an error.
2783 *
2784 * Using {@link watch} is more efficient than `fs.watchFile()` and`fs.unwatchFile()`. `fs.watch()` should be used instead of `fs.watchFile()`and `fs.unwatchFile()` when possible.
2785 * @since v0.1.31
2786 * @param listener Optional, a listener previously attached using `fs.watchFile()`
2787 */
2788 export function unwatchFile(filename: PathLike, listener?: (curr: Stats, prev: Stats) => void): void;
2789 export interface WatchOptions extends Abortable {
2790 encoding?: BufferEncoding | 'buffer' | undefined;
2791 persistent?: boolean | undefined;
2792 recursive?: boolean | undefined;
2793 }
2794 export type WatchListener<T> = (event: 'rename' | 'change', filename: T) => void;
2795 /**
2796 * Watch for changes on `filename`, where `filename` is either a file or a
2797 * directory.
2798 *
2799 * The second argument is optional. If `options` is provided as a string, it
2800 * specifies the `encoding`. Otherwise `options` should be passed as an object.
2801 *
2802 * The listener callback gets two arguments `(eventType, filename)`. `eventType`is either `'rename'` or `'change'`, and `filename` is the name of the file
2803 * which triggered the event.
2804 *
2805 * On most platforms, `'rename'` is emitted whenever a filename appears or
2806 * disappears in the directory.
2807 *
2808 * The listener callback is attached to the `'change'` event fired by `<fs.FSWatcher>`, but it is not the same thing as the `'change'` value of`eventType`.
2809 *
2810 * If a `signal` is passed, aborting the corresponding AbortController will close
2811 * the returned `<fs.FSWatcher>`.
2812 * @since v0.5.10
2813 * @param listener
2814 */
2815 export function watch(
2816 filename: PathLike,
2817 options:
2818 | (WatchOptions & {
2819 encoding: 'buffer';
2820 })
2821 | 'buffer',
2822 listener?: WatchListener<Buffer>
2823 ): FSWatcher;
2824 /**
2825 * Watch for changes on `filename`, where `filename` is either a file or a directory, returning an `FSWatcher`.
2826 * @param filename A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
2827 * @param options Either the encoding for the filename provided to the listener, or an object optionally specifying encoding, persistent, and recursive options.
2828 * If `encoding` is not supplied, the default of `'utf8'` is used.
2829 * If `persistent` is not supplied, the default of `true` is used.
2830 * If `recursive` is not supplied, the default of `false` is used.
2831 */
2832 export function watch(filename: PathLike, options?: WatchOptions | BufferEncoding | null, listener?: WatchListener<string>): FSWatcher;
2833 /**
2834 * Watch for changes on `filename`, where `filename` is either a file or a directory, returning an `FSWatcher`.
2835 * @param filename A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
2836 * @param options Either the encoding for the filename provided to the listener, or an object optionally specifying encoding, persistent, and recursive options.
2837 * If `encoding` is not supplied, the default of `'utf8'` is used.
2838 * If `persistent` is not supplied, the default of `true` is used.
2839 * If `recursive` is not supplied, the default of `false` is used.
2840 */
2841 export function watch(filename: PathLike, options: WatchOptions | string, listener?: WatchListener<string | Buffer>): FSWatcher;
2842 /**
2843 * Watch for changes on `filename`, where `filename` is either a file or a directory, returning an `FSWatcher`.
2844 * @param filename A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
2845 */
2846 export function watch(filename: PathLike, listener?: WatchListener<string>): FSWatcher;
2847 /**
2848 * Test whether or not the given path exists by checking with the file system.
2849 * Then call the `callback` argument with either true or false:
2850 *
2851 * ```js
2852 * import { exists } from 'fs';
2853 *
2854 * exists('/etc/passwd', (e) => {
2855 * console.log(e ? 'it exists' : 'no passwd!');
2856 * });
2857 * ```
2858 *
2859 * **The parameters for this callback are not consistent with other Node.js**
2860 * **callbacks.** Normally, the first parameter to a Node.js callback is an `err`parameter, optionally followed by other parameters. The `fs.exists()` callback
2861 * has only one boolean parameter. This is one reason `fs.access()` is recommended
2862 * instead of `fs.exists()`.
2863 *
2864 * Using `fs.exists()` to check for the existence of a file before calling`fs.open()`, `fs.readFile()` or `fs.writeFile()` is not recommended. Doing
2865 * so introduces a race condition, since other processes may change the file's
2866 * state between the two calls. Instead, user code should open/read/write the
2867 * file directly and handle the error raised if the file does not exist.
2868 *
2869 * **write (NOT RECOMMENDED)**
2870 *
2871 * ```js
2872 * import { exists, open, close } from 'fs';
2873 *
2874 * exists('myfile', (e) => {
2875 * if (e) {
2876 * console.error('myfile already exists');
2877 * } else {
2878 * open('myfile', 'wx', (err, fd) => {
2879 * if (err) throw err;
2880 *
2881 * try {
2882 * writeMyData(fd);
2883 * } finally {
2884 * close(fd, (err) => {
2885 * if (err) throw err;
2886 * });
2887 * }
2888 * });
2889 * }
2890 * });
2891 * ```
2892 *
2893 * **write (RECOMMENDED)**
2894 *
2895 * ```js
2896 * import { open, close } from 'fs';
2897 * open('myfile', 'wx', (err, fd) => {
2898 * if (err) {
2899 * if (err.code === 'EEXIST') {
2900 * console.error('myfile already exists');
2901 * return;
2902 * }
2903 *
2904 * throw err;
2905 * }
2906 *
2907 * try {
2908 * writeMyData(fd);
2909 * } finally {
2910 * close(fd, (err) => {
2911 * if (err) throw err;
2912 * });
2913 * }
2914 * });
2915 * ```
2916 *
2917 * **read (NOT RECOMMENDED)**
2918 *
2919 * ```js
2920 * import { open, close, exists } from 'fs';
2921 *
2922 * exists('myfile', (e) => {
2923 * if (e) {
2924 * open('myfile', 'r', (err, fd) => {
2925 * if (err) throw err;
2926 *
2927 * try {
2928 * readMyData(fd);
2929 * } finally {
2930 * close(fd, (err) => {
2931 * if (err) throw err;
2932 * });
2933 * }
2934 * });
2935 * } else {
2936 * console.error('myfile does not exist');
2937 * }
2938 * });
2939 * ```
2940 *
2941 * **read (RECOMMENDED)**
2942 *
2943 * ```js
2944 * import { open, close } from 'fs';
2945 *
2946 * open('myfile', 'r', (err, fd) => {
2947 * if (err) {
2948 * if (err.code === 'ENOENT') {
2949 * console.error('myfile does not exist');
2950 * return;
2951 * }
2952 *
2953 * throw err;
2954 * }
2955 *
2956 * try {
2957 * readMyData(fd);
2958 * } finally {
2959 * close(fd, (err) => {
2960 * if (err) throw err;
2961 * });
2962 * }
2963 * });
2964 * ```
2965 *
2966 * The "not recommended" examples above check for existence and then use the
2967 * file; the "recommended" examples are better because they use the file directly
2968 * and handle the error, if any.
2969 *
2970 * In general, check for the existence of a file only if the file won’t be
2971 * used directly, for example when its existence is a signal from another
2972 * process.
2973 * @since v0.0.2
2974 * @deprecated Since v1.0.0 - Use {@link stat} or {@link access} instead.
2975 */
2976 export function exists(path: PathLike, callback: (exists: boolean) => void): void;
2977 export namespace exists {
2978 /**
2979 * @param path A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
2980 * URL support is _experimental_.
2981 */
2982 function __promisify__(path: PathLike): Promise<boolean>;
2983 }
2984 /**
2985 * Returns `true` if the path exists, `false` otherwise.
2986 *
2987 * For detailed information, see the documentation of the asynchronous version of
2988 * this API: {@link exists}.
2989 *
2990 * `fs.exists()` is deprecated, but `fs.existsSync()` is not. The `callback`parameter to `fs.exists()` accepts parameters that are inconsistent with other
2991 * Node.js callbacks. `fs.existsSync()` does not use a callback.
2992 *
2993 * ```js
2994 * import { existsSync } from 'fs';
2995 *
2996 * if (existsSync('/etc/passwd'))
2997 * console.log('The path exists.');
2998 * ```
2999 * @since v0.1.21
3000 */
3001 export function existsSync(path: PathLike): boolean;
3002 export namespace constants {
3003 // File Access Constants
3004 /** Constant for fs.access(). File is visible to the calling process. */
3005 const F_OK: number;
3006 /** Constant for fs.access(). File can be read by the calling process. */
3007 const R_OK: number;
3008 /** Constant for fs.access(). File can be written by the calling process. */
3009 const W_OK: number;
3010 /** Constant for fs.access(). File can be executed by the calling process. */
3011 const X_OK: number;
3012 // File Copy Constants
3013 /** Constant for fs.copyFile. Flag indicating the destination file should not be overwritten if it already exists. */
3014 const COPYFILE_EXCL: number;
3015 /**
3016 * Constant for fs.copyFile. copy operation will attempt to create a copy-on-write reflink.
3017 * If the underlying platform does not support copy-on-write, then a fallback copy mechanism is used.
3018 */
3019 const COPYFILE_FICLONE: number;
3020 /**
3021 * Constant for fs.copyFile. Copy operation will attempt to create a copy-on-write reflink.
3022 * If the underlying platform does not support copy-on-write, then the operation will fail with an error.
3023 */
3024 const COPYFILE_FICLONE_FORCE: number;
3025 // File Open Constants
3026 /** Constant for fs.open(). Flag indicating to open a file for read-only access. */
3027 const O_RDONLY: number;
3028 /** Constant for fs.open(). Flag indicating to open a file for write-only access. */
3029 const O_WRONLY: number;
3030 /** Constant for fs.open(). Flag indicating to open a file for read-write access. */
3031 const O_RDWR: number;
3032 /** Constant for fs.open(). Flag indicating to create the file if it does not already exist. */
3033 const O_CREAT: number;
3034 /** Constant for fs.open(). Flag indicating that opening a file should fail if the O_CREAT flag is set and the file already exists. */
3035 const O_EXCL: number;
3036 /**
3037 * Constant for fs.open(). Flag indicating that if path identifies a terminal device,
3038 * opening the path shall not cause that terminal to become the controlling terminal for the process
3039 * (if the process does not already have one).
3040 */
3041 const O_NOCTTY: number;
3042 /** 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. */
3043 const O_TRUNC: number;
3044 /** Constant for fs.open(). Flag indicating that data will be appended to the end of the file. */
3045 const O_APPEND: number;
3046 /** Constant for fs.open(). Flag indicating that the open should fail if the path is not a directory. */
3047 const O_DIRECTORY: number;
3048 /**
3049 * constant for fs.open().
3050 * Flag indicating reading accesses to the file system will no longer result in
3051 * an update to the atime information associated with the file.
3052 * This flag is available on Linux operating systems only.
3053 */
3054 const O_NOATIME: number;
3055 /** Constant for fs.open(). Flag indicating that the open should fail if the path is a symbolic link. */
3056 const O_NOFOLLOW: number;
3057 /** Constant for fs.open(). Flag indicating that the file is opened for synchronous I/O. */
3058 const O_SYNC: number;
3059 /** Constant for fs.open(). Flag indicating that the file is opened for synchronous I/O with write operations waiting for data integrity. */
3060 const O_DSYNC: number;
3061 /** Constant for fs.open(). Flag indicating to open the symbolic link itself rather than the resource it is pointing to. */
3062 const O_SYMLINK: number;
3063 /** Constant for fs.open(). When set, an attempt will be made to minimize caching effects of file I/O. */
3064 const O_DIRECT: number;
3065 /** Constant for fs.open(). Flag indicating to open the file in nonblocking mode when possible. */
3066 const O_NONBLOCK: number;
3067 // File Type Constants
3068 /** Constant for fs.Stats mode property for determining a file's type. Bit mask used to extract the file type code. */
3069 const S_IFMT: number;
3070 /** Constant for fs.Stats mode property for determining a file's type. File type constant for a regular file. */
3071 const S_IFREG: number;
3072 /** Constant for fs.Stats mode property for determining a file's type. File type constant for a directory. */
3073 const S_IFDIR: number;
3074 /** Constant for fs.Stats mode property for determining a file's type. File type constant for a character-oriented device file. */
3075 const S_IFCHR: number;
3076 /** Constant for fs.Stats mode property for determining a file's type. File type constant for a block-oriented device file. */
3077 const S_IFBLK: number;
3078 /** Constant for fs.Stats mode property for determining a file's type. File type constant for a FIFO/pipe. */
3079 const S_IFIFO: number;
3080 /** Constant for fs.Stats mode property for determining a file's type. File type constant for a symbolic link. */
3081 const S_IFLNK: number;
3082 /** Constant for fs.Stats mode property for determining a file's type. File type constant for a socket. */
3083 const S_IFSOCK: number;
3084 // File Mode Constants
3085 /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating readable, writable and executable by owner. */
3086 const S_IRWXU: number;
3087 /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating readable by owner. */
3088 const S_IRUSR: number;
3089 /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating writable by owner. */
3090 const S_IWUSR: number;
3091 /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating executable by owner. */
3092 const S_IXUSR: number;
3093 /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating readable, writable and executable by group. */
3094 const S_IRWXG: number;
3095 /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating readable by group. */
3096 const S_IRGRP: number;
3097 /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating writable by group. */
3098 const S_IWGRP: number;
3099 /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating executable by group. */
3100 const S_IXGRP: number;
3101 /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating readable, writable and executable by others. */
3102 const S_IRWXO: number;
3103 /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating readable by others. */
3104 const S_IROTH: number;
3105 /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating writable by others. */
3106 const S_IWOTH: number;
3107 /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating executable by others. */
3108 const S_IXOTH: number;
3109 /**
3110 * When set, a memory file mapping is used to access the file. This flag
3111 * is available on Windows operating systems only. On other operating systems,
3112 * this flag is ignored.
3113 */
3114 const UV_FS_O_FILEMAP: number;
3115 }
3116 /**
3117 * Tests a user's permissions for the file or directory specified by `path`.
3118 * The `mode` argument is an optional integer that specifies the accessibility
3119 * checks to be performed. Check `File access constants` for possible values
3120 * of `mode`. It is possible to create a mask consisting of the bitwise OR of
3121 * two or more values (e.g. `fs.constants.W_OK | fs.constants.R_OK`).
3122 *
3123 * The final argument, `callback`, is a callback function that is invoked with
3124 * a possible error argument. If any of the accessibility checks fail, the error
3125 * argument will be an `Error` object. The following examples check if`package.json` exists, and if it is readable or writable.
3126 *
3127 * ```js
3128 * import { access, constants } from 'fs';
3129 *
3130 * const file = 'package.json';
3131 *
3132 * // Check if the file exists in the current directory.
3133 * access(file, constants.F_OK, (err) => {
3134 * console.log(`${file} ${err ? 'does not exist' : 'exists'}`);
3135 * });
3136 *
3137 * // Check if the file is readable.
3138 * access(file, constants.R_OK, (err) => {
3139 * console.log(`${file} ${err ? 'is not readable' : 'is readable'}`);
3140 * });
3141 *
3142 * // Check if the file is writable.
3143 * access(file, constants.W_OK, (err) => {
3144 * console.log(`${file} ${err ? 'is not writable' : 'is writable'}`);
3145 * });
3146 *
3147 * // Check if the file exists in the current directory, and if it is writable.
3148 * access(file, constants.F_OK | fs.constants.W_OK, (err) => {
3149 * if (err) {
3150 * console.error(
3151 * `${file} ${err.code === 'ENOENT' ? 'does not exist' : 'is read-only'}`);
3152 * } else {
3153 * console.log(`${file} exists, and it is writable`);
3154 * }
3155 * });
3156 * ```
3157 *
3158 * Do not use `fs.access()` to check for the accessibility of a file before calling`fs.open()`, `fs.readFile()` or `fs.writeFile()`. Doing
3159 * so introduces a race condition, since other processes may change the file's
3160 * state between the two calls. Instead, user code should open/read/write the
3161 * file directly and handle the error raised if the file is not accessible.
3162 *
3163 * **write (NOT RECOMMENDED)**
3164 *
3165 * ```js
3166 * import { access, open, close } from 'fs';
3167 *
3168 * access('myfile', (err) => {
3169 * if (!err) {
3170 * console.error('myfile already exists');
3171 * return;
3172 * }
3173 *
3174 * open('myfile', 'wx', (err, fd) => {
3175 * if (err) throw err;
3176 *
3177 * try {
3178 * writeMyData(fd);
3179 * } finally {
3180 * close(fd, (err) => {
3181 * if (err) throw err;
3182 * });
3183 * }
3184 * });
3185 * });
3186 * ```
3187 *
3188 * **write (RECOMMENDED)**
3189 *
3190 * ```js
3191 * import { open, close } from 'fs';
3192 *
3193 * open('myfile', 'wx', (err, fd) => {
3194 * if (err) {
3195 * if (err.code === 'EEXIST') {
3196 * console.error('myfile already exists');
3197 * return;
3198 * }
3199 *
3200 * throw err;
3201 * }
3202 *
3203 * try {
3204 * writeMyData(fd);
3205 * } finally {
3206 * close(fd, (err) => {
3207 * if (err) throw err;
3208 * });
3209 * }
3210 * });
3211 * ```
3212 *
3213 * **read (NOT RECOMMENDED)**
3214 *
3215 * ```js
3216 * import { access, open, close } from 'fs';
3217 * access('myfile', (err) => {
3218 * if (err) {
3219 * if (err.code === 'ENOENT') {
3220 * console.error('myfile does not exist');
3221 * return;
3222 * }
3223 *
3224 * throw err;
3225 * }
3226 *
3227 * open('myfile', 'r', (err, fd) => {
3228 * if (err) throw err;
3229 *
3230 * try {
3231 * readMyData(fd);
3232 * } finally {
3233 * close(fd, (err) => {
3234 * if (err) throw err;
3235 * });
3236 * }
3237 * });
3238 * });
3239 * ```
3240 *
3241 * **read (RECOMMENDED)**
3242 *
3243 * ```js
3244 * import { open, close } from 'fs';
3245 *
3246 * open('myfile', 'r', (err, fd) => {
3247 * if (err) {
3248 * if (err.code === 'ENOENT') {
3249 * console.error('myfile does not exist');
3250 * return;
3251 * }
3252 *
3253 * throw err;
3254 * }
3255 *
3256 * try {
3257 * readMyData(fd);
3258 * } finally {
3259 * close(fd, (err) => {
3260 * if (err) throw err;
3261 * });
3262 * }
3263 * });
3264 * ```
3265 *
3266 * The "not recommended" examples above check for accessibility and then use the
3267 * file; the "recommended" examples are better because they use the file directly
3268 * and handle the error, if any.
3269 *
3270 * In general, check for the accessibility of a file only if the file will not be
3271 * used directly, for example when its accessibility is a signal from another
3272 * process.
3273 *
3274 * On Windows, access-control policies (ACLs) on a directory may limit access to
3275 * a file or directory. The `fs.access()` function, however, does not check the
3276 * ACL and therefore may report that a path is accessible even if the ACL restricts
3277 * the user from reading or writing to it.
3278 * @since v0.11.15
3279 * @param [mode=fs.constants.F_OK]
3280 */
3281 export function access(path: PathLike, mode: number | undefined, callback: NoParamCallback): void;
3282 /**
3283 * Asynchronously tests a user's permissions for the file specified by path.
3284 * @param path A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
3285 */
3286 export function access(path: PathLike, callback: NoParamCallback): void;
3287 export namespace access {
3288 /**
3289 * Asynchronously tests a user's permissions for the file specified by path.
3290 * @param path A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
3291 * URL support is _experimental_.
3292 */
3293 function __promisify__(path: PathLike, mode?: number): Promise<void>;
3294 }
3295 /**
3296 * Synchronously tests a user's permissions for the file or directory specified
3297 * by `path`. The `mode` argument is an optional integer that specifies the
3298 * accessibility checks to be performed. Check `File access constants` for
3299 * possible values of `mode`. It is possible to create a mask consisting of
3300 * the bitwise OR of two or more values
3301 * (e.g. `fs.constants.W_OK | fs.constants.R_OK`).
3302 *
3303 * If any of the accessibility checks fail, an `Error` will be thrown. Otherwise,
3304 * the method will return `undefined`.
3305 *
3306 * ```js
3307 * import { accessSync, constants } from 'fs';
3308 *
3309 * try {
3310 * accessSync('etc/passwd', constants.R_OK | constants.W_OK);
3311 * console.log('can read/write');
3312 * } catch (err) {
3313 * console.error('no access!');
3314 * }
3315 * ```
3316 * @since v0.11.15
3317 * @param [mode=fs.constants.F_OK]
3318 */
3319 export function accessSync(path: PathLike, mode?: number): void;
3320 interface StreamOptions {
3321 flags?: string | undefined;
3322 encoding?: BufferEncoding | undefined;
3323 fd?: number | promises.FileHandle | undefined;
3324 mode?: number | undefined;
3325 autoClose?: boolean | undefined;
3326 /**
3327 * @default false
3328 */
3329 emitClose?: boolean | undefined;
3330 start?: number | undefined;
3331 highWaterMark?: number | undefined;
3332 }
3333 interface ReadStreamOptions extends StreamOptions {
3334 end?: number | undefined;
3335 }
3336 /**
3337 * Unlike the 16 kb default `highWaterMark` for a readable stream, the stream
3338 * returned by this method has a default `highWaterMark` of 64 kb.
3339 *
3340 * `options` can include `start` and `end` values to read a range of bytes from
3341 * the file instead of the entire file. Both `start` and `end` are inclusive and
3342 * start counting at 0, allowed values are in the
3343 * \[0, [`Number.MAX_SAFE_INTEGER`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER)\] range. If `fd` is specified and `start` is
3344 * omitted or `undefined`, `fs.createReadStream()` reads sequentially from the
3345 * current file position. The `encoding` can be any one of those accepted by `<Buffer>`.
3346 *
3347 * If `fd` is specified, `ReadStream` will ignore the `path` argument and will use
3348 * the specified file descriptor. This means that no `'open'` event will be
3349 * emitted. `fd` should be blocking; non-blocking `fd`s should be passed to `<net.Socket>`.
3350 *
3351 * If `fd` points to a character device that only supports blocking reads
3352 * (such as keyboard or sound card), read operations do not finish until data is
3353 * available. This can prevent the process from exiting and the stream from
3354 * closing naturally.
3355 *
3356 * By default, the stream will emit a `'close'` event after it has been
3357 * destroyed, like most `Readable` streams. Set the `emitClose` option to`false` to change this behavior.
3358 *
3359 * By providing the `fs` option, it is possible to override the corresponding `fs`implementations for `open`, `read`, and `close`. When providing the `fs` option,
3360 * overrides for `open`, `read`, and `close` are required.
3361 *
3362 * ```js
3363 * import { createReadStream } from 'fs';
3364 *
3365 * // Create a stream from some character device.
3366 * const stream = createReadStream('/dev/input/event0');
3367 * setTimeout(() => {
3368 * stream.close(); // This may not close the stream.
3369 * // Artificially marking end-of-stream, as if the underlying resource had
3370 * // indicated end-of-file by itself, allows the stream to close.
3371 * // This does not cancel pending read operations, and if there is such an
3372 * // operation, the process may still not be able to exit successfully
3373 * // until it finishes.
3374 * stream.push(null);
3375 * stream.read(0);
3376 * }, 100);
3377 * ```
3378 *
3379 * If `autoClose` is false, then the file descriptor won't be closed, even if
3380 * there's an error. It is the application's responsibility to close it and make
3381 * sure there's no file descriptor leak. If `autoClose` is set to true (default
3382 * behavior), on `'error'` or `'end'` the file descriptor will be closed
3383 * automatically.
3384 *
3385 * `mode` sets the file mode (permission and sticky bits), but only if the
3386 * file was created.
3387 *
3388 * An example to read the last 10 bytes of a file which is 100 bytes long:
3389 *
3390 * ```js
3391 * import { createReadStream } from 'fs';
3392 *
3393 * createReadStream('sample.txt', { start: 90, end: 99 });
3394 * ```
3395 *
3396 * If `options` is a string, then it specifies the encoding.
3397 * @since v0.1.31
3398 * @return See `Readable Stream`.
3399 */
3400 export function createReadStream(path: PathLike, options?: BufferEncoding | ReadStreamOptions): ReadStream;
3401 /**
3402 * `options` may also include a `start` option to allow writing data at some
3403 * position past the beginning of the file, allowed values are in the
3404 * \[0, [`Number.MAX_SAFE_INTEGER`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER)\] range. Modifying a file rather than replacing
3405 * it may require the `flags` option to be set to `r+` rather than the default `w`.
3406 * The `encoding` can be any one of those accepted by `<Buffer>`.
3407 *
3408 * If `autoClose` is set to true (default behavior) on `'error'` or `'finish'`the file descriptor will be closed automatically. If `autoClose` is false,
3409 * then the file descriptor won't be closed, even if there's an error.
3410 * It is the application's responsibility to close it and make sure there's no
3411 * file descriptor leak.
3412 *
3413 * By default, the stream will emit a `'close'` event after it has been
3414 * destroyed, like most `Writable` streams. Set the `emitClose` option to`false` to change this behavior.
3415 *
3416 * By providing the `fs` option it is possible to override the corresponding `fs`implementations for `open`, `write`, `writev` and `close`. Overriding `write()`without `writev()` can reduce
3417 * performance as some optimizations (`_writev()`)
3418 * will be disabled. When providing the `fs` option, overrides for `open`,`close`, and at least one of `write` and `writev` are required.
3419 *
3420 * Like `<fs.ReadStream>`, if `fd` is specified, `<fs.WriteStream>` will ignore the`path` argument and will use the specified file descriptor. This means that no`'open'` event will be
3421 * emitted. `fd` should be blocking; non-blocking `fd`s
3422 * should be passed to `<net.Socket>`.
3423 *
3424 * If `options` is a string, then it specifies the encoding.
3425 * @since v0.1.31
3426 * @return See `Writable Stream`.
3427 */
3428 export function createWriteStream(path: PathLike, options?: BufferEncoding | StreamOptions): WriteStream;
3429 /**
3430 * Forces all currently queued I/O operations associated with the file to the
3431 * operating system's synchronized I/O completion state. Refer to the POSIX[`fdatasync(2)`](http://man7.org/linux/man-pages/man2/fdatasync.2.html) documentation for details. No arguments other
3432 * than a possible
3433 * exception are given to the completion callback.
3434 * @since v0.1.96
3435 */
3436 export function fdatasync(fd: number, callback: NoParamCallback): void;
3437 export namespace fdatasync {
3438 /**
3439 * Asynchronous fdatasync(2) - synchronize a file's in-core state with storage device.
3440 * @param fd A file descriptor.
3441 */
3442 function __promisify__(fd: number): Promise<void>;
3443 }
3444 /**
3445 * Forces all currently queued I/O operations associated with the file to the
3446 * operating system's synchronized I/O completion state. Refer to the POSIX[`fdatasync(2)`](http://man7.org/linux/man-pages/man2/fdatasync.2.html) documentation for details. Returns `undefined`.
3447 * @since v0.1.96
3448 */
3449 export function fdatasyncSync(fd: number): void;
3450 /**
3451 * Asynchronously copies `src` to `dest`. By default, `dest` is overwritten if it
3452 * already exists. No arguments other than a possible exception are given to the
3453 * callback function. Node.js makes no guarantees about the atomicity of the copy
3454 * operation. If an error occurs after the destination file has been opened for
3455 * writing, Node.js will attempt to remove the destination.
3456 *
3457 * `mode` is an optional integer that specifies the behavior
3458 * of the copy operation. It is possible to create a mask consisting of the bitwise
3459 * OR of two or more values (e.g.`fs.constants.COPYFILE_EXCL | fs.constants.COPYFILE_FICLONE`).
3460 *
3461 * * `fs.constants.COPYFILE_EXCL`: The copy operation will fail if `dest` already
3462 * exists.
3463 * * `fs.constants.COPYFILE_FICLONE`: The copy operation will attempt to create a
3464 * copy-on-write reflink. If the platform does not support copy-on-write, then a
3465 * fallback copy mechanism is used.
3466 * * `fs.constants.COPYFILE_FICLONE_FORCE`: The copy operation will attempt to
3467 * create a copy-on-write reflink. If the platform does not support
3468 * copy-on-write, then the operation will fail.
3469 *
3470 * ```js
3471 * import { copyFile, constants } from 'fs';
3472 *
3473 * function callback(err) {
3474 * if (err) throw err;
3475 * console.log('source.txt was copied to destination.txt');
3476 * }
3477 *
3478 * // destination.txt will be created or overwritten by default.
3479 * copyFile('source.txt', 'destination.txt', callback);
3480 *
3481 * // By using COPYFILE_EXCL, the operation will fail if destination.txt exists.
3482 * copyFile('source.txt', 'destination.txt', constants.COPYFILE_EXCL, callback);
3483 * ```
3484 * @since v8.5.0
3485 * @param src source filename to copy
3486 * @param dest destination filename of the copy operation
3487 * @param [mode=0] modifiers for copy operation.
3488 */
3489 export function copyFile(src: PathLike, dest: PathLike, callback: NoParamCallback): void;
3490 export function copyFile(src: PathLike, dest: PathLike, mode: number, callback: NoParamCallback): void;
3491 export namespace copyFile {
3492 function __promisify__(src: PathLike, dst: PathLike, mode?: number): Promise<void>;
3493 }
3494 /**
3495 * Synchronously copies `src` to `dest`. By default, `dest` is overwritten if it
3496 * already exists. Returns `undefined`. Node.js makes no guarantees about the
3497 * atomicity of the copy operation. If an error occurs after the destination file
3498 * has been opened for writing, Node.js will attempt to remove the destination.
3499 *
3500 * `mode` is an optional integer that specifies the behavior
3501 * of the copy operation. It is possible to create a mask consisting of the bitwise
3502 * OR of two or more values (e.g.`fs.constants.COPYFILE_EXCL | fs.constants.COPYFILE_FICLONE`).
3503 *
3504 * * `fs.constants.COPYFILE_EXCL`: The copy operation will fail if `dest` already
3505 * exists.
3506 * * `fs.constants.COPYFILE_FICLONE`: The copy operation will attempt to create a
3507 * copy-on-write reflink. If the platform does not support copy-on-write, then a
3508 * fallback copy mechanism is used.
3509 * * `fs.constants.COPYFILE_FICLONE_FORCE`: The copy operation will attempt to
3510 * create a copy-on-write reflink. If the platform does not support
3511 * copy-on-write, then the operation will fail.
3512 *
3513 * ```js
3514 * import { copyFileSync, constants } from 'fs';
3515 *
3516 * // destination.txt will be created or overwritten by default.
3517 * copyFileSync('source.txt', 'destination.txt');
3518 * console.log('source.txt was copied to destination.txt');
3519 *
3520 * // By using COPYFILE_EXCL, the operation will fail if destination.txt exists.
3521 * copyFileSync('source.txt', 'destination.txt', constants.COPYFILE_EXCL);
3522 * ```
3523 * @since v8.5.0
3524 * @param src source filename to copy
3525 * @param dest destination filename of the copy operation
3526 * @param [mode=0] modifiers for copy operation.
3527 */
3528 export function copyFileSync(src: PathLike, dest: PathLike, mode?: number): void;
3529 /**
3530 * Write an array of `ArrayBufferView`s to the file specified by `fd` using`writev()`.
3531 *
3532 * `position` is the offset from the beginning of the file where this data
3533 * should be written. If `typeof position !== 'number'`, the data will be written
3534 * at the current position.
3535 *
3536 * The callback will be given three arguments: `err`, `bytesWritten`, and`buffers`. `bytesWritten` is how many bytes were written from `buffers`.
3537 *
3538 * If this method is `util.promisify()` ed, it returns a promise for an`Object` with `bytesWritten` and `buffers` properties.
3539 *
3540 * It is unsafe to use `fs.writev()` multiple times on the same file without
3541 * waiting for the callback. For this scenario, use {@link createWriteStream}.
3542 *
3543 * On Linux, positional writes don't work when the file is opened in append mode.
3544 * The kernel ignores the position argument and always appends the data to
3545 * the end of the file.
3546 * @since v12.9.0
3547 */
3548 export function writev(fd: number, buffers: ReadonlyArray<NodeJS.ArrayBufferView>, cb: (err: NodeJS.ErrnoException | null, bytesWritten: number, buffers: NodeJS.ArrayBufferView[]) => void): void;
3549 export function writev(
3550 fd: number,
3551 buffers: ReadonlyArray<NodeJS.ArrayBufferView>,
3552 position: number,
3553 cb: (err: NodeJS.ErrnoException | null, bytesWritten: number, buffers: NodeJS.ArrayBufferView[]) => void
3554 ): void;
3555 export interface WriteVResult {
3556 bytesWritten: number;
3557 buffers: NodeJS.ArrayBufferView[];
3558 }
3559 export namespace writev {
3560 function __promisify__(fd: number, buffers: ReadonlyArray<NodeJS.ArrayBufferView>, position?: number): Promise<WriteVResult>;
3561 }
3562 /**
3563 * For detailed information, see the documentation of the asynchronous version of
3564 * this API: {@link writev}.
3565 * @since v12.9.0
3566 * @return The number of bytes written.
3567 */
3568 export function writevSync(fd: number, buffers: ReadonlyArray<NodeJS.ArrayBufferView>, position?: number): number;
3569 /**
3570 * Read from a file specified by `fd` and write to an array of `ArrayBufferView`s
3571 * using `readv()`.
3572 *
3573 * `position` is the offset from the beginning of the file from where data
3574 * should be read. If `typeof position !== 'number'`, the data will be read
3575 * from the current position.
3576 *
3577 * The callback will be given three arguments: `err`, `bytesRead`, and`buffers`. `bytesRead` is how many bytes were read from the file.
3578 *
3579 * If this method is invoked as its `util.promisify()` ed version, it returns
3580 * a promise for an `Object` with `bytesRead` and `buffers` properties.
3581 * @since v13.13.0, v12.17.0
3582 */
3583 export function readv(fd: number, buffers: ReadonlyArray<NodeJS.ArrayBufferView>, cb: (err: NodeJS.ErrnoException | null, bytesRead: number, buffers: NodeJS.ArrayBufferView[]) => void): void;
3584 export function readv(
3585 fd: number,
3586 buffers: ReadonlyArray<NodeJS.ArrayBufferView>,
3587 position: number,
3588 cb: (err: NodeJS.ErrnoException | null, bytesRead: number, buffers: NodeJS.ArrayBufferView[]) => void
3589 ): void;
3590 export interface ReadVResult {
3591 bytesRead: number;
3592 buffers: NodeJS.ArrayBufferView[];
3593 }
3594 export namespace readv {
3595 function __promisify__(fd: number, buffers: ReadonlyArray<NodeJS.ArrayBufferView>, position?: number): Promise<ReadVResult>;
3596 }
3597 /**
3598 * For detailed information, see the documentation of the asynchronous version of
3599 * this API: {@link readv}.
3600 * @since v13.13.0, v12.17.0
3601 * @return The number of bytes read.
3602 */
3603 export function readvSync(fd: number, buffers: ReadonlyArray<NodeJS.ArrayBufferView>, position?: number): number;
3604 export interface OpenDirOptions {
3605 encoding?: BufferEncoding | undefined;
3606 /**
3607 * Number of directory entries that are buffered
3608 * internally when reading from the directory. Higher values lead to better
3609 * performance but higher memory usage.
3610 * @default 32
3611 */
3612 bufferSize?: number | undefined;
3613 }
3614 /**
3615 * Synchronously open a directory. See [`opendir(3)`](http://man7.org/linux/man-pages/man3/opendir.3.html).
3616 *
3617 * Creates an `<fs.Dir>`, which contains all further functions for reading from
3618 * and cleaning up the directory.
3619 *
3620 * The `encoding` option sets the encoding for the `path` while opening the
3621 * directory and subsequent read operations.
3622 * @since v12.12.0
3623 */
3624 export function opendirSync(path: string, options?: OpenDirOptions): Dir;
3625 /**
3626 * Asynchronously open a directory. See the POSIX [`opendir(3)`](http://man7.org/linux/man-pages/man3/opendir.3.html) documentation for
3627 * more details.
3628 *
3629 * Creates an `<fs.Dir>`, which contains all further functions for reading from
3630 * and cleaning up the directory.
3631 *
3632 * The `encoding` option sets the encoding for the `path` while opening the
3633 * directory and subsequent read operations.
3634 * @since v12.12.0
3635 */
3636 export function opendir(path: string, cb: (err: NodeJS.ErrnoException | null, dir: Dir) => void): void;
3637 export function opendir(path: string, options: OpenDirOptions, cb: (err: NodeJS.ErrnoException | null, dir: Dir) => void): void;
3638 export namespace opendir {
3639 function __promisify__(path: string, options?: OpenDirOptions): Promise<Dir>;
3640 }
3641 export interface BigIntStats extends StatsBase<bigint> {
3642 atimeNs: bigint;
3643 mtimeNs: bigint;
3644 ctimeNs: bigint;
3645 birthtimeNs: bigint;
3646 }
3647 export interface BigIntOptions {
3648 bigint: true;
3649 }
3650 export interface StatOptions {
3651 bigint?: boolean | undefined;
3652 throwIfNoEntry?: boolean | undefined;
3653 }
3654}
3655declare module 'node:fs' {
3656 export * from 'fs';
3657}