@types/node 18.19.21 → 18.19.23

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