@types/node 16.18.87 → 16.18.88

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