@types/node 18.19.22 → 18.19.24

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