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