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