1 | declare module 'fs/promises' {
|
2 | import { Abortable } from 'events';
|
3 | import { Stream } from 'stream';
|
4 | import {
|
5 | Stats,
|
6 | BigIntStats,
|
7 | StatOptions,
|
8 | WriteVResult,
|
9 | ReadVResult,
|
10 | PathLike,
|
11 | RmDirOptions,
|
12 | RmOptions,
|
13 | MakeDirectoryOptions,
|
14 | Dirent,
|
15 | OpenDirOptions,
|
16 | Dir,
|
17 | ObjectEncodingOptions,
|
18 | BufferEncodingOption,
|
19 | OpenMode,
|
20 | Mode,
|
21 | WatchOptions,
|
22 | } from 'fs';
|
23 |
|
24 | interface FlagAndOpenMode {
|
25 | mode?: Mode | undefined;
|
26 | flag?: OpenMode | undefined;
|
27 | }
|
28 |
|
29 | interface FileReadResult<T extends ArrayBufferView> {
|
30 | bytesRead: number;
|
31 | buffer: T;
|
32 | }
|
33 |
|
34 | interface FileReadOptions<T extends ArrayBufferView = Buffer> {
|
35 | /**
|
36 | * @default `Buffer.alloc(0xffff)`
|
37 | */
|
38 | buffer?: T;
|
39 | /**
|
40 | * @default 0
|
41 | */
|
42 | offset?: number | null;
|
43 | /**
|
44 | * @default `buffer.byteLength`
|
45 | */
|
46 | length?: number | null;
|
47 | position?: number | null;
|
48 | }
|
49 |
|
50 | // TODO: Add `EventEmitter` close
|
51 | interface FileHandle {
|
52 | /**
|
53 | * Gets the file descriptor for this file handle.
|
54 | */
|
55 | readonly fd: number;
|
56 |
|
57 | /**
|
58 | * Asynchronously append data to a file, creating the file if it does not exist. The underlying file will _not_ be closed automatically.
|
59 | * The `FileHandle` must have been opened for appending.
|
60 | * @param data The data to write. If something other than a `Buffer` or `Uint8Array` is provided, the value is coerced to a string.
|
61 | * @param options Either the encoding for the file, or an object optionally specifying the encoding, file mode, and flag.
|
62 | * If `encoding` is not supplied, the default of `'utf8'` is used.
|
63 | * If `mode` is not supplied, the default of `0o666` is used.
|
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.
|
66 | */
|
67 | appendFile(data: string | Uint8Array, options?: ObjectEncodingOptions & FlagAndOpenMode | BufferEncoding | null): Promise<void>;
|
68 |
|
69 | /**
|
70 | * Asynchronous fchown(2) - Change ownership of a file.
|
71 | */
|
72 | chown(uid: number, gid: number): Promise<void>;
|
73 |
|
74 | /**
|
75 | * Asynchronous fchmod(2) - Change permissions of a file.
|
76 | * @param mode A file mode. If a string is passed, it is parsed as an octal integer.
|
77 | */
|
78 | chmod(mode: Mode): Promise<void>;
|
79 |
|
80 | /**
|
81 | * Asynchronous fdatasync(2) - synchronize a file's in-core state with storage device.
|
82 | */
|
83 | datasync(): Promise<void>;
|
84 |
|
85 | /**
|
86 | * Asynchronous fsync(2) - synchronize a file's in-core state with the underlying storage device.
|
87 | */
|
88 | sync(): Promise<void>;
|
89 |
|
90 | /**
|
91 | * Asynchronously reads data from the file.
|
92 | * The `FileHandle` must have been opened for reading.
|
93 | * @param buffer The buffer that the data will be written to.
|
94 | * @param offset The offset in the buffer at which to start writing.
|
95 | * @param length The number of bytes to read.
|
96 | * @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.
|
97 | */
|
98 | read<T extends ArrayBufferView>(buffer: T, offset?: number | null, length?: number | null, position?: number | null): Promise<FileReadResult<T>>;
|
99 | read<T extends ArrayBufferView = Buffer>(options?: FileReadOptions<T>): Promise<FileReadResult<T>>;
|
100 | /**
|
101 | * Asynchronously reads the entire contents of a file. The underlying file will _not_ be closed automatically.
|
102 | * The `FileHandle` must have been opened for reading.
|
103 | * @param options An object that may contain an optional flag.
|
104 | * If a flag is not provided, it defaults to `'r'`.
|
105 | */
|
106 | readFile(options?: { encoding?: null | undefined, flag?: OpenMode | undefined } | null): Promise<Buffer>;
|
107 |
|
108 | /**
|
109 | * Asynchronously reads the entire contents of a file. The underlying file will _not_ be closed automatically.
|
110 | * The `FileHandle` must have been opened for reading.
|
111 | * @param options An object that may contain an optional flag.
|
112 | * If a flag is not provided, it defaults to `'r'`.
|
113 | */
|
114 | readFile(options: { encoding: BufferEncoding, flag?: OpenMode | undefined } | BufferEncoding): Promise<string>;
|
115 |
|
116 | /**
|
117 | * Asynchronously reads the entire contents of a file. The underlying file will _not_ be closed automatically.
|
118 | * The `FileHandle` must have been opened for reading.
|
119 | * @param options An object that may contain an optional flag.
|
120 | * If a flag is not provided, it defaults to `'r'`.
|
121 | */
|
122 | readFile(options?: ObjectEncodingOptions & { flag?: OpenMode | undefined } | BufferEncoding | null): Promise<string | Buffer>;
|
123 |
|
124 | /**
|
125 | * Asynchronous fstat(2) - Get file status.
|
126 | */
|
127 | stat(opts?: StatOptions & { bigint?: false | undefined }): Promise<Stats>;
|
128 | stat(opts: StatOptions & { bigint: true }): Promise<BigIntStats>;
|
129 | stat(opts?: StatOptions): Promise<Stats | BigIntStats>;
|
130 |
|
131 | /**
|
132 | * Asynchronous ftruncate(2) - Truncate a file to a specified length.
|
133 | * @param len If not specified, defaults to `0`.
|
134 | */
|
135 | truncate(len?: number): Promise<void>;
|
136 |
|
137 | /**
|
138 | * Asynchronously change file timestamps of the file.
|
139 | * @param atime The last access time. If a string is provided, it will be coerced to number.
|
140 | * @param mtime The last modified time. If a string is provided, it will be coerced to number.
|
141 | */
|
142 | 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 | /**
|
166 | * Asynchronously writes data to a file, replacing the file if it already exists. The underlying file will _not_ be closed automatically.
|
167 | * The `FileHandle` must have been opened for writing.
|
168 | * It is unsafe to call `writeFile()` multiple times on the same file without waiting for the `Promise` to be resolved (or rejected).
|
169 | * @param data The data to write. If something other than a `Buffer` or `Uint8Array` is provided, the value is coerced to a string.
|
170 | * @param options Either the encoding for the file, or an object optionally specifying the encoding, file mode, and flag.
|
171 | * If `encoding` is not supplied, the default of `'utf8'` is used.
|
172 | * If `mode` is not supplied, the default of `0o666` is used.
|
173 | * If `mode` is a string, it is parsed as an octal integer.
|
174 | * If `flag` is not supplied, the default of `'w'` is used.
|
175 | */
|
176 | writeFile(data: string | Uint8Array, options?: ObjectEncodingOptions & FlagAndOpenMode & Abortable | BufferEncoding | null): Promise<void>;
|
177 |
|
178 | /**
|
179 | * See `fs.writev` promisified version.
|
180 | */
|
181 | writev(buffers: ReadonlyArray<NodeJS.ArrayBufferView>, position?: number): Promise<WriteVResult>;
|
182 |
|
183 | /**
|
184 | * See `fs.readv` promisified version.
|
185 | */
|
186 | readv(buffers: ReadonlyArray<NodeJS.ArrayBufferView>, position?: number): Promise<ReadVResult>;
|
187 |
|
188 | /**
|
189 | * Asynchronous close(2) - close a `FileHandle`.
|
190 | */
|
191 | close(): Promise<void>;
|
192 | }
|
193 |
|
194 | /**
|
195 | * Asynchronously tests a user's permissions for the file specified by path.
|
196 | * @param path A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
|
197 | * URL support is _experimental_.
|
198 | */
|
199 | function access(path: PathLike, mode?: number): Promise<void>;
|
200 |
|
201 | /**
|
202 | * Asynchronously copies `src` to `dest`. By default, `dest` is overwritten if it already exists.
|
203 | * Node.js makes no guarantees about the atomicity of the copy operation.
|
204 | * If an error occurs after the destination file has been opened for writing, Node.js will attempt
|
205 | * to remove the destination.
|
206 | * @param src A path to the source file.
|
207 | * @param dest A path to the destination file.
|
208 | * @param flags An optional integer that specifies the behavior of the copy operation. The only
|
209 | * supported flag is `fs.constants.COPYFILE_EXCL`, which causes the copy operation to fail if
|
210 | * `dest` already exists.
|
211 | */
|
212 | function copyFile(src: PathLike, dest: PathLike, flags?: number): Promise<void>;
|
213 |
|
214 | /**
|
215 | * Asynchronous open(2) - open and possibly create a file.
|
216 | * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
217 | * @param mode A file mode. If a string is passed, it is parsed as an octal integer. If not
|
218 | * supplied, defaults to `0o666`.
|
219 | */
|
220 | function open(path: PathLike, flags: string | number, mode?: Mode): Promise<FileHandle>;
|
221 |
|
222 | /**
|
223 | * Asynchronous rename(2) - Change the name or location of a file or directory.
|
224 | * @param oldPath A path to a file. If a URL is provided, it must use the `file:` protocol.
|
225 | * URL support is _experimental_.
|
226 | * @param newPath A path to a file. If a URL is provided, it must use the `file:` protocol.
|
227 | * URL support is _experimental_.
|
228 | */
|
229 | function rename(oldPath: PathLike, newPath: PathLike): Promise<void>;
|
230 |
|
231 | /**
|
232 | * Asynchronous truncate(2) - Truncate a file to a specified length.
|
233 | * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
234 | * @param len If not specified, defaults to `0`.
|
235 | */
|
236 | function truncate(path: PathLike, len?: number): Promise<void>;
|
237 |
|
238 | /**
|
239 | * Asynchronous rmdir(2) - delete a directory.
|
240 | * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
241 | */
|
242 | function rmdir(path: PathLike, options?: RmDirOptions): Promise<void>;
|
243 |
|
244 | /**
|
245 | * Asynchronously removes files and directories (modeled on the standard POSIX `rm` utility).
|
246 | */
|
247 | function rm(path: PathLike, options?: RmOptions): Promise<void>;
|
248 |
|
249 | /**
|
250 | * Asynchronous mkdir(2) - create a directory.
|
251 | * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
252 | * @param options Either the file mode, or an object optionally specifying the file mode and whether parent folders
|
253 | * should be created. If a string is passed, it is parsed as an octal integer. If not specified, defaults to `0o777`.
|
254 | */
|
255 | function mkdir(path: PathLike, options: MakeDirectoryOptions & { recursive: true; }): Promise<string | undefined>;
|
256 |
|
257 | /**
|
258 | * Asynchronous mkdir(2) - create a directory.
|
259 | * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
260 | * @param options Either the file mode, or an object optionally specifying the file mode and whether parent folders
|
261 | * should be created. If a string is passed, it is parsed as an octal integer. If not specified, defaults to `0o777`.
|
262 | */
|
263 | function mkdir(path: PathLike, options?: Mode | (MakeDirectoryOptions & { recursive?: false | undefined; }) | null): Promise<void>;
|
264 |
|
265 | /**
|
266 | * Asynchronous mkdir(2) - create a directory.
|
267 | * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
268 | * @param options Either the file mode, or an object optionally specifying the file mode and whether parent folders
|
269 | * should be created. If a string is passed, it is parsed as an octal integer. If not specified, defaults to `0o777`.
|
270 | */
|
271 | function mkdir(path: PathLike, options?: Mode | MakeDirectoryOptions | null): Promise<string | undefined>;
|
272 |
|
273 | /**
|
274 | * Asynchronous readdir(3) - read a directory.
|
275 | * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
276 | * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
|
277 | */
|
278 | function readdir(path: PathLike, options?: ObjectEncodingOptions & { withFileTypes?: false | undefined } | BufferEncoding | null): Promise<string[]>;
|
279 |
|
280 | /**
|
281 | * Asynchronous readdir(3) - read a directory.
|
282 | * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
283 | * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
|
284 | */
|
285 | function readdir(path: PathLike, options: { encoding: "buffer"; withFileTypes?: false | undefined } | "buffer"): Promise<Buffer[]>;
|
286 |
|
287 | /**
|
288 | * Asynchronous readdir(3) - read a directory.
|
289 | * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
290 | * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
|
291 | */
|
292 | function readdir(path: PathLike, options?: ObjectEncodingOptions & { withFileTypes?: false | undefined } | BufferEncoding | null): Promise<string[] | Buffer[]>;
|
293 |
|
294 | /**
|
295 | * Asynchronous readdir(3) - read a directory.
|
296 | * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
297 | * @param options If called with `withFileTypes: true` the result data will be an array of Dirent.
|
298 | */
|
299 | function readdir(path: PathLike, options: ObjectEncodingOptions & { withFileTypes: true }): Promise<Dirent[]>;
|
300 |
|
301 | /**
|
302 | * Asynchronous readlink(2) - read value of a symbolic link.
|
303 | * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
304 | * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
|
305 | */
|
306 | function readlink(path: PathLike, options?: ObjectEncodingOptions | BufferEncoding | null): Promise<string>;
|
307 |
|
308 | /**
|
309 | * Asynchronous readlink(2) - read value of a symbolic link.
|
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.
|
312 | */
|
313 | function readlink(path: PathLike, options: BufferEncodingOption): Promise<Buffer>;
|
314 |
|
315 | /**
|
316 | * Asynchronous readlink(2) - read value of a symbolic link.
|
317 | * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
318 | * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
|
319 | */
|
320 | function readlink(path: PathLike, options?: ObjectEncodingOptions | string | null): Promise<string | Buffer>;
|
321 |
|
322 | /**
|
323 | * Asynchronous symlink(2) - Create a new symbolic link to an existing file.
|
324 | * @param target A path to an existing file. If a URL is provided, it must use the `file:` protocol.
|
325 | * @param path A path to the new symlink. If a URL is provided, it must use the `file:` protocol.
|
326 | * @param type May be set to `'dir'`, `'file'`, or `'junction'` (default is `'file'`) and is only available on Windows (ignored on other platforms).
|
327 | * When using `'junction'`, the `target` argument will automatically be normalized to an absolute path.
|
328 | */
|
329 | function symlink(target: PathLike, path: PathLike, type?: string | null): Promise<void>;
|
330 |
|
331 | /**
|
332 | * Asynchronous lstat(2) - Get file status. Does not dereference symbolic links.
|
333 | * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
334 | */
|
335 | function lstat(path: PathLike, opts?: StatOptions & { bigint?: false | undefined }): Promise<Stats>;
|
336 | function lstat(path: PathLike, opts: StatOptions & { bigint: true }): Promise<BigIntStats>;
|
337 | function lstat(path: PathLike, opts?: StatOptions): Promise<Stats | BigIntStats>;
|
338 |
|
339 | /**
|
340 | * Asynchronous stat(2) - Get file status.
|
341 | * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
342 | */
|
343 | function stat(path: PathLike, opts?: StatOptions & { bigint?: false | undefined }): Promise<Stats>;
|
344 | function stat(path: PathLike, opts: StatOptions & { bigint: true }): Promise<BigIntStats>;
|
345 | function stat(path: PathLike, opts?: StatOptions): Promise<Stats | BigIntStats>;
|
346 |
|
347 | /**
|
348 | * Asynchronous link(2) - Create a new link (also known as a hard link) to an existing file.
|
349 | * @param existingPath A path to a file. If a URL is provided, it must use the `file:` protocol.
|
350 | * @param newPath A path to a file. If a URL is provided, it must use the `file:` protocol.
|
351 | */
|
352 | function link(existingPath: PathLike, newPath: PathLike): Promise<void>;
|
353 |
|
354 | /**
|
355 | * Asynchronous unlink(2) - delete a name and possibly the file it refers to.
|
356 | * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
357 | */
|
358 | function unlink(path: PathLike): Promise<void>;
|
359 |
|
360 | /**
|
361 | * Asynchronous chmod(2) - Change permissions of a file.
|
362 | * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
363 | * @param mode A file mode. If a string is passed, it is parsed as an octal integer.
|
364 | */
|
365 | function chmod(path: PathLike, mode: Mode): Promise<void>;
|
366 |
|
367 | /**
|
368 | * Asynchronous lchmod(2) - Change permissions of a file. Does not dereference symbolic links.
|
369 | * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
370 | * @param mode A file mode. If a string is passed, it is parsed as an octal integer.
|
371 | */
|
372 | function lchmod(path: PathLike, mode: Mode): Promise<void>;
|
373 |
|
374 | /**
|
375 | * Asynchronous lchown(2) - Change ownership of a file. Does not dereference symbolic links.
|
376 | * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
377 | */
|
378 | function lchown(path: PathLike, uid: number, gid: number): Promise<void>;
|
379 |
|
380 | /**
|
381 | * Changes the access and modification times of a file in the same way as `fsPromises.utimes()`,
|
382 | * with the difference that if the path refers to a symbolic link, then the link is not
|
383 | * dereferenced: instead, the timestamps of the symbolic link itself are changed.
|
384 | * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
385 | * @param atime The last access time. If a string is provided, it will be coerced to number.
|
386 | * @param mtime The last modified time. If a string is provided, it will be coerced to number.
|
387 | */
|
388 | function lutimes(path: PathLike, atime: string | number | Date, mtime: string | number | Date): Promise<void>;
|
389 |
|
390 | /**
|
391 | * Asynchronous chown(2) - Change ownership of a file.
|
392 | * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
393 | */
|
394 | function chown(path: PathLike, uid: number, gid: number): Promise<void>;
|
395 |
|
396 | /**
|
397 | * Asynchronously change file timestamps of the file referenced by the supplied path.
|
398 | * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
399 | * @param atime The last access time. If a string is provided, it will be coerced to number.
|
400 | * @param mtime The last modified time. If a string is provided, it will be coerced to number.
|
401 | */
|
402 | function utimes(path: PathLike, atime: string | number | Date, mtime: string | number | Date): Promise<void>;
|
403 |
|
404 | /**
|
405 | * Asynchronous realpath(3) - return the canonicalized absolute pathname.
|
406 | * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
407 | * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
|
408 | */
|
409 | function realpath(path: PathLike, options?: ObjectEncodingOptions | BufferEncoding | null): Promise<string>;
|
410 |
|
411 | /**
|
412 | * Asynchronous realpath(3) - return the canonicalized absolute pathname.
|
413 | * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
414 | * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
|
415 | */
|
416 | function realpath(path: PathLike, options: BufferEncodingOption): Promise<Buffer>;
|
417 |
|
418 | /**
|
419 | * Asynchronous realpath(3) - return the canonicalized absolute pathname.
|
420 | * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
421 | * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
|
422 | */
|
423 | function realpath(path: PathLike, options?: ObjectEncodingOptions | BufferEncoding | null): Promise<string | Buffer>;
|
424 |
|
425 | /**
|
426 | * Asynchronously creates a unique temporary directory.
|
427 | * Generates six random characters to be appended behind a required `prefix` to create a unique temporary directory.
|
428 | * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
|
429 | */
|
430 | function mkdtemp(prefix: string, options?: ObjectEncodingOptions | BufferEncoding | null): Promise<string>;
|
431 |
|
432 | /**
|
433 | * Asynchronously creates a unique temporary directory.
|
434 | * Generates six random characters to be appended behind a required `prefix` to create a unique temporary directory.
|
435 | * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
|
436 | */
|
437 | function mkdtemp(prefix: string, options: BufferEncodingOption): Promise<Buffer>;
|
438 |
|
439 | /**
|
440 | * Asynchronously creates a unique temporary directory.
|
441 | * Generates six random characters to be appended behind a required `prefix` to create a unique temporary directory.
|
442 | * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
|
443 | */
|
444 | function mkdtemp(prefix: string, options?: ObjectEncodingOptions | BufferEncoding | null): Promise<string | Buffer>;
|
445 |
|
446 | /**
|
447 | * Asynchronously writes data to a file, replacing the file if it already exists.
|
448 | * It is unsafe to call `fsPromises.writeFile()` multiple times on the same file without waiting for the `Promise` to be resolved (or rejected).
|
449 | * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
450 | * URL support is _experimental_.
|
451 | * If a `FileHandle` is provided, the underlying file will _not_ be closed automatically.
|
452 | * @param data The data to write. If something other than a `Buffer` or `Uint8Array` is provided, the value is coerced to a string.
|
453 | * @param options Either the encoding for the file, or an object optionally specifying the encoding, file mode, and flag.
|
454 | * If `encoding` is not supplied, the default of `'utf8'` is used.
|
455 | * If `mode` is not supplied, the default of `0o666` is used.
|
456 | * If `mode` is a string, it is parsed as an octal integer.
|
457 | * If `flag` is not supplied, the default of `'w'` is used.
|
458 | */
|
459 | function writeFile(
|
460 | path: PathLike | FileHandle,
|
461 | data: string | NodeJS.ArrayBufferView | Iterable<string | NodeJS.ArrayBufferView> | AsyncIterable<string | NodeJS.ArrayBufferView> | Stream,
|
462 | options?: ObjectEncodingOptions & { mode?: Mode | undefined, flag?: OpenMode | undefined } & Abortable | BufferEncoding | null
|
463 | ): Promise<void>;
|
464 |
|
465 | /**
|
466 | * Asynchronously append data to a file, creating the file if it does not exist.
|
467 | * @param file A path to a file. If a URL is provided, it must use the `file:` protocol.
|
468 | * URL support is _experimental_.
|
469 | * If a `FileHandle` is provided, the underlying file will _not_ be closed automatically.
|
470 | * @param data The data to write. If something other than a `Buffer` or `Uint8Array` is provided, the value is coerced to a string.
|
471 | * @param options Either the encoding for the file, or an object optionally specifying the encoding, file mode, and flag.
|
472 | * If `encoding` is not supplied, the default of `'utf8'` is used.
|
473 | * If `mode` is not supplied, the default of `0o666` is used.
|
474 | * If `mode` is a string, it is parsed as an octal integer.
|
475 | * If `flag` is not supplied, the default of `'a'` is used.
|
476 | */
|
477 | function appendFile(
|
478 | path: PathLike | FileHandle,
|
479 | data: string | Uint8Array,
|
480 | options?: ObjectEncodingOptions & FlagAndOpenMode | BufferEncoding | null,
|
481 | ): Promise<void>;
|
482 |
|
483 | /**
|
484 | * Asynchronously reads the entire contents of a file.
|
485 | * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
486 | * If a `FileHandle` is provided, the underlying file will _not_ be closed automatically.
|
487 | * @param options An object that may contain an optional flag.
|
488 | * If a flag is not provided, it defaults to `'r'`.
|
489 | */
|
490 | function readFile(path: PathLike | FileHandle, options?: { encoding?: null | undefined, flag?: OpenMode | undefined } & Abortable | null): Promise<Buffer>;
|
491 |
|
492 | /**
|
493 | * Asynchronously reads the entire contents of a file.
|
494 | * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
495 | * If a `FileHandle` is provided, the underlying file will _not_ be closed automatically.
|
496 | * @param options An object that may contain an optional flag.
|
497 | * If a flag is not provided, it defaults to `'r'`.
|
498 | */
|
499 | function readFile(path: PathLike | FileHandle, options: { encoding: BufferEncoding, flag?: OpenMode | undefined } & Abortable | BufferEncoding): Promise<string>;
|
500 |
|
501 | /**
|
502 | * Asynchronously reads the entire contents of a file.
|
503 | * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
504 | * If a `FileHandle` is provided, the underlying file will _not_ be closed automatically.
|
505 | * @param options An object that may contain an optional flag.
|
506 | * If a flag is not provided, it defaults to `'r'`.
|
507 | */
|
508 | function readFile(path: PathLike | FileHandle, options?: ObjectEncodingOptions & Abortable & { flag?: OpenMode | undefined } | BufferEncoding | null): Promise<string | Buffer>;
|
509 |
|
510 | function opendir(path: string, options?: OpenDirOptions): Promise<Dir>;
|
511 |
|
512 | /**
|
513 | * Watch for changes on `filename`, where `filename` is either a file or a directory, returning an `FSWatcher`.
|
514 | * @param filename A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
|
515 | * @param options Either the encoding for the filename provided to the listener, or an object optionally specifying encoding, persistent, and recursive options.
|
516 | * If `encoding` is not supplied, the default of `'utf8'` is used.
|
517 | * If `persistent` is not supplied, the default of `true` is used.
|
518 | * If `recursive` is not supplied, the default of `false` is used.
|
519 | */
|
520 | function watch(filename: PathLike, options: WatchOptions & { encoding: "buffer" } | "buffer"): AsyncIterable<Buffer>;
|
521 |
|
522 | /**
|
523 | * Watch for changes on `filename`, where `filename` is either a file or a directory, returning an `FSWatcher`.
|
524 | * @param filename A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
|
525 | * @param options Either the encoding for the filename provided to the listener, or an object optionally specifying encoding, persistent, and recursive options.
|
526 | * If `encoding` is not supplied, the default of `'utf8'` is used.
|
527 | * If `persistent` is not supplied, the default of `true` is used.
|
528 | * If `recursive` is not supplied, the default of `false` is used.
|
529 | */
|
530 | function watch(
|
531 | filename: PathLike,
|
532 | options?: WatchOptions | BufferEncoding
|
533 | ): AsyncIterable<string>;
|
534 |
|
535 | /**
|
536 | * Watch for changes on `filename`, where `filename` is either a file or a directory, returning an `FSWatcher`.
|
537 | * @param filename A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
|
538 | * @param options Either the encoding for the filename provided to the listener, or an object optionally specifying encoding, persistent, and recursive options.
|
539 | * If `encoding` is not supplied, the default of `'utf8'` is used.
|
540 | * If `persistent` is not supplied, the default of `true` is used.
|
541 | * If `recursive` is not supplied, the default of `false` is used.
|
542 | */
|
543 | function watch(filename: PathLike, options: WatchOptions | string): AsyncIterable<string> | AsyncIterable<Buffer>;
|
544 | }
|
545 |
|
546 | declare module 'node:fs/promises' {
|
547 | export * from 'fs/promises';
|
548 | }
|