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