@types/node 18.7.18 → 18.7.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 (59) hide show
  1. node/README.md +1 -1
  2. node/globals.d.ts +2 -0
  3. node/index.d.ts +1 -1
  4. node/os.d.ts +1 -0
  5. node/package.json +9 -2
  6. node/test.d.ts +129 -5
  7. node/ts4.8/assert/strict.d.ts +8 -0
  8. node/ts4.8/assert.d.ts +911 -0
  9. node/ts4.8/async_hooks.d.ts +501 -0
  10. node/ts4.8/buffer.d.ts +2238 -0
  11. node/ts4.8/child_process.d.ts +1369 -0
  12. node/ts4.8/cluster.d.ts +410 -0
  13. node/ts4.8/console.d.ts +412 -0
  14. node/ts4.8/constants.d.ts +18 -0
  15. node/ts4.8/crypto.d.ts +3961 -0
  16. node/ts4.8/dgram.d.ts +545 -0
  17. node/ts4.8/diagnostics_channel.d.ts +153 -0
  18. node/ts4.8/dns/promises.d.ts +370 -0
  19. node/ts4.8/dns.d.ts +659 -0
  20. node/ts4.8/domain.d.ts +170 -0
  21. node/ts4.8/events.d.ts +641 -0
  22. node/ts4.8/fs/promises.d.ts +1120 -0
  23. node/ts4.8/fs.d.ts +3872 -0
  24. node/ts4.8/globals.d.ts +294 -0
  25. node/ts4.8/globals.global.d.ts +1 -0
  26. node/ts4.8/http.d.ts +1553 -0
  27. node/ts4.8/http2.d.ts +2106 -0
  28. node/ts4.8/https.d.ts +541 -0
  29. node/ts4.8/index.d.ts +87 -0
  30. node/ts4.8/inspector.d.ts +2741 -0
  31. node/ts4.8/module.d.ts +114 -0
  32. node/ts4.8/net.d.ts +838 -0
  33. node/ts4.8/os.d.ts +466 -0
  34. node/ts4.8/path.d.ts +191 -0
  35. node/ts4.8/perf_hooks.d.ts +610 -0
  36. node/ts4.8/process.d.ts +1482 -0
  37. node/ts4.8/punycode.d.ts +117 -0
  38. node/ts4.8/querystring.d.ts +131 -0
  39. node/ts4.8/readline/promises.d.ts +143 -0
  40. node/ts4.8/readline.d.ts +653 -0
  41. node/ts4.8/repl.d.ts +424 -0
  42. node/ts4.8/stream/consumers.d.ts +24 -0
  43. node/ts4.8/stream/promises.d.ts +42 -0
  44. node/ts4.8/stream/web.d.ts +330 -0
  45. node/ts4.8/stream.d.ts +1339 -0
  46. node/ts4.8/string_decoder.d.ts +67 -0
  47. node/ts4.8/test.d.ts +190 -0
  48. node/ts4.8/timers/promises.d.ts +68 -0
  49. node/ts4.8/timers.d.ts +94 -0
  50. node/ts4.8/tls.d.ts +1028 -0
  51. node/ts4.8/trace_events.d.ts +171 -0
  52. node/ts4.8/tty.d.ts +206 -0
  53. node/ts4.8/url.d.ts +897 -0
  54. node/ts4.8/util.d.ts +1792 -0
  55. node/ts4.8/v8.d.ts +396 -0
  56. node/ts4.8/vm.d.ts +509 -0
  57. node/ts4.8/wasi.d.ts +158 -0
  58. node/ts4.8/worker_threads.d.ts +646 -0
  59. node/ts4.8/zlib.d.ts +517 -0
@@ -0,0 +1,1120 @@
1
+ /**
2
+ * The `fs/promises` API provides asynchronous file system methods that return
3
+ * promises.
4
+ *
5
+ * The promise APIs use the underlying Node.js threadpool to perform file
6
+ * system operations off the event loop thread. These operations are not
7
+ * synchronized or threadsafe. Care must be taken when performing multiple
8
+ * concurrent modifications on the same file or data corruption may occur.
9
+ * @since v10.0.0
10
+ */
11
+ declare module 'fs/promises' {
12
+ import { Abortable } from 'node:events';
13
+ import { Stream } from 'node:stream';
14
+ import { ReadableStream } from 'node:stream/web';
15
+ import {
16
+ BigIntStats,
17
+ BufferEncodingOption,
18
+ constants as fsConstants,
19
+ CopyOptions,
20
+ Dir,
21
+ Dirent,
22
+ MakeDirectoryOptions,
23
+ Mode,
24
+ ObjectEncodingOptions,
25
+ OpenDirOptions,
26
+ OpenMode,
27
+ PathLike,
28
+ ReadStream,
29
+ ReadVResult,
30
+ RmDirOptions,
31
+ RmOptions,
32
+ StatOptions,
33
+ Stats,
34
+ TimeLike,
35
+ WatchEventType,
36
+ WatchOptions,
37
+ WriteStream,
38
+ WriteVResult,
39
+ } from 'node:fs';
40
+
41
+ interface FileChangeInfo<T extends string | Buffer> {
42
+ eventType: WatchEventType;
43
+ filename: T;
44
+ }
45
+ interface FlagAndOpenMode {
46
+ mode?: Mode | undefined;
47
+ flag?: OpenMode | undefined;
48
+ }
49
+ interface FileReadResult<T extends NodeJS.ArrayBufferView> {
50
+ bytesRead: number;
51
+ buffer: T;
52
+ }
53
+ interface FileReadOptions<T extends NodeJS.ArrayBufferView = Buffer> {
54
+ /**
55
+ * @default `Buffer.alloc(0xffff)`
56
+ */
57
+ buffer?: T;
58
+ /**
59
+ * @default 0
60
+ */
61
+ offset?: number | null;
62
+ /**
63
+ * @default `buffer.byteLength`
64
+ */
65
+ length?: number | null;
66
+ position?: number | null;
67
+ }
68
+ interface CreateReadStreamOptions {
69
+ encoding?: BufferEncoding | null | undefined;
70
+ autoClose?: boolean | undefined;
71
+ emitClose?: boolean | undefined;
72
+ start?: number | undefined;
73
+ end?: number | undefined;
74
+ highWaterMark?: number | undefined;
75
+ }
76
+ interface CreateWriteStreamOptions {
77
+ encoding?: BufferEncoding | null | undefined;
78
+ autoClose?: boolean | undefined;
79
+ emitClose?: boolean | undefined;
80
+ start?: number | undefined;
81
+ }
82
+ // TODO: Add `EventEmitter` close
83
+ interface FileHandle {
84
+ /**
85
+ * The numeric file descriptor managed by the {FileHandle} object.
86
+ * @since v10.0.0
87
+ */
88
+ readonly fd: number;
89
+ /**
90
+ * Alias of `filehandle.writeFile()`.
91
+ *
92
+ * When operating on file handles, the mode cannot be changed from what it was set
93
+ * to with `fsPromises.open()`. Therefore, this is equivalent to `filehandle.writeFile()`.
94
+ * @since v10.0.0
95
+ * @return Fulfills with `undefined` upon success.
96
+ */
97
+ appendFile(data: string | Uint8Array, options?: (ObjectEncodingOptions & FlagAndOpenMode) | BufferEncoding | null): Promise<void>;
98
+ /**
99
+ * Changes the ownership of the file. A wrapper for [`chown(2)`](http://man7.org/linux/man-pages/man2/chown.2.html).
100
+ * @since v10.0.0
101
+ * @param uid The file's new owner's user id.
102
+ * @param gid The file's new group's group id.
103
+ * @return Fulfills with `undefined` upon success.
104
+ */
105
+ chown(uid: number, gid: number): Promise<void>;
106
+ /**
107
+ * Modifies the permissions on the file. See [`chmod(2)`](http://man7.org/linux/man-pages/man2/chmod.2.html).
108
+ * @since v10.0.0
109
+ * @param mode the file mode bit mask.
110
+ * @return Fulfills with `undefined` upon success.
111
+ */
112
+ chmod(mode: Mode): Promise<void>;
113
+ /**
114
+ * Unlike the 16 kb default `highWaterMark` for a `stream.Readable`, the stream
115
+ * returned by this method has a default `highWaterMark` of 64 kb.
116
+ *
117
+ * `options` can include `start` and `end` values to read a range of bytes from
118
+ * the file instead of the entire file. Both `start` and `end` are inclusive and
119
+ * start counting at 0, allowed values are in the
120
+ * \[0, [`Number.MAX_SAFE_INTEGER`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER)\] range. If `start` is
121
+ * omitted or `undefined`, `filehandle.createReadStream()` reads sequentially from
122
+ * the current file position. The `encoding` can be any one of those accepted by `Buffer`.
123
+ *
124
+ * If the `FileHandle` points to a character device that only supports blocking
125
+ * reads (such as keyboard or sound card), read operations do not finish until data
126
+ * is available. This can prevent the process from exiting and the stream from
127
+ * closing naturally.
128
+ *
129
+ * By default, the stream will emit a `'close'` event after it has been
130
+ * destroyed. Set the `emitClose` option to `false` to change this behavior.
131
+ *
132
+ * ```js
133
+ * import { open } from 'fs/promises';
134
+ *
135
+ * const fd = await open('/dev/input/event0');
136
+ * // Create a stream from some character device.
137
+ * const stream = fd.createReadStream();
138
+ * setTimeout(() => {
139
+ * stream.close(); // This may not close the stream.
140
+ * // Artificially marking end-of-stream, as if the underlying resource had
141
+ * // indicated end-of-file by itself, allows the stream to close.
142
+ * // This does not cancel pending read operations, and if there is such an
143
+ * // operation, the process may still not be able to exit successfully
144
+ * // until it finishes.
145
+ * stream.push(null);
146
+ * stream.read(0);
147
+ * }, 100);
148
+ * ```
149
+ *
150
+ * If `autoClose` is false, then the file descriptor won't be closed, even if
151
+ * there's an error. It is the application's responsibility to close it and make
152
+ * sure there's no file descriptor leak. If `autoClose` is set to true (default
153
+ * behavior), on `'error'` or `'end'` the file descriptor will be closed
154
+ * automatically.
155
+ *
156
+ * An example to read the last 10 bytes of a file which is 100 bytes long:
157
+ *
158
+ * ```js
159
+ * import { open } from 'fs/promises';
160
+ *
161
+ * const fd = await open('sample.txt');
162
+ * fd.createReadStream({ start: 90, end: 99 });
163
+ * ```
164
+ * @since v16.11.0
165
+ */
166
+ createReadStream(options?: CreateReadStreamOptions): ReadStream;
167
+ /**
168
+ * `options` may also include a `start` option to allow writing data at some
169
+ * position past the beginning of the file, allowed values are in the
170
+ * \[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
171
+ * replacing it may require the `flags` `open` option to be set to `r+` rather than
172
+ * the default `r`. The `encoding` can be any one of those accepted by `Buffer`.
173
+ *
174
+ * If `autoClose` is set to true (default behavior) on `'error'` or `'finish'`the file descriptor will be closed automatically. If `autoClose` is false,
175
+ * then the file descriptor won't be closed, even if there's an error.
176
+ * It is the application's responsibility to close it and make sure there's no
177
+ * file descriptor leak.
178
+ *
179
+ * By default, the stream will emit a `'close'` event after it has been
180
+ * destroyed. Set the `emitClose` option to `false` to change this behavior.
181
+ * @since v16.11.0
182
+ */
183
+ createWriteStream(options?: CreateWriteStreamOptions): WriteStream;
184
+ /**
185
+ * Forces all currently queued I/O operations associated with the file to the
186
+ * 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.
187
+ *
188
+ * Unlike `filehandle.sync` this method does not flush modified metadata.
189
+ * @since v10.0.0
190
+ * @return Fulfills with `undefined` upon success.
191
+ */
192
+ datasync(): Promise<void>;
193
+ /**
194
+ * Request that all data for the open file descriptor is flushed to the storage
195
+ * device. The specific implementation is operating system and device specific.
196
+ * Refer to the POSIX [`fsync(2)`](http://man7.org/linux/man-pages/man2/fsync.2.html) documentation for more detail.
197
+ * @since v10.0.0
198
+ * @return Fufills with `undefined` upon success.
199
+ */
200
+ sync(): Promise<void>;
201
+ /**
202
+ * Reads data from the file and stores that in the given buffer.
203
+ *
204
+ * If the file is not modified concurrently, the end-of-file is reached when the
205
+ * number of bytes read is zero.
206
+ * @since v10.0.0
207
+ * @param buffer A buffer that will be filled with the file data read.
208
+ * @param offset The location in the buffer at which to start filling.
209
+ * @param length The number of bytes to read.
210
+ * @param position The location where to begin reading data from the file. If `null`, data will be read from the current file position, and the position will be updated. If `position` is an
211
+ * integer, the current file position will remain unchanged.
212
+ * @return Fulfills upon success with an object with two properties:
213
+ */
214
+ read<T extends NodeJS.ArrayBufferView>(buffer: T, offset?: number | null, length?: number | null, position?: number | null): Promise<FileReadResult<T>>;
215
+ read<T extends NodeJS.ArrayBufferView = Buffer>(options?: FileReadOptions<T>): Promise<FileReadResult<T>>;
216
+ /**
217
+ * Returns a `ReadableStream` that may be used to read the files data.
218
+ *
219
+ * An error will be thrown if this method is called more than once or is called after the `FileHandle` is closed
220
+ * or closing.
221
+ *
222
+ * ```js
223
+ * import { open } from 'node:fs/promises';
224
+ *
225
+ * const file = await open('./some/file/to/read');
226
+ *
227
+ * for await (const chunk of file.readableWebStream())
228
+ * console.log(chunk);
229
+ *
230
+ * await file.close();
231
+ * ```
232
+ *
233
+ * While the `ReadableStream` will read the file to completion, it will not close the `FileHandle` automatically. User code must still call the `fileHandle.close()` method.
234
+ *
235
+ * @since v17.0.0
236
+ * @experimental
237
+ */
238
+ readableWebStream(): ReadableStream;
239
+ /**
240
+ * Asynchronously reads the entire contents of a file.
241
+ *
242
+ * If `options` is a string, then it specifies the `encoding`.
243
+ *
244
+ * The `FileHandle` has to support reading.
245
+ *
246
+ * If one or more `filehandle.read()` calls are made on a file handle and then a`filehandle.readFile()` call is made, the data will be read from the current
247
+ * position till the end of the file. It doesn't always read from the beginning
248
+ * of the file.
249
+ * @since v10.0.0
250
+ * @return Fulfills upon a successful read with the contents of the file. If no encoding is specified (using `options.encoding`), the data is returned as a {Buffer} object. Otherwise, the
251
+ * data will be a string.
252
+ */
253
+ readFile(
254
+ options?: {
255
+ encoding?: null | undefined;
256
+ flag?: OpenMode | undefined;
257
+ } | null
258
+ ): Promise<Buffer>;
259
+ /**
260
+ * Asynchronously reads the entire contents of a file. The underlying file will _not_ be closed automatically.
261
+ * The `FileHandle` must have been opened for reading.
262
+ * @param options An object that may contain an optional flag.
263
+ * If a flag is not provided, it defaults to `'r'`.
264
+ */
265
+ readFile(
266
+ options:
267
+ | {
268
+ encoding: BufferEncoding;
269
+ flag?: OpenMode | undefined;
270
+ }
271
+ | BufferEncoding
272
+ ): Promise<string>;
273
+ /**
274
+ * Asynchronously reads the entire contents of a file. The underlying file will _not_ be closed automatically.
275
+ * The `FileHandle` must have been opened for reading.
276
+ * @param options An object that may contain an optional flag.
277
+ * If a flag is not provided, it defaults to `'r'`.
278
+ */
279
+ readFile(
280
+ options?:
281
+ | (ObjectEncodingOptions & {
282
+ flag?: OpenMode | undefined;
283
+ })
284
+ | BufferEncoding
285
+ | null
286
+ ): Promise<string | Buffer>;
287
+ /**
288
+ * @since v10.0.0
289
+ * @return Fulfills with an {fs.Stats} for the file.
290
+ */
291
+ stat(
292
+ opts?: StatOptions & {
293
+ bigint?: false | undefined;
294
+ }
295
+ ): Promise<Stats>;
296
+ stat(
297
+ opts: StatOptions & {
298
+ bigint: true;
299
+ }
300
+ ): Promise<BigIntStats>;
301
+ stat(opts?: StatOptions): Promise<Stats | BigIntStats>;
302
+ /**
303
+ * Truncates the file.
304
+ *
305
+ * If the file was larger than `len` bytes, only the first `len` bytes will be
306
+ * retained in the file.
307
+ *
308
+ * The following example retains only the first four bytes of the file:
309
+ *
310
+ * ```js
311
+ * import { open } from 'fs/promises';
312
+ *
313
+ * let filehandle = null;
314
+ * try {
315
+ * filehandle = await open('temp.txt', 'r+');
316
+ * await filehandle.truncate(4);
317
+ * } finally {
318
+ * await filehandle?.close();
319
+ * }
320
+ * ```
321
+ *
322
+ * If the file previously was shorter than `len` bytes, it is extended, and the
323
+ * extended part is filled with null bytes (`'\0'`):
324
+ *
325
+ * If `len` is negative then `0` will be used.
326
+ * @since v10.0.0
327
+ * @param [len=0]
328
+ * @return Fulfills with `undefined` upon success.
329
+ */
330
+ truncate(len?: number): Promise<void>;
331
+ /**
332
+ * Change the file system timestamps of the object referenced by the `FileHandle` then resolves the promise with no arguments upon success.
333
+ * @since v10.0.0
334
+ */
335
+ utimes(atime: TimeLike, mtime: TimeLike): Promise<void>;
336
+ /**
337
+ * Asynchronously writes data to a file, replacing the file if it already exists.`data` can be a string, a buffer, an
338
+ * [AsyncIterable](https://tc39.github.io/ecma262/#sec-asynciterable-interface) or
339
+ * [Iterable](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterable_protocol) object.
340
+ * The promise is resolved with no arguments upon success.
341
+ *
342
+ * If `options` is a string, then it specifies the `encoding`.
343
+ *
344
+ * The `FileHandle` has to support writing.
345
+ *
346
+ * It is unsafe to use `filehandle.writeFile()` multiple times on the same file
347
+ * without waiting for the promise to be resolved (or rejected).
348
+ *
349
+ * If one or more `filehandle.write()` calls are made on a file handle and then a`filehandle.writeFile()` call is made, the data will be written from the
350
+ * current position till the end of the file. It doesn't always write from the
351
+ * beginning of the file.
352
+ * @since v10.0.0
353
+ */
354
+ writeFile(data: string | Uint8Array, options?: (ObjectEncodingOptions & FlagAndOpenMode & Abortable) | BufferEncoding | null): Promise<void>;
355
+ /**
356
+ * Write `buffer` to the file.
357
+ *
358
+ * The promise is resolved with an object containing two properties:
359
+ *
360
+ * It is unsafe to use `filehandle.write()` multiple times on the same file
361
+ * without waiting for the promise to be resolved (or rejected). For this
362
+ * scenario, use `filehandle.createWriteStream()`.
363
+ *
364
+ * On Linux, positional writes do not work when the file is opened in append mode.
365
+ * The kernel ignores the position argument and always appends the data to
366
+ * the end of the file.
367
+ * @since v10.0.0
368
+ * @param [offset=0] The start position from within `buffer` where the data to write begins.
369
+ * @param [length=buffer.byteLength - offset] The number of bytes from `buffer` to write.
370
+ * @param position The offset from the beginning of the file where the data from `buffer` should be written. If `position` is not a `number`, the data will be written at the current position.
371
+ * See the POSIX pwrite(2) documentation for more detail.
372
+ */
373
+ write<TBuffer extends Uint8Array>(
374
+ buffer: TBuffer,
375
+ offset?: number | null,
376
+ length?: number | null,
377
+ position?: number | null
378
+ ): Promise<{
379
+ bytesWritten: number;
380
+ buffer: TBuffer;
381
+ }>;
382
+ write(
383
+ data: string,
384
+ position?: number | null,
385
+ encoding?: BufferEncoding | null
386
+ ): Promise<{
387
+ bytesWritten: number;
388
+ buffer: string;
389
+ }>;
390
+ /**
391
+ * Write an array of [ArrayBufferView](https://developer.mozilla.org/en-US/docs/Web/API/ArrayBufferView) s to the file.
392
+ *
393
+ * The promise is resolved with an object containing a two properties:
394
+ *
395
+ * It is unsafe to call `writev()` multiple times on the same file without waiting
396
+ * for the promise to be resolved (or rejected).
397
+ *
398
+ * On Linux, positional writes don't work when the file is opened in append mode.
399
+ * The kernel ignores the position argument and always appends the data to
400
+ * the end of the file.
401
+ * @since v12.9.0
402
+ * @param position The offset from the beginning of the file where the data from `buffers` should be written. If `position` is not a `number`, the data will be written at the current
403
+ * position.
404
+ */
405
+ writev(buffers: ReadonlyArray<NodeJS.ArrayBufferView>, position?: number): Promise<WriteVResult>;
406
+ /**
407
+ * Read from a file and write to an array of [ArrayBufferView](https://developer.mozilla.org/en-US/docs/Web/API/ArrayBufferView) s
408
+ * @since v13.13.0, v12.17.0
409
+ * @param position The offset from the beginning of the file where the data should be read from. If `position` is not a `number`, the data will be read from the current position.
410
+ * @return Fulfills upon success an object containing two properties:
411
+ */
412
+ readv(buffers: ReadonlyArray<NodeJS.ArrayBufferView>, position?: number): Promise<ReadVResult>;
413
+ /**
414
+ * Closes the file handle after waiting for any pending operation on the handle to
415
+ * complete.
416
+ *
417
+ * ```js
418
+ * import { open } from 'fs/promises';
419
+ *
420
+ * let filehandle;
421
+ * try {
422
+ * filehandle = await open('thefile.txt', 'r');
423
+ * } finally {
424
+ * await filehandle?.close();
425
+ * }
426
+ * ```
427
+ * @since v10.0.0
428
+ * @return Fulfills with `undefined` upon success.
429
+ */
430
+ close(): Promise<void>;
431
+ }
432
+
433
+ const constants: typeof fsConstants;
434
+
435
+ /**
436
+ * Tests a user's permissions for the file or directory specified by `path`.
437
+ * The `mode` argument is an optional integer that specifies the accessibility
438
+ * 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`
439
+ * (e.g.`fs.constants.W_OK | fs.constants.R_OK`). Check `File access constants` for
440
+ * possible values of `mode`.
441
+ *
442
+ * If the accessibility check is successful, the promise is resolved with no
443
+ * value. If any of the accessibility checks fail, the promise is rejected
444
+ * with an [Error](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error) object. The following example checks if the file`/etc/passwd` can be read and
445
+ * written by the current process.
446
+ *
447
+ * ```js
448
+ * import { access } from 'fs/promises';
449
+ * import { constants } from 'fs';
450
+ *
451
+ * try {
452
+ * await access('/etc/passwd', constants.R_OK | constants.W_OK);
453
+ * console.log('can access');
454
+ * } catch {
455
+ * console.error('cannot access');
456
+ * }
457
+ * ```
458
+ *
459
+ * Using `fsPromises.access()` to check for the accessibility of a file before
460
+ * calling `fsPromises.open()` is not recommended. Doing so introduces a race
461
+ * condition, since other processes may change the file's state between the two
462
+ * calls. Instead, user code should open/read/write the file directly and handle
463
+ * the error raised if the file is not accessible.
464
+ * @since v10.0.0
465
+ * @param [mode=fs.constants.F_OK]
466
+ * @return Fulfills with `undefined` upon success.
467
+ */
468
+ function access(path: PathLike, mode?: number): Promise<void>;
469
+ /**
470
+ * Asynchronously copies `src` to `dest`. By default, `dest` is overwritten if it
471
+ * already exists.
472
+ *
473
+ * No guarantees are made about the atomicity of the copy operation. If an
474
+ * error occurs after the destination file has been opened for writing, an attempt
475
+ * will be made to remove the destination.
476
+ *
477
+ * ```js
478
+ * import { constants } from 'fs';
479
+ * import { copyFile } from 'fs/promises';
480
+ *
481
+ * try {
482
+ * await copyFile('source.txt', 'destination.txt');
483
+ * console.log('source.txt was copied to destination.txt');
484
+ * } catch {
485
+ * console.log('The file could not be copied');
486
+ * }
487
+ *
488
+ * // By using COPYFILE_EXCL, the operation will fail if destination.txt exists.
489
+ * try {
490
+ * await copyFile('source.txt', 'destination.txt', constants.COPYFILE_EXCL);
491
+ * console.log('source.txt was copied to destination.txt');
492
+ * } catch {
493
+ * console.log('The file could not be copied');
494
+ * }
495
+ * ```
496
+ * @since v10.0.0
497
+ * @param src source filename to copy
498
+ * @param dest destination filename of the copy operation
499
+ * @param [mode=0] Optional modifiers that specify the behavior of the copy operation. It is possible to create a mask consisting of the bitwise OR of two or more values (e.g.
500
+ * `fs.constants.COPYFILE_EXCL | fs.constants.COPYFILE_FICLONE`)
501
+ * @return Fulfills with `undefined` upon success.
502
+ */
503
+ function copyFile(src: PathLike, dest: PathLike, mode?: number): Promise<void>;
504
+ /**
505
+ * Opens a `FileHandle`.
506
+ *
507
+ * Refer to the POSIX [`open(2)`](http://man7.org/linux/man-pages/man2/open.2.html) documentation for more detail.
508
+ *
509
+ * Some characters (`< > : " / \ | ? *`) are reserved under Windows as documented
510
+ * by [Naming Files, Paths, and Namespaces](https://docs.microsoft.com/en-us/windows/desktop/FileIO/naming-a-file). Under NTFS, if the filename contains
511
+ * 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).
512
+ * @since v10.0.0
513
+ * @param [flags='r'] See `support of file system `flags``.
514
+ * @param [mode=0o666] Sets the file mode (permission and sticky bits) if the file is created.
515
+ * @return Fulfills with a {FileHandle} object.
516
+ */
517
+ function open(path: PathLike, flags?: string | number, mode?: Mode): Promise<FileHandle>;
518
+ /**
519
+ * Renames `oldPath` to `newPath`.
520
+ * @since v10.0.0
521
+ * @return Fulfills with `undefined` upon success.
522
+ */
523
+ function rename(oldPath: PathLike, newPath: PathLike): Promise<void>;
524
+ /**
525
+ * Truncates (shortens or extends the length) of the content at `path` to `len`bytes.
526
+ * @since v10.0.0
527
+ * @param [len=0]
528
+ * @return Fulfills with `undefined` upon success.
529
+ */
530
+ function truncate(path: PathLike, len?: number): Promise<void>;
531
+ /**
532
+ * Removes the directory identified by `path`.
533
+ *
534
+ * Using `fsPromises.rmdir()` on a file (not a directory) results in the
535
+ * promise being rejected with an `ENOENT` error on Windows and an `ENOTDIR`error on POSIX.
536
+ *
537
+ * To get a behavior similar to the `rm -rf` Unix command, use `fsPromises.rm()` with options `{ recursive: true, force: true }`.
538
+ * @since v10.0.0
539
+ * @return Fulfills with `undefined` upon success.
540
+ */
541
+ function rmdir(path: PathLike, options?: RmDirOptions): Promise<void>;
542
+ /**
543
+ * Removes files and directories (modeled on the standard POSIX `rm` utility).
544
+ * @since v14.14.0
545
+ * @return Fulfills with `undefined` upon success.
546
+ */
547
+ function rm(path: PathLike, options?: RmOptions): Promise<void>;
548
+ /**
549
+ * Asynchronously creates a directory.
550
+ *
551
+ * The optional `options` argument can be an integer specifying `mode` (permission
552
+ * and sticky bits), or an object with a `mode` property and a `recursive`property indicating whether parent directories should be created. Calling`fsPromises.mkdir()` when `path` is a directory
553
+ * that exists results in a
554
+ * rejection only when `recursive` is false.
555
+ * @since v10.0.0
556
+ * @return Upon success, fulfills with `undefined` if `recursive` is `false`, or the first directory path created if `recursive` is `true`.
557
+ */
558
+ function mkdir(
559
+ path: PathLike,
560
+ options: MakeDirectoryOptions & {
561
+ recursive: true;
562
+ }
563
+ ): Promise<string | undefined>;
564
+ /**
565
+ * Asynchronous mkdir(2) - create a directory.
566
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
567
+ * @param options Either the file mode, or an object optionally specifying the file mode and whether parent folders
568
+ * should be created. If a string is passed, it is parsed as an octal integer. If not specified, defaults to `0o777`.
569
+ */
570
+ function mkdir(
571
+ path: PathLike,
572
+ options?:
573
+ | Mode
574
+ | (MakeDirectoryOptions & {
575
+ recursive?: false | undefined;
576
+ })
577
+ | null
578
+ ): Promise<void>;
579
+ /**
580
+ * Asynchronous mkdir(2) - create a directory.
581
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
582
+ * @param options Either the file mode, or an object optionally specifying the file mode and whether parent folders
583
+ * should be created. If a string is passed, it is parsed as an octal integer. If not specified, defaults to `0o777`.
584
+ */
585
+ function mkdir(path: PathLike, options?: Mode | MakeDirectoryOptions | null): Promise<string | undefined>;
586
+ /**
587
+ * Reads the contents of a directory.
588
+ *
589
+ * The optional `options` argument can be a string specifying an encoding, or an
590
+ * object with an `encoding` property specifying the character encoding to use for
591
+ * the filenames. If the `encoding` is set to `'buffer'`, the filenames returned
592
+ * will be passed as `Buffer` objects.
593
+ *
594
+ * If `options.withFileTypes` is set to `true`, the resolved array will contain `fs.Dirent` objects.
595
+ *
596
+ * ```js
597
+ * import { readdir } from 'fs/promises';
598
+ *
599
+ * try {
600
+ * const files = await readdir(path);
601
+ * for (const file of files)
602
+ * console.log(file);
603
+ * } catch (err) {
604
+ * console.error(err);
605
+ * }
606
+ * ```
607
+ * @since v10.0.0
608
+ * @return Fulfills with an array of the names of the files in the directory excluding `'.'` and `'..'`.
609
+ */
610
+ function readdir(
611
+ path: PathLike,
612
+ options?:
613
+ | (ObjectEncodingOptions & {
614
+ withFileTypes?: false | undefined;
615
+ })
616
+ | BufferEncoding
617
+ | null
618
+ ): Promise<string[]>;
619
+ /**
620
+ * Asynchronous readdir(3) - read a directory.
621
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
622
+ * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
623
+ */
624
+ function readdir(
625
+ path: PathLike,
626
+ options:
627
+ | {
628
+ encoding: 'buffer';
629
+ withFileTypes?: false | undefined;
630
+ }
631
+ | 'buffer'
632
+ ): Promise<Buffer[]>;
633
+ /**
634
+ * Asynchronous readdir(3) - read a directory.
635
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
636
+ * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
637
+ */
638
+ function readdir(
639
+ path: PathLike,
640
+ options?:
641
+ | (ObjectEncodingOptions & {
642
+ withFileTypes?: false | undefined;
643
+ })
644
+ | BufferEncoding
645
+ | null
646
+ ): Promise<string[] | Buffer[]>;
647
+ /**
648
+ * Asynchronous readdir(3) - read a directory.
649
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
650
+ * @param options If called with `withFileTypes: true` the result data will be an array of Dirent.
651
+ */
652
+ function readdir(
653
+ path: PathLike,
654
+ options: ObjectEncodingOptions & {
655
+ withFileTypes: true;
656
+ }
657
+ ): Promise<Dirent[]>;
658
+ /**
659
+ * Reads the contents of the symbolic link referred to by `path`. See the POSIX [`readlink(2)`](http://man7.org/linux/man-pages/man2/readlink.2.html) documentation for more detail. The promise is
660
+ * resolved with the`linkString` upon success.
661
+ *
662
+ * The optional `options` argument can be a string specifying an encoding, or an
663
+ * object with an `encoding` property specifying the character encoding to use for
664
+ * the link path returned. If the `encoding` is set to `'buffer'`, the link path
665
+ * returned will be passed as a `Buffer` object.
666
+ * @since v10.0.0
667
+ * @return Fulfills with the `linkString` upon success.
668
+ */
669
+ function readlink(path: PathLike, options?: ObjectEncodingOptions | BufferEncoding | null): Promise<string>;
670
+ /**
671
+ * Asynchronous readlink(2) - read value of a symbolic link.
672
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
673
+ * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
674
+ */
675
+ function readlink(path: PathLike, options: BufferEncodingOption): Promise<Buffer>;
676
+ /**
677
+ * Asynchronous readlink(2) - read value of a symbolic link.
678
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
679
+ * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
680
+ */
681
+ function readlink(path: PathLike, options?: ObjectEncodingOptions | string | null): Promise<string | Buffer>;
682
+ /**
683
+ * Creates a symbolic link.
684
+ *
685
+ * The `type` argument is only used on Windows platforms and can be one of `'dir'`,`'file'`, or `'junction'`. Windows junction points require the destination path
686
+ * to be absolute. When using `'junction'`, the `target` argument will
687
+ * automatically be normalized to absolute path.
688
+ * @since v10.0.0
689
+ * @param [type='file']
690
+ * @return Fulfills with `undefined` upon success.
691
+ */
692
+ function symlink(target: PathLike, path: PathLike, type?: string | null): Promise<void>;
693
+ /**
694
+ * Equivalent to `fsPromises.stat()` unless `path` refers to a symbolic link,
695
+ * in which case the link itself is stat-ed, not the file that it refers to.
696
+ * Refer to the POSIX [`lstat(2)`](http://man7.org/linux/man-pages/man2/lstat.2.html) document for more detail.
697
+ * @since v10.0.0
698
+ * @return Fulfills with the {fs.Stats} object for the given symbolic link `path`.
699
+ */
700
+ function lstat(
701
+ path: PathLike,
702
+ opts?: StatOptions & {
703
+ bigint?: false | undefined;
704
+ }
705
+ ): Promise<Stats>;
706
+ function lstat(
707
+ path: PathLike,
708
+ opts: StatOptions & {
709
+ bigint: true;
710
+ }
711
+ ): Promise<BigIntStats>;
712
+ function lstat(path: PathLike, opts?: StatOptions): Promise<Stats | BigIntStats>;
713
+ /**
714
+ * @since v10.0.0
715
+ * @return Fulfills with the {fs.Stats} object for the given `path`.
716
+ */
717
+ function stat(
718
+ path: PathLike,
719
+ opts?: StatOptions & {
720
+ bigint?: false | undefined;
721
+ }
722
+ ): Promise<Stats>;
723
+ function stat(
724
+ path: PathLike,
725
+ opts: StatOptions & {
726
+ bigint: true;
727
+ }
728
+ ): Promise<BigIntStats>;
729
+ function stat(path: PathLike, opts?: StatOptions): Promise<Stats | BigIntStats>;
730
+ /**
731
+ * 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.
732
+ * @since v10.0.0
733
+ * @return Fulfills with `undefined` upon success.
734
+ */
735
+ function link(existingPath: PathLike, newPath: PathLike): Promise<void>;
736
+ /**
737
+ * If `path` refers to a symbolic link, then the link is removed without affecting
738
+ * the file or directory to which that link refers. If the `path` refers to a file
739
+ * path that is not a symbolic link, the file is deleted. See the POSIX [`unlink(2)`](http://man7.org/linux/man-pages/man2/unlink.2.html) documentation for more detail.
740
+ * @since v10.0.0
741
+ * @return Fulfills with `undefined` upon success.
742
+ */
743
+ function unlink(path: PathLike): Promise<void>;
744
+ /**
745
+ * Changes the permissions of a file.
746
+ * @since v10.0.0
747
+ * @return Fulfills with `undefined` upon success.
748
+ */
749
+ function chmod(path: PathLike, mode: Mode): Promise<void>;
750
+ /**
751
+ * Changes the permissions on a symbolic link.
752
+ *
753
+ * This method is only implemented on macOS.
754
+ * @deprecated Since v10.0.0
755
+ * @return Fulfills with `undefined` upon success.
756
+ */
757
+ function lchmod(path: PathLike, mode: Mode): Promise<void>;
758
+ /**
759
+ * Changes the ownership on a symbolic link.
760
+ * @since v10.0.0
761
+ * @return Fulfills with `undefined` upon success.
762
+ */
763
+ function lchown(path: PathLike, uid: number, gid: number): Promise<void>;
764
+ /**
765
+ * Changes the access and modification times of a file in the same way as `fsPromises.utimes()`, with the difference that if the path refers to a
766
+ * symbolic link, then the link is not dereferenced: instead, the timestamps of
767
+ * the symbolic link itself are changed.
768
+ * @since v14.5.0, v12.19.0
769
+ * @return Fulfills with `undefined` upon success.
770
+ */
771
+ function lutimes(path: PathLike, atime: TimeLike, mtime: TimeLike): Promise<void>;
772
+ /**
773
+ * Changes the ownership of a file.
774
+ * @since v10.0.0
775
+ * @return Fulfills with `undefined` upon success.
776
+ */
777
+ function chown(path: PathLike, uid: number, gid: number): Promise<void>;
778
+ /**
779
+ * Change the file system timestamps of the object referenced by `path`.
780
+ *
781
+ * The `atime` and `mtime` arguments follow these rules:
782
+ *
783
+ * * Values can be either numbers representing Unix epoch time, `Date`s, or a
784
+ * numeric string like `'123456789.0'`.
785
+ * * If the value can not be converted to a number, or is `NaN`, `Infinity` or`-Infinity`, an `Error` will be thrown.
786
+ * @since v10.0.0
787
+ * @return Fulfills with `undefined` upon success.
788
+ */
789
+ function utimes(path: PathLike, atime: TimeLike, mtime: TimeLike): Promise<void>;
790
+ /**
791
+ * Determines the actual location of `path` using the same semantics as the`fs.realpath.native()` function.
792
+ *
793
+ * Only paths that can be converted to UTF8 strings are supported.
794
+ *
795
+ * The optional `options` argument can be a string specifying an encoding, or an
796
+ * object with an `encoding` property specifying the character encoding to use for
797
+ * the path. If the `encoding` is set to `'buffer'`, the path returned will be
798
+ * passed as a `Buffer` object.
799
+ *
800
+ * On Linux, when Node.js is linked against musl libc, the procfs file system must
801
+ * be mounted on `/proc` in order for this function to work. Glibc does not have
802
+ * this restriction.
803
+ * @since v10.0.0
804
+ * @return Fulfills with the resolved path upon success.
805
+ */
806
+ function realpath(path: PathLike, options?: ObjectEncodingOptions | BufferEncoding | null): Promise<string>;
807
+ /**
808
+ * Asynchronous realpath(3) - return the canonicalized absolute pathname.
809
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
810
+ * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
811
+ */
812
+ function realpath(path: PathLike, options: BufferEncodingOption): Promise<Buffer>;
813
+ /**
814
+ * Asynchronous realpath(3) - return the canonicalized absolute pathname.
815
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
816
+ * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
817
+ */
818
+ function realpath(path: PathLike, options?: ObjectEncodingOptions | BufferEncoding | null): Promise<string | Buffer>;
819
+ /**
820
+ * Creates a unique temporary directory. A unique directory name is generated by
821
+ * appending six random characters to the end of the provided `prefix`. Due to
822
+ * platform inconsistencies, avoid trailing `X` characters in `prefix`. Some
823
+ * platforms, notably the BSDs, can return more than six random characters, and
824
+ * replace trailing `X` characters in `prefix` with random characters.
825
+ *
826
+ * The optional `options` argument can be a string specifying an encoding, or an
827
+ * object with an `encoding` property specifying the character encoding to use.
828
+ *
829
+ * ```js
830
+ * import { mkdtemp } from 'fs/promises';
831
+ *
832
+ * try {
833
+ * await mkdtemp(path.join(os.tmpdir(), 'foo-'));
834
+ * } catch (err) {
835
+ * console.error(err);
836
+ * }
837
+ * ```
838
+ *
839
+ * The `fsPromises.mkdtemp()` method will append the six randomly selected
840
+ * characters directly to the `prefix` string. For instance, given a directory`/tmp`, if the intention is to create a temporary directory _within_`/tmp`, the`prefix` must end with a trailing
841
+ * platform-specific path separator
842
+ * (`require('path').sep`).
843
+ * @since v10.0.0
844
+ * @return Fulfills with a string containing the filesystem path of the newly created temporary directory.
845
+ */
846
+ function mkdtemp(prefix: string, options?: ObjectEncodingOptions | BufferEncoding | null): Promise<string>;
847
+ /**
848
+ * Asynchronously creates a unique temporary directory.
849
+ * Generates six random characters to be appended behind a required `prefix` to create a unique temporary directory.
850
+ * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
851
+ */
852
+ function mkdtemp(prefix: string, options: BufferEncodingOption): Promise<Buffer>;
853
+ /**
854
+ * Asynchronously creates a unique temporary directory.
855
+ * Generates six random characters to be appended behind a required `prefix` to create a unique temporary directory.
856
+ * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
857
+ */
858
+ function mkdtemp(prefix: string, options?: ObjectEncodingOptions | BufferEncoding | null): Promise<string | Buffer>;
859
+ /**
860
+ * Asynchronously writes data to a file, replacing the file if it already exists.`data` can be a string, a buffer, an
861
+ * [AsyncIterable](https://tc39.github.io/ecma262/#sec-asynciterable-interface) or
862
+ * [Iterable](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterable_protocol) object.
863
+ *
864
+ * The `encoding` option is ignored if `data` is a buffer.
865
+ *
866
+ * If `options` is a string, then it specifies the encoding.
867
+ *
868
+ * The `mode` option only affects the newly created file. See `fs.open()` for more details.
869
+ *
870
+ * Any specified `FileHandle` has to support writing.
871
+ *
872
+ * It is unsafe to use `fsPromises.writeFile()` multiple times on the same file
873
+ * without waiting for the promise to be settled.
874
+ *
875
+ * Similarly to `fsPromises.readFile` \- `fsPromises.writeFile` is a convenience
876
+ * method that performs multiple `write` calls internally to write the buffer
877
+ * passed to it. For performance sensitive code consider using `fs.createWriteStream()` or `filehandle.createWriteStream()`.
878
+ *
879
+ * It is possible to use an `AbortSignal` to cancel an `fsPromises.writeFile()`.
880
+ * Cancelation is "best effort", and some amount of data is likely still
881
+ * to be written.
882
+ *
883
+ * ```js
884
+ * import { writeFile } from 'fs/promises';
885
+ * import { Buffer } from 'buffer';
886
+ *
887
+ * try {
888
+ * const controller = new AbortController();
889
+ * const { signal } = controller;
890
+ * const data = new Uint8Array(Buffer.from('Hello Node.js'));
891
+ * const promise = writeFile('message.txt', data, { signal });
892
+ *
893
+ * // Abort the request before the promise settles.
894
+ * controller.abort();
895
+ *
896
+ * await promise;
897
+ * } catch (err) {
898
+ * // When a request is aborted - err is an AbortError
899
+ * console.error(err);
900
+ * }
901
+ * ```
902
+ *
903
+ * Aborting an ongoing request does not abort individual operating
904
+ * system requests but rather the internal buffering `fs.writeFile` performs.
905
+ * @since v10.0.0
906
+ * @param file filename or `FileHandle`
907
+ * @return Fulfills with `undefined` upon success.
908
+ */
909
+ function writeFile(
910
+ file: PathLike | FileHandle,
911
+ data: string | NodeJS.ArrayBufferView | Iterable<string | NodeJS.ArrayBufferView> | AsyncIterable<string | NodeJS.ArrayBufferView> | Stream,
912
+ options?:
913
+ | (ObjectEncodingOptions & {
914
+ mode?: Mode | undefined;
915
+ flag?: OpenMode | undefined;
916
+ } & Abortable)
917
+ | BufferEncoding
918
+ | null
919
+ ): Promise<void>;
920
+ /**
921
+ * Asynchronously append data to a file, creating the file if it does not yet
922
+ * exist. `data` can be a string or a `Buffer`.
923
+ *
924
+ * If `options` is a string, then it specifies the `encoding`.
925
+ *
926
+ * The `mode` option only affects the newly created file. See `fs.open()` for more details.
927
+ *
928
+ * The `path` may be specified as a `FileHandle` that has been opened
929
+ * for appending (using `fsPromises.open()`).
930
+ * @since v10.0.0
931
+ * @param path filename or {FileHandle}
932
+ * @return Fulfills with `undefined` upon success.
933
+ */
934
+ function appendFile(path: PathLike | FileHandle, data: string | Uint8Array, options?: (ObjectEncodingOptions & FlagAndOpenMode) | BufferEncoding | null): Promise<void>;
935
+ /**
936
+ * Asynchronously reads the entire contents of a file.
937
+ *
938
+ * If no encoding is specified (using `options.encoding`), the data is returned
939
+ * as a `Buffer` object. Otherwise, the data will be a string.
940
+ *
941
+ * If `options` is a string, then it specifies the encoding.
942
+ *
943
+ * When the `path` is a directory, the behavior of `fsPromises.readFile()` is
944
+ * platform-specific. On macOS, Linux, and Windows, the promise will be rejected
945
+ * with an error. On FreeBSD, a representation of the directory's contents will be
946
+ * returned.
947
+ *
948
+ * It is possible to abort an ongoing `readFile` using an `AbortSignal`. If a
949
+ * request is aborted the promise returned is rejected with an `AbortError`:
950
+ *
951
+ * ```js
952
+ * import { readFile } from 'fs/promises';
953
+ *
954
+ * try {
955
+ * const controller = new AbortController();
956
+ * const { signal } = controller;
957
+ * const promise = readFile(fileName, { signal });
958
+ *
959
+ * // Abort the request before the promise settles.
960
+ * controller.abort();
961
+ *
962
+ * await promise;
963
+ * } catch (err) {
964
+ * // When a request is aborted - err is an AbortError
965
+ * console.error(err);
966
+ * }
967
+ * ```
968
+ *
969
+ * Aborting an ongoing request does not abort individual operating
970
+ * system requests but rather the internal buffering `fs.readFile` performs.
971
+ *
972
+ * Any specified `FileHandle` has to support reading.
973
+ * @since v10.0.0
974
+ * @param path filename or `FileHandle`
975
+ * @return Fulfills with the contents of the file.
976
+ */
977
+ function readFile(
978
+ path: PathLike | FileHandle,
979
+ options?:
980
+ | ({
981
+ encoding?: null | undefined;
982
+ flag?: OpenMode | undefined;
983
+ } & Abortable)
984
+ | null
985
+ ): Promise<Buffer>;
986
+ /**
987
+ * Asynchronously reads the entire contents of a file.
988
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
989
+ * If a `FileHandle` is provided, the underlying file will _not_ be closed automatically.
990
+ * @param options An object that may contain an optional flag.
991
+ * If a flag is not provided, it defaults to `'r'`.
992
+ */
993
+ function readFile(
994
+ path: PathLike | FileHandle,
995
+ options:
996
+ | ({
997
+ encoding: BufferEncoding;
998
+ flag?: OpenMode | undefined;
999
+ } & Abortable)
1000
+ | BufferEncoding
1001
+ ): Promise<string>;
1002
+ /**
1003
+ * Asynchronously reads the entire contents of a file.
1004
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1005
+ * If a `FileHandle` is provided, the underlying file will _not_ be closed automatically.
1006
+ * @param options An object that may contain an optional flag.
1007
+ * If a flag is not provided, it defaults to `'r'`.
1008
+ */
1009
+ function readFile(
1010
+ path: PathLike | FileHandle,
1011
+ options?:
1012
+ | (ObjectEncodingOptions &
1013
+ Abortable & {
1014
+ flag?: OpenMode | undefined;
1015
+ })
1016
+ | BufferEncoding
1017
+ | null
1018
+ ): Promise<string | Buffer>;
1019
+ /**
1020
+ * Asynchronously open a directory for iterative scanning. See the POSIX [`opendir(3)`](http://man7.org/linux/man-pages/man3/opendir.3.html) documentation for more detail.
1021
+ *
1022
+ * Creates an `fs.Dir`, which contains all further functions for reading from
1023
+ * and cleaning up the directory.
1024
+ *
1025
+ * The `encoding` option sets the encoding for the `path` while opening the
1026
+ * directory and subsequent read operations.
1027
+ *
1028
+ * Example using async iteration:
1029
+ *
1030
+ * ```js
1031
+ * import { opendir } from 'fs/promises';
1032
+ *
1033
+ * try {
1034
+ * const dir = await opendir('./');
1035
+ * for await (const dirent of dir)
1036
+ * console.log(dirent.name);
1037
+ * } catch (err) {
1038
+ * console.error(err);
1039
+ * }
1040
+ * ```
1041
+ *
1042
+ * When using the async iterator, the `fs.Dir` object will be automatically
1043
+ * closed after the iterator exits.
1044
+ * @since v12.12.0
1045
+ * @return Fulfills with an {fs.Dir}.
1046
+ */
1047
+ function opendir(path: PathLike, options?: OpenDirOptions): Promise<Dir>;
1048
+ /**
1049
+ * Returns an async iterator that watches for changes on `filename`, where `filename`is either a file or a directory.
1050
+ *
1051
+ * ```js
1052
+ * const { watch } = require('fs/promises');
1053
+ *
1054
+ * const ac = new AbortController();
1055
+ * const { signal } = ac;
1056
+ * setTimeout(() => ac.abort(), 10000);
1057
+ *
1058
+ * (async () => {
1059
+ * try {
1060
+ * const watcher = watch(__filename, { signal });
1061
+ * for await (const event of watcher)
1062
+ * console.log(event);
1063
+ * } catch (err) {
1064
+ * if (err.name === 'AbortError')
1065
+ * return;
1066
+ * throw err;
1067
+ * }
1068
+ * })();
1069
+ * ```
1070
+ *
1071
+ * On most platforms, `'rename'` is emitted whenever a filename appears or
1072
+ * disappears in the directory.
1073
+ *
1074
+ * All the `caveats` for `fs.watch()` also apply to `fsPromises.watch()`.
1075
+ * @since v15.9.0, v14.18.0
1076
+ * @return of objects with the properties:
1077
+ */
1078
+ function watch(
1079
+ filename: PathLike,
1080
+ options:
1081
+ | (WatchOptions & {
1082
+ encoding: 'buffer';
1083
+ })
1084
+ | 'buffer'
1085
+ ): AsyncIterable<FileChangeInfo<Buffer>>;
1086
+ /**
1087
+ * Watch for changes on `filename`, where `filename` is either a file or a directory, returning an `FSWatcher`.
1088
+ * @param filename A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
1089
+ * @param options Either the encoding for the filename provided to the listener, or an object optionally specifying encoding, persistent, and recursive options.
1090
+ * If `encoding` is not supplied, the default of `'utf8'` is used.
1091
+ * If `persistent` is not supplied, the default of `true` is used.
1092
+ * If `recursive` is not supplied, the default of `false` is used.
1093
+ */
1094
+ function watch(filename: PathLike, options?: WatchOptions | BufferEncoding): AsyncIterable<FileChangeInfo<string>>;
1095
+ /**
1096
+ * Watch for changes on `filename`, where `filename` is either a file or a directory, returning an `FSWatcher`.
1097
+ * @param filename A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
1098
+ * @param options Either the encoding for the filename provided to the listener, or an object optionally specifying encoding, persistent, and recursive options.
1099
+ * If `encoding` is not supplied, the default of `'utf8'` is used.
1100
+ * If `persistent` is not supplied, the default of `true` is used.
1101
+ * If `recursive` is not supplied, the default of `false` is used.
1102
+ */
1103
+ function watch(filename: PathLike, options: WatchOptions | string): AsyncIterable<FileChangeInfo<string>> | AsyncIterable<FileChangeInfo<Buffer>>;
1104
+ /**
1105
+ * Asynchronously copies the entire directory structure from `src` to `dest`,
1106
+ * including subdirectories and files.
1107
+ *
1108
+ * When copying a directory to another directory, globs are not supported and
1109
+ * behavior is similar to `cp dir1/ dir2/`.
1110
+ * @since v16.7.0
1111
+ * @experimental
1112
+ * @param src source path to copy.
1113
+ * @param dest destination path to copy to.
1114
+ * @return Fulfills with `undefined` upon success.
1115
+ */
1116
+ function cp(source: string | URL, destination: string | URL, opts?: CopyOptions): Promise<void>;
1117
+ }
1118
+ declare module 'node:fs/promises' {
1119
+ export * from 'fs/promises';
1120
+ }