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