@aligent/cdk-prerender-proxy 0.2.4-beta1 → 0.2.5-beta

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