@aligent/cdk-prerender-proxy 0.2.4 → 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/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
|
@@ -1,27 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `fs` module enables interacting with the file system in a
|
|
3
|
+
* way modeled on standard POSIX functions.
|
|
4
|
+
*
|
|
5
|
+
* To use the promise-based APIs:
|
|
6
|
+
*
|
|
7
|
+
* ```js
|
|
8
|
+
* import * as fs from 'fs/promises';
|
|
9
|
+
* ```
|
|
10
|
+
*
|
|
11
|
+
* To use the callback and sync APIs:
|
|
12
|
+
*
|
|
13
|
+
* ```js
|
|
14
|
+
* import * as fs from 'fs';
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* All file system operations have synchronous, callback, and promise-based
|
|
18
|
+
* forms, and are accessible using both CommonJS syntax and ES6 Modules (ESM).
|
|
19
|
+
* @see [source](https://github.com/nodejs/node/blob/v18.0.0/lib/fs.js)
|
|
20
|
+
*/
|
|
1
21
|
declare module 'fs' {
|
|
2
|
-
import * as stream from 'stream';
|
|
3
|
-
import { Abortable, EventEmitter } from 'events';
|
|
4
|
-
import { URL } from 'url';
|
|
5
|
-
import * as promises from 'fs/promises';
|
|
6
|
-
|
|
22
|
+
import * as stream from 'node:stream';
|
|
23
|
+
import { Abortable, EventEmitter } from 'node:events';
|
|
24
|
+
import { URL } from 'node:url';
|
|
25
|
+
import * as promises from 'node:fs/promises';
|
|
7
26
|
export { promises };
|
|
8
27
|
/**
|
|
9
28
|
* Valid types for path values in "fs".
|
|
10
29
|
*/
|
|
11
30
|
export type PathLike = string | Buffer | URL;
|
|
12
|
-
|
|
31
|
+
export type PathOrFileDescriptor = PathLike | number;
|
|
32
|
+
export type TimeLike = string | number | Date;
|
|
13
33
|
export type NoParamCallback = (err: NodeJS.ErrnoException | null) => void;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
34
|
+
export type BufferEncodingOption =
|
|
35
|
+
| 'buffer'
|
|
36
|
+
| {
|
|
37
|
+
encoding: 'buffer';
|
|
38
|
+
};
|
|
39
|
+
export interface ObjectEncodingOptions {
|
|
40
|
+
encoding?: BufferEncoding | null | undefined;
|
|
41
|
+
}
|
|
42
|
+
export type EncodingOption = ObjectEncodingOptions | BufferEncoding | undefined | null;
|
|
21
43
|
export type OpenMode = number | string;
|
|
22
|
-
|
|
23
44
|
export type Mode = number | string;
|
|
24
|
-
|
|
25
45
|
export interface StatsBase<T> {
|
|
26
46
|
isFile(): boolean;
|
|
27
47
|
isDirectory(): boolean;
|
|
@@ -30,7 +50,6 @@ declare module 'fs' {
|
|
|
30
50
|
isSymbolicLink(): boolean;
|
|
31
51
|
isFIFO(): boolean;
|
|
32
52
|
isSocket(): boolean;
|
|
33
|
-
|
|
34
53
|
dev: T;
|
|
35
54
|
ino: T;
|
|
36
55
|
mode: T;
|
|
@@ -50,237 +69,441 @@ declare module 'fs' {
|
|
|
50
69
|
ctime: Date;
|
|
51
70
|
birthtime: Date;
|
|
52
71
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
72
|
+
export interface Stats extends StatsBase<number> {}
|
|
73
|
+
/**
|
|
74
|
+
* A `fs.Stats` object provides information about a file.
|
|
75
|
+
*
|
|
76
|
+
* Objects returned from {@link stat}, {@link lstat} and {@link fstat} and
|
|
77
|
+
* their synchronous counterparts are of this type.
|
|
78
|
+
* If `bigint` in the `options` passed to those methods is true, the numeric values
|
|
79
|
+
* will be `bigint` instead of `number`, and the object will contain additional
|
|
80
|
+
* nanosecond-precision properties suffixed with `Ns`.
|
|
81
|
+
*
|
|
82
|
+
* ```console
|
|
83
|
+
* Stats {
|
|
84
|
+
* dev: 2114,
|
|
85
|
+
* ino: 48064969,
|
|
86
|
+
* mode: 33188,
|
|
87
|
+
* nlink: 1,
|
|
88
|
+
* uid: 85,
|
|
89
|
+
* gid: 100,
|
|
90
|
+
* rdev: 0,
|
|
91
|
+
* size: 527,
|
|
92
|
+
* blksize: 4096,
|
|
93
|
+
* blocks: 8,
|
|
94
|
+
* atimeMs: 1318289051000.1,
|
|
95
|
+
* mtimeMs: 1318289051000.1,
|
|
96
|
+
* ctimeMs: 1318289051000.1,
|
|
97
|
+
* birthtimeMs: 1318289051000.1,
|
|
98
|
+
* atime: Mon, 10 Oct 2011 23:24:11 GMT,
|
|
99
|
+
* mtime: Mon, 10 Oct 2011 23:24:11 GMT,
|
|
100
|
+
* ctime: Mon, 10 Oct 2011 23:24:11 GMT,
|
|
101
|
+
* birthtime: Mon, 10 Oct 2011 23:24:11 GMT }
|
|
102
|
+
* ```
|
|
103
|
+
*
|
|
104
|
+
* `bigint` version:
|
|
105
|
+
*
|
|
106
|
+
* ```console
|
|
107
|
+
* BigIntStats {
|
|
108
|
+
* dev: 2114n,
|
|
109
|
+
* ino: 48064969n,
|
|
110
|
+
* mode: 33188n,
|
|
111
|
+
* nlink: 1n,
|
|
112
|
+
* uid: 85n,
|
|
113
|
+
* gid: 100n,
|
|
114
|
+
* rdev: 0n,
|
|
115
|
+
* size: 527n,
|
|
116
|
+
* blksize: 4096n,
|
|
117
|
+
* blocks: 8n,
|
|
118
|
+
* atimeMs: 1318289051000n,
|
|
119
|
+
* mtimeMs: 1318289051000n,
|
|
120
|
+
* ctimeMs: 1318289051000n,
|
|
121
|
+
* birthtimeMs: 1318289051000n,
|
|
122
|
+
* atimeNs: 1318289051000000000n,
|
|
123
|
+
* mtimeNs: 1318289051000000000n,
|
|
124
|
+
* ctimeNs: 1318289051000000000n,
|
|
125
|
+
* birthtimeNs: 1318289051000000000n,
|
|
126
|
+
* atime: Mon, 10 Oct 2011 23:24:11 GMT,
|
|
127
|
+
* mtime: Mon, 10 Oct 2011 23:24:11 GMT,
|
|
128
|
+
* ctime: Mon, 10 Oct 2011 23:24:11 GMT,
|
|
129
|
+
* birthtime: Mon, 10 Oct 2011 23:24:11 GMT }
|
|
130
|
+
* ```
|
|
131
|
+
* @since v0.1.21
|
|
132
|
+
*/
|
|
133
|
+
export class Stats {}
|
|
134
|
+
/**
|
|
135
|
+
* A representation of a directory entry, which can be a file or a subdirectory
|
|
136
|
+
* within the directory, as returned by reading from an `fs.Dir`. The
|
|
137
|
+
* directory entry is a combination of the file name and file type pairs.
|
|
138
|
+
*
|
|
139
|
+
* Additionally, when {@link readdir} or {@link readdirSync} is called with
|
|
140
|
+
* the `withFileTypes` option set to `true`, the resulting array is filled with `fs.Dirent` objects, rather than strings or `Buffer` s.
|
|
141
|
+
* @since v10.10.0
|
|
142
|
+
*/
|
|
60
143
|
export class Dirent {
|
|
144
|
+
/**
|
|
145
|
+
* Returns `true` if the `fs.Dirent` object describes a regular file.
|
|
146
|
+
* @since v10.10.0
|
|
147
|
+
*/
|
|
61
148
|
isFile(): boolean;
|
|
149
|
+
/**
|
|
150
|
+
* Returns `true` if the `fs.Dirent` object describes a file system
|
|
151
|
+
* directory.
|
|
152
|
+
* @since v10.10.0
|
|
153
|
+
*/
|
|
62
154
|
isDirectory(): boolean;
|
|
155
|
+
/**
|
|
156
|
+
* Returns `true` if the `fs.Dirent` object describes a block device.
|
|
157
|
+
* @since v10.10.0
|
|
158
|
+
*/
|
|
63
159
|
isBlockDevice(): boolean;
|
|
160
|
+
/**
|
|
161
|
+
* Returns `true` if the `fs.Dirent` object describes a character device.
|
|
162
|
+
* @since v10.10.0
|
|
163
|
+
*/
|
|
64
164
|
isCharacterDevice(): boolean;
|
|
165
|
+
/**
|
|
166
|
+
* Returns `true` if the `fs.Dirent` object describes a symbolic link.
|
|
167
|
+
* @since v10.10.0
|
|
168
|
+
*/
|
|
65
169
|
isSymbolicLink(): boolean;
|
|
170
|
+
/**
|
|
171
|
+
* Returns `true` if the `fs.Dirent` object describes a first-in-first-out
|
|
172
|
+
* (FIFO) pipe.
|
|
173
|
+
* @since v10.10.0
|
|
174
|
+
*/
|
|
66
175
|
isFIFO(): boolean;
|
|
176
|
+
/**
|
|
177
|
+
* Returns `true` if the `fs.Dirent` object describes a socket.
|
|
178
|
+
* @since v10.10.0
|
|
179
|
+
*/
|
|
67
180
|
isSocket(): boolean;
|
|
181
|
+
/**
|
|
182
|
+
* The file name that this `fs.Dirent` object refers to. The type of this
|
|
183
|
+
* value is determined by the `options.encoding` passed to {@link readdir} or {@link readdirSync}.
|
|
184
|
+
* @since v10.10.0
|
|
185
|
+
*/
|
|
68
186
|
name: string;
|
|
69
187
|
}
|
|
70
|
-
|
|
71
188
|
/**
|
|
72
189
|
* A class representing a directory stream.
|
|
73
|
-
|
|
74
|
-
|
|
190
|
+
*
|
|
191
|
+
* Created by {@link opendir}, {@link opendirSync}, or `fsPromises.opendir()`.
|
|
192
|
+
*
|
|
193
|
+
* ```js
|
|
194
|
+
* import { opendir } from 'fs/promises';
|
|
195
|
+
*
|
|
196
|
+
* try {
|
|
197
|
+
* const dir = await opendir('./');
|
|
198
|
+
* for await (const dirent of dir)
|
|
199
|
+
* console.log(dirent.name);
|
|
200
|
+
* } catch (err) {
|
|
201
|
+
* console.error(err);
|
|
202
|
+
* }
|
|
203
|
+
* ```
|
|
204
|
+
*
|
|
205
|
+
* When using the async iterator, the `fs.Dir` object will be automatically
|
|
206
|
+
* closed after the iterator exits.
|
|
207
|
+
* @since v12.12.0
|
|
208
|
+
*/
|
|
209
|
+
export class Dir implements AsyncIterable<Dirent> {
|
|
210
|
+
/**
|
|
211
|
+
* The read-only path of this directory as was provided to {@link opendir},{@link opendirSync}, or `fsPromises.opendir()`.
|
|
212
|
+
* @since v12.12.0
|
|
213
|
+
*/
|
|
75
214
|
readonly path: string;
|
|
76
|
-
|
|
77
215
|
/**
|
|
78
216
|
* Asynchronously iterates over the directory via `readdir(3)` until all entries have been read.
|
|
79
217
|
*/
|
|
80
218
|
[Symbol.asyncIterator](): AsyncIterableIterator<Dirent>;
|
|
81
|
-
|
|
82
219
|
/**
|
|
83
220
|
* Asynchronously close the directory's underlying resource handle.
|
|
84
221
|
* Subsequent reads will result in errors.
|
|
222
|
+
*
|
|
223
|
+
* A promise is returned that will be resolved after the resource has been
|
|
224
|
+
* closed.
|
|
225
|
+
* @since v12.12.0
|
|
85
226
|
*/
|
|
86
227
|
close(): Promise<void>;
|
|
87
228
|
close(cb: NoParamCallback): void;
|
|
88
|
-
|
|
89
229
|
/**
|
|
90
230
|
* Synchronously close the directory's underlying resource handle.
|
|
91
231
|
* Subsequent reads will result in errors.
|
|
232
|
+
* @since v12.12.0
|
|
92
233
|
*/
|
|
93
234
|
closeSync(): void;
|
|
94
|
-
|
|
95
235
|
/**
|
|
96
|
-
* Asynchronously read the next directory entry via `readdir(3)` as an `Dirent`.
|
|
97
|
-
*
|
|
98
|
-
*
|
|
236
|
+
* Asynchronously read the next directory entry via [`readdir(3)`](http://man7.org/linux/man-pages/man3/readdir.3.html) as an `fs.Dirent`.
|
|
237
|
+
*
|
|
238
|
+
* A promise is returned that will be resolved with an `fs.Dirent`, or `null`if there are no more directory entries to read.
|
|
239
|
+
*
|
|
240
|
+
* Directory entries returned by this function are in no particular order as
|
|
241
|
+
* provided by the operating system's underlying directory mechanisms.
|
|
242
|
+
* Entries added or removed while iterating over the directory might not be
|
|
243
|
+
* included in the iteration results.
|
|
244
|
+
* @since v12.12.0
|
|
245
|
+
* @return containing {fs.Dirent|null}
|
|
99
246
|
*/
|
|
100
247
|
read(): Promise<Dirent | null>;
|
|
101
248
|
read(cb: (err: NodeJS.ErrnoException | null, dirEnt: Dirent | null) => void): void;
|
|
102
|
-
|
|
103
249
|
/**
|
|
104
|
-
* Synchronously read the next directory entry
|
|
105
|
-
*
|
|
106
|
-
*
|
|
250
|
+
* Synchronously read the next directory entry as an `fs.Dirent`. See the
|
|
251
|
+
* POSIX [`readdir(3)`](http://man7.org/linux/man-pages/man3/readdir.3.html) documentation for more detail.
|
|
252
|
+
*
|
|
253
|
+
* If there are no more directory entries to read, `null` will be returned.
|
|
254
|
+
*
|
|
255
|
+
* Directory entries returned by this function are in no particular order as
|
|
256
|
+
* provided by the operating system's underlying directory mechanisms.
|
|
257
|
+
* Entries added or removed while iterating over the directory might not be
|
|
258
|
+
* included in the iteration results.
|
|
259
|
+
* @since v12.12.0
|
|
107
260
|
*/
|
|
108
261
|
readSync(): Dirent | null;
|
|
109
262
|
}
|
|
110
|
-
|
|
263
|
+
/**
|
|
264
|
+
* Class: fs.StatWatcher
|
|
265
|
+
* @since v14.3.0, v12.20.0
|
|
266
|
+
* Extends `EventEmitter`
|
|
267
|
+
* A successful call to {@link watchFile} method will return a new fs.StatWatcher object.
|
|
268
|
+
*/
|
|
269
|
+
export interface StatWatcher extends EventEmitter {
|
|
270
|
+
/**
|
|
271
|
+
* When called, requests that the Node.js event loop _not_ exit so long as the `fs.StatWatcher` is active. Calling `watcher.ref()` multiple times will have
|
|
272
|
+
* no effect.
|
|
273
|
+
*
|
|
274
|
+
* By default, all `fs.StatWatcher` objects are "ref'ed", making it normally
|
|
275
|
+
* unnecessary to call `watcher.ref()` unless `watcher.unref()` had been
|
|
276
|
+
* called previously.
|
|
277
|
+
* @since v14.3.0, v12.20.0
|
|
278
|
+
*/
|
|
279
|
+
ref(): this;
|
|
280
|
+
/**
|
|
281
|
+
* When called, the active `fs.StatWatcher` object will not require the Node.js
|
|
282
|
+
* event loop to remain active. If there is no other activity keeping the
|
|
283
|
+
* event loop running, the process may exit before the `fs.StatWatcher` object's
|
|
284
|
+
* callback is invoked. Calling `watcher.unref()` multiple times will have
|
|
285
|
+
* no effect.
|
|
286
|
+
* @since v14.3.0, v12.20.0
|
|
287
|
+
*/
|
|
288
|
+
unref(): this;
|
|
289
|
+
}
|
|
111
290
|
export interface FSWatcher extends EventEmitter {
|
|
291
|
+
/**
|
|
292
|
+
* Stop watching for changes on the given `fs.FSWatcher`. Once stopped, the `fs.FSWatcher` object is no longer usable.
|
|
293
|
+
* @since v0.5.8
|
|
294
|
+
*/
|
|
112
295
|
close(): void;
|
|
113
|
-
|
|
114
296
|
/**
|
|
115
297
|
* events.EventEmitter
|
|
116
298
|
* 1. change
|
|
117
299
|
* 2. error
|
|
118
300
|
*/
|
|
119
301
|
addListener(event: string, listener: (...args: any[]) => void): this;
|
|
120
|
-
addListener(event:
|
|
121
|
-
addListener(event:
|
|
122
|
-
addListener(event:
|
|
123
|
-
|
|
302
|
+
addListener(event: 'change', listener: (eventType: string, filename: string | Buffer) => void): this;
|
|
303
|
+
addListener(event: 'error', listener: (error: Error) => void): this;
|
|
304
|
+
addListener(event: 'close', listener: () => void): this;
|
|
124
305
|
on(event: string, listener: (...args: any[]) => void): this;
|
|
125
|
-
on(event:
|
|
126
|
-
on(event:
|
|
127
|
-
on(event:
|
|
128
|
-
|
|
306
|
+
on(event: 'change', listener: (eventType: string, filename: string | Buffer) => void): this;
|
|
307
|
+
on(event: 'error', listener: (error: Error) => void): this;
|
|
308
|
+
on(event: 'close', listener: () => void): this;
|
|
129
309
|
once(event: string, listener: (...args: any[]) => void): this;
|
|
130
|
-
once(event:
|
|
131
|
-
once(event:
|
|
132
|
-
once(event:
|
|
133
|
-
|
|
310
|
+
once(event: 'change', listener: (eventType: string, filename: string | Buffer) => void): this;
|
|
311
|
+
once(event: 'error', listener: (error: Error) => void): this;
|
|
312
|
+
once(event: 'close', listener: () => void): this;
|
|
134
313
|
prependListener(event: string, listener: (...args: any[]) => void): this;
|
|
135
|
-
prependListener(event:
|
|
136
|
-
prependListener(event:
|
|
137
|
-
prependListener(event:
|
|
138
|
-
|
|
314
|
+
prependListener(event: 'change', listener: (eventType: string, filename: string | Buffer) => void): this;
|
|
315
|
+
prependListener(event: 'error', listener: (error: Error) => void): this;
|
|
316
|
+
prependListener(event: 'close', listener: () => void): this;
|
|
139
317
|
prependOnceListener(event: string, listener: (...args: any[]) => void): this;
|
|
140
|
-
prependOnceListener(event:
|
|
141
|
-
prependOnceListener(event:
|
|
142
|
-
prependOnceListener(event:
|
|
318
|
+
prependOnceListener(event: 'change', listener: (eventType: string, filename: string | Buffer) => void): this;
|
|
319
|
+
prependOnceListener(event: 'error', listener: (error: Error) => void): this;
|
|
320
|
+
prependOnceListener(event: 'close', listener: () => void): this;
|
|
143
321
|
}
|
|
144
|
-
|
|
322
|
+
/**
|
|
323
|
+
* Instances of `fs.ReadStream` are created and returned using the {@link createReadStream} function.
|
|
324
|
+
* @since v0.1.93
|
|
325
|
+
*/
|
|
145
326
|
export class ReadStream extends stream.Readable {
|
|
146
|
-
close(): void;
|
|
327
|
+
close(callback?: (err?: NodeJS.ErrnoException | null) => void): void;
|
|
328
|
+
/**
|
|
329
|
+
* The number of bytes that have been read so far.
|
|
330
|
+
* @since v6.4.0
|
|
331
|
+
*/
|
|
147
332
|
bytesRead: number;
|
|
333
|
+
/**
|
|
334
|
+
* The path to the file the stream is reading from as specified in the first
|
|
335
|
+
* argument to `fs.createReadStream()`. If `path` is passed as a string, then`readStream.path` will be a string. If `path` is passed as a `Buffer`, then`readStream.path` will be a
|
|
336
|
+
* `Buffer`. If `fd` is specified, then`readStream.path` will be `undefined`.
|
|
337
|
+
* @since v0.1.93
|
|
338
|
+
*/
|
|
148
339
|
path: string | Buffer;
|
|
340
|
+
/**
|
|
341
|
+
* This property is `true` if the underlying file has not been opened yet,
|
|
342
|
+
* i.e. before the `'ready'` event is emitted.
|
|
343
|
+
* @since v11.2.0, v10.16.0
|
|
344
|
+
*/
|
|
149
345
|
pending: boolean;
|
|
150
|
-
|
|
151
346
|
/**
|
|
152
347
|
* events.EventEmitter
|
|
153
348
|
* 1. open
|
|
154
349
|
* 2. close
|
|
155
350
|
* 3. ready
|
|
156
351
|
*/
|
|
157
|
-
addListener(event:
|
|
158
|
-
addListener(event:
|
|
159
|
-
addListener(event:
|
|
160
|
-
addListener(event:
|
|
161
|
-
addListener(event:
|
|
162
|
-
addListener(event:
|
|
163
|
-
addListener(event:
|
|
164
|
-
addListener(event:
|
|
165
|
-
addListener(event:
|
|
352
|
+
addListener(event: 'close', listener: () => void): this;
|
|
353
|
+
addListener(event: 'data', listener: (chunk: Buffer | string) => void): this;
|
|
354
|
+
addListener(event: 'end', listener: () => void): this;
|
|
355
|
+
addListener(event: 'error', listener: (err: Error) => void): this;
|
|
356
|
+
addListener(event: 'open', listener: (fd: number) => void): this;
|
|
357
|
+
addListener(event: 'pause', listener: () => void): this;
|
|
358
|
+
addListener(event: 'readable', listener: () => void): this;
|
|
359
|
+
addListener(event: 'ready', listener: () => void): this;
|
|
360
|
+
addListener(event: 'resume', listener: () => void): this;
|
|
166
361
|
addListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
167
|
-
|
|
168
|
-
on(event:
|
|
169
|
-
on(event:
|
|
170
|
-
on(event:
|
|
171
|
-
on(event:
|
|
172
|
-
on(event:
|
|
173
|
-
on(event:
|
|
174
|
-
on(event:
|
|
175
|
-
on(event:
|
|
176
|
-
on(event: "resume", listener: () => void): this;
|
|
362
|
+
on(event: 'close', listener: () => void): this;
|
|
363
|
+
on(event: 'data', listener: (chunk: Buffer | string) => void): this;
|
|
364
|
+
on(event: 'end', listener: () => void): this;
|
|
365
|
+
on(event: 'error', listener: (err: Error) => void): this;
|
|
366
|
+
on(event: 'open', listener: (fd: number) => void): this;
|
|
367
|
+
on(event: 'pause', listener: () => void): this;
|
|
368
|
+
on(event: 'readable', listener: () => void): this;
|
|
369
|
+
on(event: 'ready', listener: () => void): this;
|
|
370
|
+
on(event: 'resume', listener: () => void): this;
|
|
177
371
|
on(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
178
|
-
|
|
179
|
-
once(event:
|
|
180
|
-
once(event:
|
|
181
|
-
once(event:
|
|
182
|
-
once(event:
|
|
183
|
-
once(event:
|
|
184
|
-
once(event:
|
|
185
|
-
once(event:
|
|
186
|
-
once(event:
|
|
187
|
-
once(event: "resume", listener: () => void): this;
|
|
372
|
+
once(event: 'close', listener: () => void): this;
|
|
373
|
+
once(event: 'data', listener: (chunk: Buffer | string) => void): this;
|
|
374
|
+
once(event: 'end', listener: () => void): this;
|
|
375
|
+
once(event: 'error', listener: (err: Error) => void): this;
|
|
376
|
+
once(event: 'open', listener: (fd: number) => void): this;
|
|
377
|
+
once(event: 'pause', listener: () => void): this;
|
|
378
|
+
once(event: 'readable', listener: () => void): this;
|
|
379
|
+
once(event: 'ready', listener: () => void): this;
|
|
380
|
+
once(event: 'resume', listener: () => void): this;
|
|
188
381
|
once(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
189
|
-
|
|
190
|
-
prependListener(event:
|
|
191
|
-
prependListener(event:
|
|
192
|
-
prependListener(event:
|
|
193
|
-
prependListener(event:
|
|
194
|
-
prependListener(event:
|
|
195
|
-
prependListener(event:
|
|
196
|
-
prependListener(event:
|
|
197
|
-
prependListener(event:
|
|
198
|
-
prependListener(event: "resume", listener: () => void): this;
|
|
382
|
+
prependListener(event: 'close', listener: () => void): this;
|
|
383
|
+
prependListener(event: 'data', listener: (chunk: Buffer | string) => void): this;
|
|
384
|
+
prependListener(event: 'end', listener: () => void): this;
|
|
385
|
+
prependListener(event: 'error', listener: (err: Error) => void): this;
|
|
386
|
+
prependListener(event: 'open', listener: (fd: number) => void): this;
|
|
387
|
+
prependListener(event: 'pause', listener: () => void): this;
|
|
388
|
+
prependListener(event: 'readable', listener: () => void): this;
|
|
389
|
+
prependListener(event: 'ready', listener: () => void): this;
|
|
390
|
+
prependListener(event: 'resume', listener: () => void): this;
|
|
199
391
|
prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
200
|
-
|
|
201
|
-
prependOnceListener(event:
|
|
202
|
-
prependOnceListener(event:
|
|
203
|
-
prependOnceListener(event:
|
|
204
|
-
prependOnceListener(event:
|
|
205
|
-
prependOnceListener(event:
|
|
206
|
-
prependOnceListener(event:
|
|
207
|
-
prependOnceListener(event:
|
|
208
|
-
prependOnceListener(event:
|
|
209
|
-
prependOnceListener(event: "resume", listener: () => void): this;
|
|
392
|
+
prependOnceListener(event: 'close', listener: () => void): this;
|
|
393
|
+
prependOnceListener(event: 'data', listener: (chunk: Buffer | string) => void): this;
|
|
394
|
+
prependOnceListener(event: 'end', listener: () => void): this;
|
|
395
|
+
prependOnceListener(event: 'error', listener: (err: Error) => void): this;
|
|
396
|
+
prependOnceListener(event: 'open', listener: (fd: number) => void): this;
|
|
397
|
+
prependOnceListener(event: 'pause', listener: () => void): this;
|
|
398
|
+
prependOnceListener(event: 'readable', listener: () => void): this;
|
|
399
|
+
prependOnceListener(event: 'ready', listener: () => void): this;
|
|
400
|
+
prependOnceListener(event: 'resume', listener: () => void): this;
|
|
210
401
|
prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
211
402
|
}
|
|
212
|
-
|
|
403
|
+
/**
|
|
404
|
+
* * Extends `stream.Writable`
|
|
405
|
+
*
|
|
406
|
+
* Instances of `fs.WriteStream` are created and returned using the {@link createWriteStream} function.
|
|
407
|
+
* @since v0.1.93
|
|
408
|
+
*/
|
|
213
409
|
export class WriteStream extends stream.Writable {
|
|
214
|
-
|
|
410
|
+
/**
|
|
411
|
+
* Closes `writeStream`. Optionally accepts a
|
|
412
|
+
* callback that will be executed once the `writeStream`is closed.
|
|
413
|
+
* @since v0.9.4
|
|
414
|
+
*/
|
|
415
|
+
close(callback?: (err?: NodeJS.ErrnoException | null) => void): void;
|
|
416
|
+
/**
|
|
417
|
+
* The number of bytes written so far. Does not include data that is still queued
|
|
418
|
+
* for writing.
|
|
419
|
+
* @since v0.4.7
|
|
420
|
+
*/
|
|
215
421
|
bytesWritten: number;
|
|
422
|
+
/**
|
|
423
|
+
* The path to the file the stream is writing to as specified in the first
|
|
424
|
+
* argument to {@link createWriteStream}. If `path` is passed as a string, then`writeStream.path` will be a string. If `path` is passed as a `Buffer`, then`writeStream.path` will be a
|
|
425
|
+
* `Buffer`.
|
|
426
|
+
* @since v0.1.93
|
|
427
|
+
*/
|
|
216
428
|
path: string | Buffer;
|
|
429
|
+
/**
|
|
430
|
+
* This property is `true` if the underlying file has not been opened yet,
|
|
431
|
+
* i.e. before the `'ready'` event is emitted.
|
|
432
|
+
* @since v11.2.0
|
|
433
|
+
*/
|
|
217
434
|
pending: boolean;
|
|
218
|
-
|
|
219
435
|
/**
|
|
220
436
|
* events.EventEmitter
|
|
221
437
|
* 1. open
|
|
222
438
|
* 2. close
|
|
223
439
|
* 3. ready
|
|
224
440
|
*/
|
|
225
|
-
addListener(event:
|
|
226
|
-
addListener(event:
|
|
227
|
-
addListener(event:
|
|
228
|
-
addListener(event:
|
|
229
|
-
addListener(event:
|
|
230
|
-
addListener(event:
|
|
231
|
-
addListener(event:
|
|
232
|
-
addListener(event:
|
|
441
|
+
addListener(event: 'close', listener: () => void): this;
|
|
442
|
+
addListener(event: 'drain', listener: () => void): this;
|
|
443
|
+
addListener(event: 'error', listener: (err: Error) => void): this;
|
|
444
|
+
addListener(event: 'finish', listener: () => void): this;
|
|
445
|
+
addListener(event: 'open', listener: (fd: number) => void): this;
|
|
446
|
+
addListener(event: 'pipe', listener: (src: stream.Readable) => void): this;
|
|
447
|
+
addListener(event: 'ready', listener: () => void): this;
|
|
448
|
+
addListener(event: 'unpipe', listener: (src: stream.Readable) => void): this;
|
|
233
449
|
addListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
234
|
-
|
|
235
|
-
on(event:
|
|
236
|
-
on(event:
|
|
237
|
-
on(event:
|
|
238
|
-
on(event:
|
|
239
|
-
on(event:
|
|
240
|
-
on(event:
|
|
241
|
-
on(event:
|
|
242
|
-
on(event: "unpipe", listener: (src: stream.Readable) => void): this;
|
|
450
|
+
on(event: 'close', listener: () => void): this;
|
|
451
|
+
on(event: 'drain', listener: () => void): this;
|
|
452
|
+
on(event: 'error', listener: (err: Error) => void): this;
|
|
453
|
+
on(event: 'finish', listener: () => void): this;
|
|
454
|
+
on(event: 'open', listener: (fd: number) => void): this;
|
|
455
|
+
on(event: 'pipe', listener: (src: stream.Readable) => void): this;
|
|
456
|
+
on(event: 'ready', listener: () => void): this;
|
|
457
|
+
on(event: 'unpipe', listener: (src: stream.Readable) => void): this;
|
|
243
458
|
on(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
244
|
-
|
|
245
|
-
once(event:
|
|
246
|
-
once(event:
|
|
247
|
-
once(event:
|
|
248
|
-
once(event:
|
|
249
|
-
once(event:
|
|
250
|
-
once(event:
|
|
251
|
-
once(event:
|
|
252
|
-
once(event: "unpipe", listener: (src: stream.Readable) => void): this;
|
|
459
|
+
once(event: 'close', listener: () => void): this;
|
|
460
|
+
once(event: 'drain', listener: () => void): this;
|
|
461
|
+
once(event: 'error', listener: (err: Error) => void): this;
|
|
462
|
+
once(event: 'finish', listener: () => void): this;
|
|
463
|
+
once(event: 'open', listener: (fd: number) => void): this;
|
|
464
|
+
once(event: 'pipe', listener: (src: stream.Readable) => void): this;
|
|
465
|
+
once(event: 'ready', listener: () => void): this;
|
|
466
|
+
once(event: 'unpipe', listener: (src: stream.Readable) => void): this;
|
|
253
467
|
once(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
254
|
-
|
|
255
|
-
prependListener(event:
|
|
256
|
-
prependListener(event:
|
|
257
|
-
prependListener(event:
|
|
258
|
-
prependListener(event:
|
|
259
|
-
prependListener(event:
|
|
260
|
-
prependListener(event:
|
|
261
|
-
prependListener(event:
|
|
262
|
-
prependListener(event: "unpipe", listener: (src: stream.Readable) => void): this;
|
|
468
|
+
prependListener(event: 'close', listener: () => void): this;
|
|
469
|
+
prependListener(event: 'drain', listener: () => void): this;
|
|
470
|
+
prependListener(event: 'error', listener: (err: Error) => void): this;
|
|
471
|
+
prependListener(event: 'finish', listener: () => void): this;
|
|
472
|
+
prependListener(event: 'open', listener: (fd: number) => void): this;
|
|
473
|
+
prependListener(event: 'pipe', listener: (src: stream.Readable) => void): this;
|
|
474
|
+
prependListener(event: 'ready', listener: () => void): this;
|
|
475
|
+
prependListener(event: 'unpipe', listener: (src: stream.Readable) => void): this;
|
|
263
476
|
prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
264
|
-
|
|
265
|
-
prependOnceListener(event:
|
|
266
|
-
prependOnceListener(event:
|
|
267
|
-
prependOnceListener(event:
|
|
268
|
-
prependOnceListener(event:
|
|
269
|
-
prependOnceListener(event:
|
|
270
|
-
prependOnceListener(event:
|
|
271
|
-
prependOnceListener(event:
|
|
272
|
-
prependOnceListener(event: "unpipe", listener: (src: stream.Readable) => void): this;
|
|
477
|
+
prependOnceListener(event: 'close', listener: () => void): this;
|
|
478
|
+
prependOnceListener(event: 'drain', listener: () => void): this;
|
|
479
|
+
prependOnceListener(event: 'error', listener: (err: Error) => void): this;
|
|
480
|
+
prependOnceListener(event: 'finish', listener: () => void): this;
|
|
481
|
+
prependOnceListener(event: 'open', listener: (fd: number) => void): this;
|
|
482
|
+
prependOnceListener(event: 'pipe', listener: (src: stream.Readable) => void): this;
|
|
483
|
+
prependOnceListener(event: 'ready', listener: () => void): this;
|
|
484
|
+
prependOnceListener(event: 'unpipe', listener: (src: stream.Readable) => void): this;
|
|
273
485
|
prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
274
486
|
}
|
|
275
|
-
|
|
276
487
|
/**
|
|
277
|
-
*
|
|
278
|
-
*
|
|
279
|
-
*
|
|
488
|
+
* Asynchronously rename file at `oldPath` to the pathname provided
|
|
489
|
+
* as `newPath`. In the case that `newPath` already exists, it will
|
|
490
|
+
* be overwritten. If there is a directory at `newPath`, an error will
|
|
491
|
+
* be raised instead. No arguments other than a possible exception are
|
|
492
|
+
* given to the completion callback.
|
|
493
|
+
*
|
|
494
|
+
* See also: [`rename(2)`](http://man7.org/linux/man-pages/man2/rename.2.html).
|
|
495
|
+
*
|
|
496
|
+
* ```js
|
|
497
|
+
* import { rename } from 'fs';
|
|
498
|
+
*
|
|
499
|
+
* rename('oldFile.txt', 'newFile.txt', (err) => {
|
|
500
|
+
* if (err) throw err;
|
|
501
|
+
* console.log('Rename complete!');
|
|
502
|
+
* });
|
|
503
|
+
* ```
|
|
504
|
+
* @since v0.0.2
|
|
280
505
|
*/
|
|
281
506
|
export function rename(oldPath: PathLike, newPath: PathLike, callback: NoParamCallback): void;
|
|
282
|
-
|
|
283
|
-
// NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
|
|
284
507
|
export namespace rename {
|
|
285
508
|
/**
|
|
286
509
|
* Asynchronous rename(2) - Change the name or location of a file or directory.
|
|
@@ -291,28 +514,40 @@ declare module 'fs' {
|
|
|
291
514
|
*/
|
|
292
515
|
function __promisify__(oldPath: PathLike, newPath: PathLike): Promise<void>;
|
|
293
516
|
}
|
|
294
|
-
|
|
295
517
|
/**
|
|
296
|
-
*
|
|
297
|
-
*
|
|
298
|
-
*
|
|
518
|
+
* Renames the file from `oldPath` to `newPath`. Returns `undefined`.
|
|
519
|
+
*
|
|
520
|
+
* See the POSIX [`rename(2)`](http://man7.org/linux/man-pages/man2/rename.2.html) documentation for more details.
|
|
521
|
+
* @since v0.1.21
|
|
299
522
|
*/
|
|
300
523
|
export function renameSync(oldPath: PathLike, newPath: PathLike): void;
|
|
301
|
-
|
|
302
524
|
/**
|
|
303
|
-
*
|
|
304
|
-
*
|
|
305
|
-
*
|
|
525
|
+
* Truncates the file. No arguments other than a possible exception are
|
|
526
|
+
* given to the completion callback. A file descriptor can also be passed as the
|
|
527
|
+
* first argument. In this case, `fs.ftruncate()` is called.
|
|
528
|
+
*
|
|
529
|
+
* ```js
|
|
530
|
+
* import { truncate } from 'fs';
|
|
531
|
+
* // Assuming that 'path/file.txt' is a regular file.
|
|
532
|
+
* truncate('path/file.txt', (err) => {
|
|
533
|
+
* if (err) throw err;
|
|
534
|
+
* console.log('path/file.txt was truncated');
|
|
535
|
+
* });
|
|
536
|
+
* ```
|
|
537
|
+
*
|
|
538
|
+
* Passing a file descriptor is deprecated and may result in an error being thrown
|
|
539
|
+
* in the future.
|
|
540
|
+
*
|
|
541
|
+
* See the POSIX [`truncate(2)`](http://man7.org/linux/man-pages/man2/truncate.2.html) documentation for more details.
|
|
542
|
+
* @since v0.8.6
|
|
543
|
+
* @param [len=0]
|
|
306
544
|
*/
|
|
307
545
|
export function truncate(path: PathLike, len: number | undefined | null, callback: NoParamCallback): void;
|
|
308
|
-
|
|
309
546
|
/**
|
|
310
547
|
* Asynchronous truncate(2) - Truncate a file to a specified length.
|
|
311
548
|
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
312
549
|
*/
|
|
313
550
|
export function truncate(path: PathLike, callback: NoParamCallback): void;
|
|
314
|
-
|
|
315
|
-
// NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
|
|
316
551
|
export namespace truncate {
|
|
317
552
|
/**
|
|
318
553
|
* Asynchronous truncate(2) - Truncate a file to a specified length.
|
|
@@ -321,28 +556,65 @@ declare module 'fs' {
|
|
|
321
556
|
*/
|
|
322
557
|
function __promisify__(path: PathLike, len?: number | null): Promise<void>;
|
|
323
558
|
}
|
|
324
|
-
|
|
325
559
|
/**
|
|
326
|
-
*
|
|
327
|
-
*
|
|
328
|
-
*
|
|
560
|
+
* Truncates the file. Returns `undefined`. A file descriptor can also be
|
|
561
|
+
* passed as the first argument. In this case, `fs.ftruncateSync()` is called.
|
|
562
|
+
*
|
|
563
|
+
* Passing a file descriptor is deprecated and may result in an error being thrown
|
|
564
|
+
* in the future.
|
|
565
|
+
* @since v0.8.6
|
|
566
|
+
* @param [len=0]
|
|
329
567
|
*/
|
|
330
568
|
export function truncateSync(path: PathLike, len?: number | null): void;
|
|
331
|
-
|
|
332
569
|
/**
|
|
333
|
-
*
|
|
334
|
-
*
|
|
335
|
-
*
|
|
570
|
+
* Truncates the file descriptor. No arguments other than a possible exception are
|
|
571
|
+
* given to the completion callback.
|
|
572
|
+
*
|
|
573
|
+
* See the POSIX [`ftruncate(2)`](http://man7.org/linux/man-pages/man2/ftruncate.2.html) documentation for more detail.
|
|
574
|
+
*
|
|
575
|
+
* If the file referred to by the file descriptor was larger than `len` bytes, only
|
|
576
|
+
* the first `len` bytes will be retained in the file.
|
|
577
|
+
*
|
|
578
|
+
* For example, the following program retains only the first four bytes of the
|
|
579
|
+
* file:
|
|
580
|
+
*
|
|
581
|
+
* ```js
|
|
582
|
+
* import { open, close, ftruncate } from 'fs';
|
|
583
|
+
*
|
|
584
|
+
* function closeFd(fd) {
|
|
585
|
+
* close(fd, (err) => {
|
|
586
|
+
* if (err) throw err;
|
|
587
|
+
* });
|
|
588
|
+
* }
|
|
589
|
+
*
|
|
590
|
+
* open('temp.txt', 'r+', (err, fd) => {
|
|
591
|
+
* if (err) throw err;
|
|
592
|
+
*
|
|
593
|
+
* try {
|
|
594
|
+
* ftruncate(fd, 4, (err) => {
|
|
595
|
+
* closeFd(fd);
|
|
596
|
+
* if (err) throw err;
|
|
597
|
+
* });
|
|
598
|
+
* } catch (err) {
|
|
599
|
+
* closeFd(fd);
|
|
600
|
+
* if (err) throw err;
|
|
601
|
+
* }
|
|
602
|
+
* });
|
|
603
|
+
* ```
|
|
604
|
+
*
|
|
605
|
+
* If the file previously was shorter than `len` bytes, it is extended, and the
|
|
606
|
+
* extended part is filled with null bytes (`'\0'`):
|
|
607
|
+
*
|
|
608
|
+
* If `len` is negative then `0` will be used.
|
|
609
|
+
* @since v0.8.6
|
|
610
|
+
* @param [len=0]
|
|
336
611
|
*/
|
|
337
612
|
export function ftruncate(fd: number, len: number | undefined | null, callback: NoParamCallback): void;
|
|
338
|
-
|
|
339
613
|
/**
|
|
340
614
|
* Asynchronous ftruncate(2) - Truncate a file to a specified length.
|
|
341
615
|
* @param fd A file descriptor.
|
|
342
616
|
*/
|
|
343
617
|
export function ftruncate(fd: number, callback: NoParamCallback): void;
|
|
344
|
-
|
|
345
|
-
// NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
|
|
346
618
|
export namespace ftruncate {
|
|
347
619
|
/**
|
|
348
620
|
* Asynchronous ftruncate(2) - Truncate a file to a specified length.
|
|
@@ -351,21 +623,23 @@ declare module 'fs' {
|
|
|
351
623
|
*/
|
|
352
624
|
function __promisify__(fd: number, len?: number | null): Promise<void>;
|
|
353
625
|
}
|
|
354
|
-
|
|
355
626
|
/**
|
|
356
|
-
*
|
|
357
|
-
*
|
|
358
|
-
*
|
|
627
|
+
* Truncates the file descriptor. Returns `undefined`.
|
|
628
|
+
*
|
|
629
|
+
* For detailed information, see the documentation of the asynchronous version of
|
|
630
|
+
* this API: {@link ftruncate}.
|
|
631
|
+
* @since v0.8.6
|
|
632
|
+
* @param [len=0]
|
|
359
633
|
*/
|
|
360
634
|
export function ftruncateSync(fd: number, len?: number | null): void;
|
|
361
|
-
|
|
362
635
|
/**
|
|
363
|
-
*
|
|
364
|
-
*
|
|
636
|
+
* Asynchronously changes owner and group of a file. No arguments other than a
|
|
637
|
+
* possible exception are given to the completion callback.
|
|
638
|
+
*
|
|
639
|
+
* See the POSIX [`chown(2)`](http://man7.org/linux/man-pages/man2/chown.2.html) documentation for more detail.
|
|
640
|
+
* @since v0.1.97
|
|
365
641
|
*/
|
|
366
642
|
export function chown(path: PathLike, uid: number, gid: number, callback: NoParamCallback): void;
|
|
367
|
-
|
|
368
|
-
// NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
|
|
369
643
|
export namespace chown {
|
|
370
644
|
/**
|
|
371
645
|
* Asynchronous chown(2) - Change ownership of a file.
|
|
@@ -373,20 +647,22 @@ declare module 'fs' {
|
|
|
373
647
|
*/
|
|
374
648
|
function __promisify__(path: PathLike, uid: number, gid: number): Promise<void>;
|
|
375
649
|
}
|
|
376
|
-
|
|
377
650
|
/**
|
|
378
|
-
*
|
|
379
|
-
*
|
|
651
|
+
* Synchronously changes owner and group of a file. Returns `undefined`.
|
|
652
|
+
* This is the synchronous version of {@link chown}.
|
|
653
|
+
*
|
|
654
|
+
* See the POSIX [`chown(2)`](http://man7.org/linux/man-pages/man2/chown.2.html) documentation for more detail.
|
|
655
|
+
* @since v0.1.97
|
|
380
656
|
*/
|
|
381
657
|
export function chownSync(path: PathLike, uid: number, gid: number): void;
|
|
382
|
-
|
|
383
658
|
/**
|
|
384
|
-
*
|
|
385
|
-
*
|
|
659
|
+
* Sets the owner of the file. No arguments other than a possible exception are
|
|
660
|
+
* given to the completion callback.
|
|
661
|
+
*
|
|
662
|
+
* See the POSIX [`fchown(2)`](http://man7.org/linux/man-pages/man2/fchown.2.html) documentation for more detail.
|
|
663
|
+
* @since v0.4.7
|
|
386
664
|
*/
|
|
387
665
|
export function fchown(fd: number, uid: number, gid: number, callback: NoParamCallback): void;
|
|
388
|
-
|
|
389
|
-
// NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
|
|
390
666
|
export namespace fchown {
|
|
391
667
|
/**
|
|
392
668
|
* Asynchronous fchown(2) - Change ownership of a file.
|
|
@@ -394,20 +670,22 @@ declare module 'fs' {
|
|
|
394
670
|
*/
|
|
395
671
|
function __promisify__(fd: number, uid: number, gid: number): Promise<void>;
|
|
396
672
|
}
|
|
397
|
-
|
|
398
673
|
/**
|
|
399
|
-
*
|
|
400
|
-
*
|
|
674
|
+
* Sets the owner of the file. Returns `undefined`.
|
|
675
|
+
*
|
|
676
|
+
* See the POSIX [`fchown(2)`](http://man7.org/linux/man-pages/man2/fchown.2.html) documentation for more detail.
|
|
677
|
+
* @since v0.4.7
|
|
678
|
+
* @param uid The file's new owner's user id.
|
|
679
|
+
* @param gid The file's new group's group id.
|
|
401
680
|
*/
|
|
402
681
|
export function fchownSync(fd: number, uid: number, gid: number): void;
|
|
403
|
-
|
|
404
682
|
/**
|
|
405
|
-
*
|
|
406
|
-
*
|
|
683
|
+
* Set the owner of the symbolic link. No arguments other than a possible
|
|
684
|
+
* exception are given to the completion callback.
|
|
685
|
+
*
|
|
686
|
+
* See the POSIX [`lchown(2)`](http://man7.org/linux/man-pages/man2/lchown.2.html) documentation for more detail.
|
|
407
687
|
*/
|
|
408
688
|
export function lchown(path: PathLike, uid: number, gid: number, callback: NoParamCallback): void;
|
|
409
|
-
|
|
410
|
-
// NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
|
|
411
689
|
export namespace lchown {
|
|
412
690
|
/**
|
|
413
691
|
* Asynchronous lchown(2) - Change ownership of a file. Does not dereference symbolic links.
|
|
@@ -415,24 +693,24 @@ declare module 'fs' {
|
|
|
415
693
|
*/
|
|
416
694
|
function __promisify__(path: PathLike, uid: number, gid: number): Promise<void>;
|
|
417
695
|
}
|
|
418
|
-
|
|
419
696
|
/**
|
|
420
|
-
*
|
|
421
|
-
*
|
|
697
|
+
* Set the owner for the path. Returns `undefined`.
|
|
698
|
+
*
|
|
699
|
+
* See the POSIX [`lchown(2)`](http://man7.org/linux/man-pages/man2/lchown.2.html) documentation for more details.
|
|
700
|
+
* @param uid The file's new owner's user id.
|
|
701
|
+
* @param gid The file's new group's group id.
|
|
422
702
|
*/
|
|
423
703
|
export function lchownSync(path: PathLike, uid: number, gid: number): void;
|
|
424
|
-
|
|
425
704
|
/**
|
|
426
|
-
* Changes the access and modification times of a file in the same way as
|
|
427
|
-
*
|
|
428
|
-
*
|
|
429
|
-
*
|
|
430
|
-
*
|
|
431
|
-
*
|
|
705
|
+
* Changes the access and modification times of a file in the same way as {@link utimes}, with the difference that if the path refers to a symbolic
|
|
706
|
+
* link, then the link is not dereferenced: instead, the timestamps of the
|
|
707
|
+
* symbolic link itself are changed.
|
|
708
|
+
*
|
|
709
|
+
* No arguments other than a possible exception are given to the completion
|
|
710
|
+
* callback.
|
|
711
|
+
* @since v14.5.0, v12.19.0
|
|
432
712
|
*/
|
|
433
|
-
export function lutimes(path: PathLike, atime:
|
|
434
|
-
|
|
435
|
-
// NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
|
|
713
|
+
export function lutimes(path: PathLike, atime: TimeLike, mtime: TimeLike, callback: NoParamCallback): void;
|
|
436
714
|
export namespace lutimes {
|
|
437
715
|
/**
|
|
438
716
|
* Changes the access and modification times of a file in the same way as `fsPromises.utimes()`,
|
|
@@ -442,27 +720,32 @@ declare module 'fs' {
|
|
|
442
720
|
* @param atime The last access time. If a string is provided, it will be coerced to number.
|
|
443
721
|
* @param mtime The last modified time. If a string is provided, it will be coerced to number.
|
|
444
722
|
*/
|
|
445
|
-
function __promisify__(path: PathLike, atime:
|
|
723
|
+
function __promisify__(path: PathLike, atime: TimeLike, mtime: TimeLike): Promise<void>;
|
|
446
724
|
}
|
|
447
|
-
|
|
448
725
|
/**
|
|
449
|
-
* Change the file system timestamps of the symbolic link referenced by `path`.
|
|
450
|
-
* or throws an exception when parameters are incorrect or
|
|
451
|
-
* This is the synchronous version of
|
|
452
|
-
* @
|
|
453
|
-
* @param atime The last access time. If a string is provided, it will be coerced to number.
|
|
454
|
-
* @param mtime The last modified time. If a string is provided, it will be coerced to number.
|
|
726
|
+
* Change the file system timestamps of the symbolic link referenced by `path`.
|
|
727
|
+
* Returns `undefined`, or throws an exception when parameters are incorrect or
|
|
728
|
+
* the operation fails. This is the synchronous version of {@link lutimes}.
|
|
729
|
+
* @since v14.5.0, v12.19.0
|
|
455
730
|
*/
|
|
456
|
-
export function lutimesSync(path: PathLike, atime:
|
|
457
|
-
|
|
731
|
+
export function lutimesSync(path: PathLike, atime: TimeLike, mtime: TimeLike): void;
|
|
458
732
|
/**
|
|
459
|
-
*
|
|
460
|
-
*
|
|
461
|
-
*
|
|
733
|
+
* Asynchronously changes the permissions of a file. No arguments other than a
|
|
734
|
+
* possible exception are given to the completion callback.
|
|
735
|
+
*
|
|
736
|
+
* See the POSIX [`chmod(2)`](http://man7.org/linux/man-pages/man2/chmod.2.html) documentation for more detail.
|
|
737
|
+
*
|
|
738
|
+
* ```js
|
|
739
|
+
* import { chmod } from 'fs';
|
|
740
|
+
*
|
|
741
|
+
* chmod('my_file.txt', 0o775, (err) => {
|
|
742
|
+
* if (err) throw err;
|
|
743
|
+
* console.log('The permissions for file "my_file.txt" have been changed!');
|
|
744
|
+
* });
|
|
745
|
+
* ```
|
|
746
|
+
* @since v0.1.30
|
|
462
747
|
*/
|
|
463
748
|
export function chmod(path: PathLike, mode: Mode, callback: NoParamCallback): void;
|
|
464
|
-
|
|
465
|
-
// NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
|
|
466
749
|
export namespace chmod {
|
|
467
750
|
/**
|
|
468
751
|
* Asynchronous chmod(2) - Change permissions of a file.
|
|
@@ -471,22 +754,22 @@ declare module 'fs' {
|
|
|
471
754
|
*/
|
|
472
755
|
function __promisify__(path: PathLike, mode: Mode): Promise<void>;
|
|
473
756
|
}
|
|
474
|
-
|
|
475
757
|
/**
|
|
476
|
-
*
|
|
477
|
-
*
|
|
478
|
-
*
|
|
758
|
+
* For detailed information, see the documentation of the asynchronous version of
|
|
759
|
+
* this API: {@link chmod}.
|
|
760
|
+
*
|
|
761
|
+
* See the POSIX [`chmod(2)`](http://man7.org/linux/man-pages/man2/chmod.2.html) documentation for more detail.
|
|
762
|
+
* @since v0.6.7
|
|
479
763
|
*/
|
|
480
764
|
export function chmodSync(path: PathLike, mode: Mode): void;
|
|
481
|
-
|
|
482
765
|
/**
|
|
483
|
-
*
|
|
484
|
-
*
|
|
485
|
-
*
|
|
766
|
+
* Sets the permissions on the file. No arguments other than a possible exception
|
|
767
|
+
* are given to the completion callback.
|
|
768
|
+
*
|
|
769
|
+
* See the POSIX [`fchmod(2)`](http://man7.org/linux/man-pages/man2/fchmod.2.html) documentation for more detail.
|
|
770
|
+
* @since v0.4.7
|
|
486
771
|
*/
|
|
487
772
|
export function fchmod(fd: number, mode: Mode, callback: NoParamCallback): void;
|
|
488
|
-
|
|
489
|
-
// NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
|
|
490
773
|
export namespace fchmod {
|
|
491
774
|
/**
|
|
492
775
|
* Asynchronous fchmod(2) - Change permissions of a file.
|
|
@@ -495,22 +778,24 @@ declare module 'fs' {
|
|
|
495
778
|
*/
|
|
496
779
|
function __promisify__(fd: number, mode: Mode): Promise<void>;
|
|
497
780
|
}
|
|
498
|
-
|
|
499
781
|
/**
|
|
500
|
-
*
|
|
501
|
-
*
|
|
502
|
-
*
|
|
782
|
+
* Sets the permissions on the file. Returns `undefined`.
|
|
783
|
+
*
|
|
784
|
+
* See the POSIX [`fchmod(2)`](http://man7.org/linux/man-pages/man2/fchmod.2.html) documentation for more detail.
|
|
785
|
+
* @since v0.4.7
|
|
503
786
|
*/
|
|
504
787
|
export function fchmodSync(fd: number, mode: Mode): void;
|
|
505
|
-
|
|
506
788
|
/**
|
|
507
|
-
*
|
|
508
|
-
*
|
|
509
|
-
*
|
|
789
|
+
* Changes the permissions on a symbolic link. No arguments other than a possible
|
|
790
|
+
* exception are given to the completion callback.
|
|
791
|
+
*
|
|
792
|
+
* This method is only implemented on macOS.
|
|
793
|
+
*
|
|
794
|
+
* See the POSIX [`lchmod(2)`](https://www.freebsd.org/cgi/man.cgi?query=lchmod&sektion=2) documentation for more detail.
|
|
795
|
+
* @deprecated Since v0.4.7
|
|
510
796
|
*/
|
|
511
797
|
export function lchmod(path: PathLike, mode: Mode, callback: NoParamCallback): void;
|
|
512
|
-
|
|
513
|
-
// NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
|
|
798
|
+
/** @deprecated */
|
|
514
799
|
export namespace lchmod {
|
|
515
800
|
/**
|
|
516
801
|
* Asynchronous lchmod(2) - Change permissions of a file. Does not dereference symbolic links.
|
|
@@ -519,109 +804,295 @@ declare module 'fs' {
|
|
|
519
804
|
*/
|
|
520
805
|
function __promisify__(path: PathLike, mode: Mode): Promise<void>;
|
|
521
806
|
}
|
|
522
|
-
|
|
523
807
|
/**
|
|
524
|
-
*
|
|
525
|
-
*
|
|
526
|
-
*
|
|
808
|
+
* Changes the permissions on a symbolic link. Returns `undefined`.
|
|
809
|
+
*
|
|
810
|
+
* This method is only implemented on macOS.
|
|
811
|
+
*
|
|
812
|
+
* See the POSIX [`lchmod(2)`](https://www.freebsd.org/cgi/man.cgi?query=lchmod&sektion=2) documentation for more detail.
|
|
813
|
+
* @deprecated Since v0.4.7
|
|
527
814
|
*/
|
|
528
815
|
export function lchmodSync(path: PathLike, mode: Mode): void;
|
|
529
|
-
|
|
530
816
|
/**
|
|
531
|
-
* Asynchronous stat(2)
|
|
532
|
-
*
|
|
817
|
+
* Asynchronous [`stat(2)`](http://man7.org/linux/man-pages/man2/stat.2.html). The callback gets two arguments `(err, stats)` where`stats` is an `fs.Stats` object.
|
|
818
|
+
*
|
|
819
|
+
* In case of an error, the `err.code` will be one of `Common System Errors`.
|
|
820
|
+
*
|
|
821
|
+
* Using `fs.stat()` to check for the existence of a file before calling`fs.open()`, `fs.readFile()` or `fs.writeFile()` is not recommended.
|
|
822
|
+
* Instead, user code should open/read/write the file directly and handle the
|
|
823
|
+
* error raised if the file is not available.
|
|
824
|
+
*
|
|
825
|
+
* To check if a file exists without manipulating it afterwards, {@link access} is recommended.
|
|
826
|
+
*
|
|
827
|
+
* For example, given the following directory structure:
|
|
828
|
+
*
|
|
829
|
+
* ```text
|
|
830
|
+
* - txtDir
|
|
831
|
+
* -- file.txt
|
|
832
|
+
* - app.js
|
|
833
|
+
* ```
|
|
834
|
+
*
|
|
835
|
+
* The next program will check for the stats of the given paths:
|
|
836
|
+
*
|
|
837
|
+
* ```js
|
|
838
|
+
* import { stat } from 'fs';
|
|
839
|
+
*
|
|
840
|
+
* const pathsToCheck = ['./txtDir', './txtDir/file.txt'];
|
|
841
|
+
*
|
|
842
|
+
* for (let i = 0; i < pathsToCheck.length; i++) {
|
|
843
|
+
* stat(pathsToCheck[i], (err, stats) => {
|
|
844
|
+
* console.log(stats.isDirectory());
|
|
845
|
+
* console.log(stats);
|
|
846
|
+
* });
|
|
847
|
+
* }
|
|
848
|
+
* ```
|
|
849
|
+
*
|
|
850
|
+
* The resulting output will resemble:
|
|
851
|
+
*
|
|
852
|
+
* ```console
|
|
853
|
+
* true
|
|
854
|
+
* Stats {
|
|
855
|
+
* dev: 16777220,
|
|
856
|
+
* mode: 16877,
|
|
857
|
+
* nlink: 3,
|
|
858
|
+
* uid: 501,
|
|
859
|
+
* gid: 20,
|
|
860
|
+
* rdev: 0,
|
|
861
|
+
* blksize: 4096,
|
|
862
|
+
* ino: 14214262,
|
|
863
|
+
* size: 96,
|
|
864
|
+
* blocks: 0,
|
|
865
|
+
* atimeMs: 1561174653071.963,
|
|
866
|
+
* mtimeMs: 1561174614583.3518,
|
|
867
|
+
* ctimeMs: 1561174626623.5366,
|
|
868
|
+
* birthtimeMs: 1561174126937.2893,
|
|
869
|
+
* atime: 2019-06-22T03:37:33.072Z,
|
|
870
|
+
* mtime: 2019-06-22T03:36:54.583Z,
|
|
871
|
+
* ctime: 2019-06-22T03:37:06.624Z,
|
|
872
|
+
* birthtime: 2019-06-22T03:28:46.937Z
|
|
873
|
+
* }
|
|
874
|
+
* false
|
|
875
|
+
* Stats {
|
|
876
|
+
* dev: 16777220,
|
|
877
|
+
* mode: 33188,
|
|
878
|
+
* nlink: 1,
|
|
879
|
+
* uid: 501,
|
|
880
|
+
* gid: 20,
|
|
881
|
+
* rdev: 0,
|
|
882
|
+
* blksize: 4096,
|
|
883
|
+
* ino: 14214074,
|
|
884
|
+
* size: 8,
|
|
885
|
+
* blocks: 8,
|
|
886
|
+
* atimeMs: 1561174616618.8555,
|
|
887
|
+
* mtimeMs: 1561174614584,
|
|
888
|
+
* ctimeMs: 1561174614583.8145,
|
|
889
|
+
* birthtimeMs: 1561174007710.7478,
|
|
890
|
+
* atime: 2019-06-22T03:36:56.619Z,
|
|
891
|
+
* mtime: 2019-06-22T03:36:54.584Z,
|
|
892
|
+
* ctime: 2019-06-22T03:36:54.584Z,
|
|
893
|
+
* birthtime: 2019-06-22T03:26:47.711Z
|
|
894
|
+
* }
|
|
895
|
+
* ```
|
|
896
|
+
* @since v0.0.2
|
|
533
897
|
*/
|
|
534
898
|
export function stat(path: PathLike, callback: (err: NodeJS.ErrnoException | null, stats: Stats) => void): void;
|
|
535
|
-
export function stat(
|
|
536
|
-
|
|
899
|
+
export function stat(
|
|
900
|
+
path: PathLike,
|
|
901
|
+
options:
|
|
902
|
+
| (StatOptions & {
|
|
903
|
+
bigint?: false | undefined;
|
|
904
|
+
})
|
|
905
|
+
| undefined,
|
|
906
|
+
callback: (err: NodeJS.ErrnoException | null, stats: Stats) => void
|
|
907
|
+
): void;
|
|
908
|
+
export function stat(
|
|
909
|
+
path: PathLike,
|
|
910
|
+
options: StatOptions & {
|
|
911
|
+
bigint: true;
|
|
912
|
+
},
|
|
913
|
+
callback: (err: NodeJS.ErrnoException | null, stats: BigIntStats) => void
|
|
914
|
+
): void;
|
|
537
915
|
export function stat(path: PathLike, options: StatOptions | undefined, callback: (err: NodeJS.ErrnoException | null, stats: Stats | BigIntStats) => void): void;
|
|
538
|
-
|
|
539
|
-
// NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
|
|
540
916
|
export namespace stat {
|
|
541
917
|
/**
|
|
542
918
|
* Asynchronous stat(2) - Get file status.
|
|
543
919
|
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
544
920
|
*/
|
|
545
|
-
function __promisify__(
|
|
546
|
-
|
|
921
|
+
function __promisify__(
|
|
922
|
+
path: PathLike,
|
|
923
|
+
options?: StatOptions & {
|
|
924
|
+
bigint?: false | undefined;
|
|
925
|
+
}
|
|
926
|
+
): Promise<Stats>;
|
|
927
|
+
function __promisify__(
|
|
928
|
+
path: PathLike,
|
|
929
|
+
options: StatOptions & {
|
|
930
|
+
bigint: true;
|
|
931
|
+
}
|
|
932
|
+
): Promise<BigIntStats>;
|
|
547
933
|
function __promisify__(path: PathLike, options?: StatOptions): Promise<Stats | BigIntStats>;
|
|
548
934
|
}
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
(
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
935
|
+
export interface StatSyncFn extends Function {
|
|
936
|
+
(path: PathLike, options?: undefined): Stats;
|
|
937
|
+
(
|
|
938
|
+
path: PathLike,
|
|
939
|
+
options?: StatSyncOptions & {
|
|
940
|
+
bigint?: false | undefined;
|
|
941
|
+
throwIfNoEntry: false;
|
|
942
|
+
}
|
|
943
|
+
): Stats | undefined;
|
|
944
|
+
(
|
|
945
|
+
path: PathLike,
|
|
946
|
+
options: StatSyncOptions & {
|
|
947
|
+
bigint: true;
|
|
948
|
+
throwIfNoEntry: false;
|
|
949
|
+
}
|
|
950
|
+
): BigIntStats | undefined;
|
|
951
|
+
(
|
|
952
|
+
path: PathLike,
|
|
953
|
+
options?: StatSyncOptions & {
|
|
954
|
+
bigint?: false | undefined;
|
|
955
|
+
}
|
|
956
|
+
): Stats;
|
|
957
|
+
(
|
|
958
|
+
path: PathLike,
|
|
959
|
+
options: StatSyncOptions & {
|
|
960
|
+
bigint: true;
|
|
961
|
+
}
|
|
962
|
+
): BigIntStats;
|
|
963
|
+
(
|
|
964
|
+
path: PathLike,
|
|
965
|
+
options: StatSyncOptions & {
|
|
966
|
+
bigint: boolean;
|
|
967
|
+
throwIfNoEntry?: false | undefined;
|
|
968
|
+
}
|
|
969
|
+
): Stats | BigIntStats;
|
|
970
|
+
(path: PathLike, options?: StatSyncOptions): Stats | BigIntStats | undefined;
|
|
558
971
|
}
|
|
559
|
-
|
|
560
972
|
/**
|
|
561
973
|
* Synchronous stat(2) - Get file status.
|
|
562
974
|
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
563
975
|
*/
|
|
564
976
|
export const statSync: StatSyncFn;
|
|
565
|
-
|
|
566
977
|
/**
|
|
567
|
-
*
|
|
568
|
-
*
|
|
978
|
+
* Invokes the callback with the `fs.Stats` for the file descriptor.
|
|
979
|
+
*
|
|
980
|
+
* See the POSIX [`fstat(2)`](http://man7.org/linux/man-pages/man2/fstat.2.html) documentation for more detail.
|
|
981
|
+
* @since v0.1.95
|
|
569
982
|
*/
|
|
570
983
|
export function fstat(fd: number, callback: (err: NodeJS.ErrnoException | null, stats: Stats) => void): void;
|
|
571
|
-
export function fstat(
|
|
572
|
-
|
|
984
|
+
export function fstat(
|
|
985
|
+
fd: number,
|
|
986
|
+
options:
|
|
987
|
+
| (StatOptions & {
|
|
988
|
+
bigint?: false | undefined;
|
|
989
|
+
})
|
|
990
|
+
| undefined,
|
|
991
|
+
callback: (err: NodeJS.ErrnoException | null, stats: Stats) => void
|
|
992
|
+
): void;
|
|
993
|
+
export function fstat(
|
|
994
|
+
fd: number,
|
|
995
|
+
options: StatOptions & {
|
|
996
|
+
bigint: true;
|
|
997
|
+
},
|
|
998
|
+
callback: (err: NodeJS.ErrnoException | null, stats: BigIntStats) => void
|
|
999
|
+
): void;
|
|
573
1000
|
export function fstat(fd: number, options: StatOptions | undefined, callback: (err: NodeJS.ErrnoException | null, stats: Stats | BigIntStats) => void): void;
|
|
574
|
-
|
|
575
|
-
// NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
|
|
576
1001
|
export namespace fstat {
|
|
577
1002
|
/**
|
|
578
1003
|
* Asynchronous fstat(2) - Get file status.
|
|
579
1004
|
* @param fd A file descriptor.
|
|
580
1005
|
*/
|
|
581
|
-
function __promisify__(
|
|
582
|
-
|
|
1006
|
+
function __promisify__(
|
|
1007
|
+
fd: number,
|
|
1008
|
+
options?: StatOptions & {
|
|
1009
|
+
bigint?: false | undefined;
|
|
1010
|
+
}
|
|
1011
|
+
): Promise<Stats>;
|
|
1012
|
+
function __promisify__(
|
|
1013
|
+
fd: number,
|
|
1014
|
+
options: StatOptions & {
|
|
1015
|
+
bigint: true;
|
|
1016
|
+
}
|
|
1017
|
+
): Promise<BigIntStats>;
|
|
583
1018
|
function __promisify__(fd: number, options?: StatOptions): Promise<Stats | BigIntStats>;
|
|
584
1019
|
}
|
|
585
|
-
|
|
586
1020
|
/**
|
|
587
|
-
*
|
|
588
|
-
*
|
|
1021
|
+
* Retrieves the `fs.Stats` for the file descriptor.
|
|
1022
|
+
*
|
|
1023
|
+
* See the POSIX [`fstat(2)`](http://man7.org/linux/man-pages/man2/fstat.2.html) documentation for more detail.
|
|
1024
|
+
* @since v0.1.95
|
|
589
1025
|
*/
|
|
590
|
-
export
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
1026
|
+
export function fstatSync(
|
|
1027
|
+
fd: number,
|
|
1028
|
+
options?: StatOptions & {
|
|
1029
|
+
bigint?: false | undefined;
|
|
1030
|
+
}
|
|
1031
|
+
): Stats;
|
|
1032
|
+
export function fstatSync(
|
|
1033
|
+
fd: number,
|
|
1034
|
+
options: StatOptions & {
|
|
1035
|
+
bigint: true;
|
|
1036
|
+
}
|
|
1037
|
+
): BigIntStats;
|
|
1038
|
+
export function fstatSync(fd: number, options?: StatOptions): Stats | BigIntStats;
|
|
1039
|
+
/**
|
|
1040
|
+
* Retrieves the `fs.Stats` for the symbolic link referred to by the path.
|
|
1041
|
+
* The callback gets two arguments `(err, stats)` where `stats` is a `fs.Stats` object. `lstat()` is identical to `stat()`, except that if `path` is a symbolic
|
|
1042
|
+
* link, then the link itself is stat-ed, not the file that it refers to.
|
|
1043
|
+
*
|
|
1044
|
+
* See the POSIX [`lstat(2)`](http://man7.org/linux/man-pages/man2/lstat.2.html) documentation for more details.
|
|
1045
|
+
* @since v0.1.30
|
|
595
1046
|
*/
|
|
596
1047
|
export function lstat(path: PathLike, callback: (err: NodeJS.ErrnoException | null, stats: Stats) => void): void;
|
|
597
|
-
export function lstat(
|
|
598
|
-
|
|
1048
|
+
export function lstat(
|
|
1049
|
+
path: PathLike,
|
|
1050
|
+
options:
|
|
1051
|
+
| (StatOptions & {
|
|
1052
|
+
bigint?: false | undefined;
|
|
1053
|
+
})
|
|
1054
|
+
| undefined,
|
|
1055
|
+
callback: (err: NodeJS.ErrnoException | null, stats: Stats) => void
|
|
1056
|
+
): void;
|
|
1057
|
+
export function lstat(
|
|
1058
|
+
path: PathLike,
|
|
1059
|
+
options: StatOptions & {
|
|
1060
|
+
bigint: true;
|
|
1061
|
+
},
|
|
1062
|
+
callback: (err: NodeJS.ErrnoException | null, stats: BigIntStats) => void
|
|
1063
|
+
): void;
|
|
599
1064
|
export function lstat(path: PathLike, options: StatOptions | undefined, callback: (err: NodeJS.ErrnoException | null, stats: Stats | BigIntStats) => void): void;
|
|
600
|
-
|
|
601
|
-
// NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
|
|
602
1065
|
export namespace lstat {
|
|
603
1066
|
/**
|
|
604
1067
|
* Asynchronous lstat(2) - Get file status. Does not dereference symbolic links.
|
|
605
1068
|
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
606
1069
|
*/
|
|
607
|
-
function __promisify__(
|
|
608
|
-
|
|
1070
|
+
function __promisify__(
|
|
1071
|
+
path: PathLike,
|
|
1072
|
+
options?: StatOptions & {
|
|
1073
|
+
bigint?: false | undefined;
|
|
1074
|
+
}
|
|
1075
|
+
): Promise<Stats>;
|
|
1076
|
+
function __promisify__(
|
|
1077
|
+
path: PathLike,
|
|
1078
|
+
options: StatOptions & {
|
|
1079
|
+
bigint: true;
|
|
1080
|
+
}
|
|
1081
|
+
): Promise<BigIntStats>;
|
|
609
1082
|
function __promisify__(path: PathLike, options?: StatOptions): Promise<Stats | BigIntStats>;
|
|
610
1083
|
}
|
|
611
|
-
|
|
612
1084
|
/**
|
|
613
1085
|
* Synchronous lstat(2) - Get file status. Does not dereference symbolic links.
|
|
614
1086
|
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
615
1087
|
*/
|
|
616
1088
|
export const lstatSync: StatSyncFn;
|
|
617
1089
|
/**
|
|
618
|
-
*
|
|
619
|
-
*
|
|
620
|
-
*
|
|
1090
|
+
* 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. No arguments other than
|
|
1091
|
+
* a possible
|
|
1092
|
+
* exception are given to the completion callback.
|
|
1093
|
+
* @since v0.1.31
|
|
621
1094
|
*/
|
|
622
1095
|
export function link(existingPath: PathLike, newPath: PathLike, callback: NoParamCallback): void;
|
|
623
|
-
|
|
624
|
-
// NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
|
|
625
1096
|
export namespace link {
|
|
626
1097
|
/**
|
|
627
1098
|
* Asynchronous link(2) - Create a new link (also known as a hard link) to an existing file.
|
|
@@ -630,31 +1101,49 @@ declare module 'fs' {
|
|
|
630
1101
|
*/
|
|
631
1102
|
function __promisify__(existingPath: PathLike, newPath: PathLike): Promise<void>;
|
|
632
1103
|
}
|
|
633
|
-
|
|
634
1104
|
/**
|
|
635
|
-
*
|
|
636
|
-
* @
|
|
637
|
-
* @param newPath A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
1105
|
+
* 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. Returns `undefined`.
|
|
1106
|
+
* @since v0.1.31
|
|
638
1107
|
*/
|
|
639
1108
|
export function linkSync(existingPath: PathLike, newPath: PathLike): void;
|
|
640
|
-
|
|
641
1109
|
/**
|
|
642
|
-
*
|
|
643
|
-
*
|
|
644
|
-
*
|
|
645
|
-
*
|
|
646
|
-
*
|
|
1110
|
+
* Creates the link called `path` pointing to `target`. No arguments other than a
|
|
1111
|
+
* possible exception are given to the completion callback.
|
|
1112
|
+
*
|
|
1113
|
+
* See the POSIX [`symlink(2)`](http://man7.org/linux/man-pages/man2/symlink.2.html) documentation for more details.
|
|
1114
|
+
*
|
|
1115
|
+
* The `type` argument is only available on Windows and ignored on other platforms.
|
|
1116
|
+
* It can be set to `'dir'`, `'file'`, or `'junction'`. If the `type` argument is
|
|
1117
|
+
* not set, Node.js will autodetect `target` type and use `'file'` or `'dir'`. If
|
|
1118
|
+
* the `target` does not exist, `'file'` will be used. Windows junction points
|
|
1119
|
+
* require the destination path to be absolute. When using `'junction'`, the`target` argument will automatically be normalized to absolute path.
|
|
1120
|
+
*
|
|
1121
|
+
* Relative targets are relative to the link’s parent directory.
|
|
1122
|
+
*
|
|
1123
|
+
* ```js
|
|
1124
|
+
* import { symlink } from 'fs';
|
|
1125
|
+
*
|
|
1126
|
+
* symlink('./mew', './mewtwo', callback);
|
|
1127
|
+
* ```
|
|
1128
|
+
*
|
|
1129
|
+
* The above example creates a symbolic link `mewtwo` which points to `mew` in the
|
|
1130
|
+
* same directory:
|
|
1131
|
+
*
|
|
1132
|
+
* ```bash
|
|
1133
|
+
* $ tree .
|
|
1134
|
+
* .
|
|
1135
|
+
* ├── mew
|
|
1136
|
+
* └── mewtwo -> ./mew
|
|
1137
|
+
* ```
|
|
1138
|
+
* @since v0.1.31
|
|
647
1139
|
*/
|
|
648
1140
|
export function symlink(target: PathLike, path: PathLike, type: symlink.Type | undefined | null, callback: NoParamCallback): void;
|
|
649
|
-
|
|
650
1141
|
/**
|
|
651
1142
|
* Asynchronous symlink(2) - Create a new symbolic link to an existing file.
|
|
652
1143
|
* @param target A path to an existing file. If a URL is provided, it must use the `file:` protocol.
|
|
653
1144
|
* @param path A path to the new symlink. If a URL is provided, it must use the `file:` protocol.
|
|
654
1145
|
*/
|
|
655
1146
|
export function symlink(target: PathLike, path: PathLike, callback: NoParamCallback): void;
|
|
656
|
-
|
|
657
|
-
// NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
|
|
658
1147
|
export namespace symlink {
|
|
659
1148
|
/**
|
|
660
1149
|
* Asynchronous symlink(2) - Create a new symbolic link to an existing file.
|
|
@@ -664,193 +1153,220 @@ declare module 'fs' {
|
|
|
664
1153
|
* When using `'junction'`, the `target` argument will automatically be normalized to an absolute path.
|
|
665
1154
|
*/
|
|
666
1155
|
function __promisify__(target: PathLike, path: PathLike, type?: string | null): Promise<void>;
|
|
667
|
-
|
|
668
|
-
type Type = "dir" | "file" | "junction";
|
|
1156
|
+
type Type = 'dir' | 'file' | 'junction';
|
|
669
1157
|
}
|
|
670
|
-
|
|
671
1158
|
/**
|
|
672
|
-
*
|
|
673
|
-
*
|
|
674
|
-
*
|
|
675
|
-
*
|
|
676
|
-
*
|
|
1159
|
+
* Returns `undefined`.
|
|
1160
|
+
*
|
|
1161
|
+
* For detailed information, see the documentation of the asynchronous version of
|
|
1162
|
+
* this API: {@link symlink}.
|
|
1163
|
+
* @since v0.1.31
|
|
677
1164
|
*/
|
|
678
1165
|
export function symlinkSync(target: PathLike, path: PathLike, type?: symlink.Type | null): void;
|
|
679
|
-
|
|
680
1166
|
/**
|
|
681
|
-
*
|
|
682
|
-
*
|
|
683
|
-
*
|
|
1167
|
+
* Reads the contents of the symbolic link referred to by `path`. The callback gets
|
|
1168
|
+
* two arguments `(err, linkString)`.
|
|
1169
|
+
*
|
|
1170
|
+
* See the POSIX [`readlink(2)`](http://man7.org/linux/man-pages/man2/readlink.2.html) documentation for more details.
|
|
1171
|
+
*
|
|
1172
|
+
* The optional `options` argument can be a string specifying an encoding, or an
|
|
1173
|
+
* object with an `encoding` property specifying the character encoding to use for
|
|
1174
|
+
* the link path passed to the callback. If the `encoding` is set to `'buffer'`,
|
|
1175
|
+
* the link path returned will be passed as a `Buffer` object.
|
|
1176
|
+
* @since v0.1.31
|
|
684
1177
|
*/
|
|
685
|
-
export function readlink(
|
|
686
|
-
path: PathLike,
|
|
687
|
-
options: BaseEncodingOptions | BufferEncoding | undefined | null,
|
|
688
|
-
callback: (err: NodeJS.ErrnoException | null, linkString: string) => void
|
|
689
|
-
): void;
|
|
690
|
-
|
|
1178
|
+
export function readlink(path: PathLike, options: EncodingOption, callback: (err: NodeJS.ErrnoException | null, linkString: string) => void): void;
|
|
691
1179
|
/**
|
|
692
1180
|
* Asynchronous readlink(2) - read value of a symbolic link.
|
|
693
1181
|
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
694
1182
|
* @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
|
|
695
1183
|
*/
|
|
696
1184
|
export function readlink(path: PathLike, options: BufferEncodingOption, callback: (err: NodeJS.ErrnoException | null, linkString: Buffer) => void): void;
|
|
697
|
-
|
|
698
1185
|
/**
|
|
699
1186
|
* Asynchronous readlink(2) - read value of a symbolic link.
|
|
700
1187
|
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
701
1188
|
* @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
|
|
702
1189
|
*/
|
|
703
|
-
export function readlink(path: PathLike, options:
|
|
704
|
-
|
|
1190
|
+
export function readlink(path: PathLike, options: EncodingOption, callback: (err: NodeJS.ErrnoException | null, linkString: string | Buffer) => void): void;
|
|
705
1191
|
/**
|
|
706
1192
|
* Asynchronous readlink(2) - read value of a symbolic link.
|
|
707
1193
|
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
708
1194
|
*/
|
|
709
1195
|
export function readlink(path: PathLike, callback: (err: NodeJS.ErrnoException | null, linkString: string) => void): void;
|
|
710
|
-
|
|
711
|
-
// NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
|
|
712
1196
|
export namespace readlink {
|
|
713
1197
|
/**
|
|
714
1198
|
* Asynchronous readlink(2) - read value of a symbolic link.
|
|
715
1199
|
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
716
1200
|
* @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
|
|
717
1201
|
*/
|
|
718
|
-
function __promisify__(path: PathLike, options?:
|
|
719
|
-
|
|
1202
|
+
function __promisify__(path: PathLike, options?: EncodingOption): Promise<string>;
|
|
720
1203
|
/**
|
|
721
1204
|
* Asynchronous readlink(2) - read value of a symbolic link.
|
|
722
1205
|
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
723
1206
|
* @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
|
|
724
1207
|
*/
|
|
725
1208
|
function __promisify__(path: PathLike, options: BufferEncodingOption): Promise<Buffer>;
|
|
726
|
-
|
|
727
1209
|
/**
|
|
728
1210
|
* Asynchronous readlink(2) - read value of a symbolic link.
|
|
729
1211
|
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
730
1212
|
* @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
|
|
731
1213
|
*/
|
|
732
|
-
function __promisify__(path: PathLike, options?:
|
|
1214
|
+
function __promisify__(path: PathLike, options?: EncodingOption): Promise<string | Buffer>;
|
|
733
1215
|
}
|
|
734
|
-
|
|
735
1216
|
/**
|
|
736
|
-
*
|
|
737
|
-
*
|
|
738
|
-
*
|
|
1217
|
+
* Returns the symbolic link's string value.
|
|
1218
|
+
*
|
|
1219
|
+
* See the POSIX [`readlink(2)`](http://man7.org/linux/man-pages/man2/readlink.2.html) documentation for more details.
|
|
1220
|
+
*
|
|
1221
|
+
* The optional `options` argument can be a string specifying an encoding, or an
|
|
1222
|
+
* object with an `encoding` property specifying the character encoding to use for
|
|
1223
|
+
* the link path returned. If the `encoding` is set to `'buffer'`,
|
|
1224
|
+
* the link path returned will be passed as a `Buffer` object.
|
|
1225
|
+
* @since v0.1.31
|
|
739
1226
|
*/
|
|
740
|
-
export function readlinkSync(path: PathLike, options?:
|
|
741
|
-
|
|
1227
|
+
export function readlinkSync(path: PathLike, options?: EncodingOption): string;
|
|
742
1228
|
/**
|
|
743
1229
|
* Synchronous readlink(2) - read value of a symbolic link.
|
|
744
1230
|
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
745
1231
|
* @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
|
|
746
1232
|
*/
|
|
747
1233
|
export function readlinkSync(path: PathLike, options: BufferEncodingOption): Buffer;
|
|
748
|
-
|
|
749
1234
|
/**
|
|
750
1235
|
* Synchronous readlink(2) - read value of a symbolic link.
|
|
751
1236
|
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
752
1237
|
* @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
|
|
753
1238
|
*/
|
|
754
|
-
export function readlinkSync(path: PathLike, options?:
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
*
|
|
758
|
-
*
|
|
759
|
-
*
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
1239
|
+
export function readlinkSync(path: PathLike, options?: EncodingOption): string | Buffer;
|
|
1240
|
+
/**
|
|
1241
|
+
* Asynchronously computes the canonical pathname by resolving `.`, `..` and
|
|
1242
|
+
* symbolic links.
|
|
1243
|
+
*
|
|
1244
|
+
* A canonical pathname is not necessarily unique. Hard links and bind mounts can
|
|
1245
|
+
* expose a file system entity through many pathnames.
|
|
1246
|
+
*
|
|
1247
|
+
* This function behaves like [`realpath(3)`](http://man7.org/linux/man-pages/man3/realpath.3.html), with some exceptions:
|
|
1248
|
+
*
|
|
1249
|
+
* 1. No case conversion is performed on case-insensitive file systems.
|
|
1250
|
+
* 2. The maximum number of symbolic links is platform-independent and generally
|
|
1251
|
+
* (much) higher than what the native [`realpath(3)`](http://man7.org/linux/man-pages/man3/realpath.3.html) implementation supports.
|
|
1252
|
+
*
|
|
1253
|
+
* The `callback` gets two arguments `(err, resolvedPath)`. May use `process.cwd`to resolve relative paths.
|
|
1254
|
+
*
|
|
1255
|
+
* Only paths that can be converted to UTF8 strings are supported.
|
|
1256
|
+
*
|
|
1257
|
+
* The optional `options` argument can be a string specifying an encoding, or an
|
|
1258
|
+
* object with an `encoding` property specifying the character encoding to use for
|
|
1259
|
+
* the path passed to the callback. If the `encoding` is set to `'buffer'`,
|
|
1260
|
+
* the path returned will be passed as a `Buffer` object.
|
|
1261
|
+
*
|
|
1262
|
+
* If `path` resolves to a socket or a pipe, the function will return a system
|
|
1263
|
+
* dependent name for that object.
|
|
1264
|
+
* @since v0.1.31
|
|
1265
|
+
*/
|
|
1266
|
+
export function realpath(path: PathLike, options: EncodingOption, callback: (err: NodeJS.ErrnoException | null, resolvedPath: string) => void): void;
|
|
767
1267
|
/**
|
|
768
1268
|
* Asynchronous realpath(3) - return the canonicalized absolute pathname.
|
|
769
1269
|
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
770
1270
|
* @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
|
|
771
1271
|
*/
|
|
772
1272
|
export function realpath(path: PathLike, options: BufferEncodingOption, callback: (err: NodeJS.ErrnoException | null, resolvedPath: Buffer) => void): void;
|
|
773
|
-
|
|
774
1273
|
/**
|
|
775
1274
|
* Asynchronous realpath(3) - return the canonicalized absolute pathname.
|
|
776
1275
|
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
777
1276
|
* @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
|
|
778
1277
|
*/
|
|
779
|
-
export function realpath(path: PathLike, options:
|
|
780
|
-
|
|
1278
|
+
export function realpath(path: PathLike, options: EncodingOption, callback: (err: NodeJS.ErrnoException | null, resolvedPath: string | Buffer) => void): void;
|
|
781
1279
|
/**
|
|
782
1280
|
* Asynchronous realpath(3) - return the canonicalized absolute pathname.
|
|
783
1281
|
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
784
1282
|
*/
|
|
785
1283
|
export function realpath(path: PathLike, callback: (err: NodeJS.ErrnoException | null, resolvedPath: string) => void): void;
|
|
786
|
-
|
|
787
|
-
// NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
|
|
788
1284
|
export namespace realpath {
|
|
789
1285
|
/**
|
|
790
1286
|
* Asynchronous realpath(3) - return the canonicalized absolute pathname.
|
|
791
1287
|
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
792
1288
|
* @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
|
|
793
1289
|
*/
|
|
794
|
-
function __promisify__(path: PathLike, options?:
|
|
795
|
-
|
|
1290
|
+
function __promisify__(path: PathLike, options?: EncodingOption): Promise<string>;
|
|
796
1291
|
/**
|
|
797
1292
|
* Asynchronous realpath(3) - return the canonicalized absolute pathname.
|
|
798
1293
|
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
799
1294
|
* @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
|
|
800
1295
|
*/
|
|
801
1296
|
function __promisify__(path: PathLike, options: BufferEncodingOption): Promise<Buffer>;
|
|
802
|
-
|
|
803
1297
|
/**
|
|
804
1298
|
* Asynchronous realpath(3) - return the canonicalized absolute pathname.
|
|
805
1299
|
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
806
1300
|
* @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
|
|
807
1301
|
*/
|
|
808
|
-
function __promisify__(path: PathLike, options?:
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
1302
|
+
function __promisify__(path: PathLike, options?: EncodingOption): Promise<string | Buffer>;
|
|
1303
|
+
/**
|
|
1304
|
+
* Asynchronous [`realpath(3)`](http://man7.org/linux/man-pages/man3/realpath.3.html).
|
|
1305
|
+
*
|
|
1306
|
+
* The `callback` gets two arguments `(err, resolvedPath)`.
|
|
1307
|
+
*
|
|
1308
|
+
* Only paths that can be converted to UTF8 strings are supported.
|
|
1309
|
+
*
|
|
1310
|
+
* The optional `options` argument can be a string specifying an encoding, or an
|
|
1311
|
+
* object with an `encoding` property specifying the character encoding to use for
|
|
1312
|
+
* the path passed to the callback. If the `encoding` is set to `'buffer'`,
|
|
1313
|
+
* the path returned will be passed as a `Buffer` object.
|
|
1314
|
+
*
|
|
1315
|
+
* On Linux, when Node.js is linked against musl libc, the procfs file system must
|
|
1316
|
+
* be mounted on `/proc` in order for this function to work. Glibc does not have
|
|
1317
|
+
* this restriction.
|
|
1318
|
+
* @since v9.2.0
|
|
1319
|
+
*/
|
|
1320
|
+
function native(path: PathLike, options: EncodingOption, callback: (err: NodeJS.ErrnoException | null, resolvedPath: string) => void): void;
|
|
815
1321
|
function native(path: PathLike, options: BufferEncodingOption, callback: (err: NodeJS.ErrnoException | null, resolvedPath: Buffer) => void): void;
|
|
816
|
-
function native(path: PathLike, options:
|
|
1322
|
+
function native(path: PathLike, options: EncodingOption, callback: (err: NodeJS.ErrnoException | null, resolvedPath: string | Buffer) => void): void;
|
|
817
1323
|
function native(path: PathLike, callback: (err: NodeJS.ErrnoException | null, resolvedPath: string) => void): void;
|
|
818
1324
|
}
|
|
819
|
-
|
|
820
1325
|
/**
|
|
821
|
-
*
|
|
822
|
-
*
|
|
823
|
-
*
|
|
1326
|
+
* Returns the resolved pathname.
|
|
1327
|
+
*
|
|
1328
|
+
* For detailed information, see the documentation of the asynchronous version of
|
|
1329
|
+
* this API: {@link realpath}.
|
|
1330
|
+
* @since v0.1.31
|
|
824
1331
|
*/
|
|
825
|
-
export function realpathSync(path: PathLike, options?:
|
|
826
|
-
|
|
1332
|
+
export function realpathSync(path: PathLike, options?: EncodingOption): string;
|
|
827
1333
|
/**
|
|
828
1334
|
* Synchronous realpath(3) - return the canonicalized absolute pathname.
|
|
829
1335
|
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
830
1336
|
* @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
|
|
831
1337
|
*/
|
|
832
1338
|
export function realpathSync(path: PathLike, options: BufferEncodingOption): Buffer;
|
|
833
|
-
|
|
834
1339
|
/**
|
|
835
1340
|
* Synchronous realpath(3) - return the canonicalized absolute pathname.
|
|
836
1341
|
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
837
1342
|
* @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
|
|
838
1343
|
*/
|
|
839
|
-
export function realpathSync(path: PathLike, options?:
|
|
840
|
-
|
|
1344
|
+
export function realpathSync(path: PathLike, options?: EncodingOption): string | Buffer;
|
|
841
1345
|
export namespace realpathSync {
|
|
842
|
-
function native(path: PathLike, options?:
|
|
1346
|
+
function native(path: PathLike, options?: EncodingOption): string;
|
|
843
1347
|
function native(path: PathLike, options: BufferEncodingOption): Buffer;
|
|
844
|
-
function native(path: PathLike, options?:
|
|
845
|
-
}
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
*
|
|
849
|
-
*
|
|
1348
|
+
function native(path: PathLike, options?: EncodingOption): string | Buffer;
|
|
1349
|
+
}
|
|
1350
|
+
/**
|
|
1351
|
+
* Asynchronously removes a file or symbolic link. No arguments other than a
|
|
1352
|
+
* possible exception are given to the completion callback.
|
|
1353
|
+
*
|
|
1354
|
+
* ```js
|
|
1355
|
+
* import { unlink } from 'fs';
|
|
1356
|
+
* // Assuming that 'path/file.txt' is a regular file.
|
|
1357
|
+
* unlink('path/file.txt', (err) => {
|
|
1358
|
+
* if (err) throw err;
|
|
1359
|
+
* console.log('path/file.txt was deleted');
|
|
1360
|
+
* });
|
|
1361
|
+
* ```
|
|
1362
|
+
*
|
|
1363
|
+
* `fs.unlink()` will not work on a directory, empty or otherwise. To remove a
|
|
1364
|
+
* directory, use {@link rmdir}.
|
|
1365
|
+
*
|
|
1366
|
+
* See the POSIX [`unlink(2)`](http://man7.org/linux/man-pages/man2/unlink.2.html) documentation for more details.
|
|
1367
|
+
* @since v0.0.2
|
|
850
1368
|
*/
|
|
851
1369
|
export function unlink(path: PathLike, callback: NoParamCallback): void;
|
|
852
|
-
|
|
853
|
-
// NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
|
|
854
1370
|
export namespace unlink {
|
|
855
1371
|
/**
|
|
856
1372
|
* Asynchronous unlink(2) - delete a name and possibly the file it refers to.
|
|
@@ -858,13 +1374,11 @@ declare module 'fs' {
|
|
|
858
1374
|
*/
|
|
859
1375
|
function __promisify__(path: PathLike): Promise<void>;
|
|
860
1376
|
}
|
|
861
|
-
|
|
862
1377
|
/**
|
|
863
|
-
* Synchronous unlink(2)
|
|
864
|
-
* @
|
|
1378
|
+
* Synchronous [`unlink(2)`](http://man7.org/linux/man-pages/man2/unlink.2.html). Returns `undefined`.
|
|
1379
|
+
* @since v0.1.21
|
|
865
1380
|
*/
|
|
866
1381
|
export function unlinkSync(path: PathLike): void;
|
|
867
|
-
|
|
868
1382
|
export interface RmDirOptions {
|
|
869
1383
|
/**
|
|
870
1384
|
* If an `EBUSY`, `EMFILE`, `ENFILE`, `ENOTEMPTY`, or
|
|
@@ -874,34 +1388,36 @@ declare module 'fs' {
|
|
|
874
1388
|
* `true`.
|
|
875
1389
|
* @default 0
|
|
876
1390
|
*/
|
|
877
|
-
maxRetries?: number;
|
|
1391
|
+
maxRetries?: number | undefined;
|
|
878
1392
|
/**
|
|
879
|
-
* @deprecated since v14.14.0 In future versions of Node.js
|
|
1393
|
+
* @deprecated since v14.14.0 In future versions of Node.js and will trigger a warning
|
|
880
1394
|
* `fs.rmdir(path, { recursive: true })` will throw if `path` does not exist or is a file.
|
|
881
1395
|
* Use `fs.rm(path, { recursive: true, force: true })` instead.
|
|
882
1396
|
*
|
|
883
1397
|
* If `true`, perform a recursive directory removal. In
|
|
884
|
-
* recursive mode,
|
|
885
|
-
* operations are retried on failure.
|
|
1398
|
+
* recursive mode, operations are retried on failure.
|
|
886
1399
|
* @default false
|
|
887
1400
|
*/
|
|
888
|
-
recursive?: boolean;
|
|
1401
|
+
recursive?: boolean | undefined;
|
|
889
1402
|
/**
|
|
890
1403
|
* The amount of time in milliseconds to wait between retries.
|
|
891
1404
|
* This option is ignored if the `recursive` option is not `true`.
|
|
892
1405
|
* @default 100
|
|
893
1406
|
*/
|
|
894
|
-
retryDelay?: number;
|
|
1407
|
+
retryDelay?: number | undefined;
|
|
895
1408
|
}
|
|
896
|
-
|
|
897
1409
|
/**
|
|
898
|
-
* Asynchronous rmdir(2)
|
|
899
|
-
*
|
|
1410
|
+
* Asynchronous [`rmdir(2)`](http://man7.org/linux/man-pages/man2/rmdir.2.html). No arguments other than a possible exception are given
|
|
1411
|
+
* to the completion callback.
|
|
1412
|
+
*
|
|
1413
|
+
* Using `fs.rmdir()` on a file (not a directory) results in an `ENOENT` error on
|
|
1414
|
+
* Windows and an `ENOTDIR` error on POSIX.
|
|
1415
|
+
*
|
|
1416
|
+
* To get a behavior similar to the `rm -rf` Unix command, use {@link rm} with options `{ recursive: true, force: true }`.
|
|
1417
|
+
* @since v0.0.2
|
|
900
1418
|
*/
|
|
901
1419
|
export function rmdir(path: PathLike, callback: NoParamCallback): void;
|
|
902
1420
|
export function rmdir(path: PathLike, options: RmDirOptions, callback: NoParamCallback): void;
|
|
903
|
-
|
|
904
|
-
// NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
|
|
905
1421
|
export namespace rmdir {
|
|
906
1422
|
/**
|
|
907
1423
|
* Asynchronous rmdir(2) - delete a directory.
|
|
@@ -909,19 +1425,22 @@ declare module 'fs' {
|
|
|
909
1425
|
*/
|
|
910
1426
|
function __promisify__(path: PathLike, options?: RmDirOptions): Promise<void>;
|
|
911
1427
|
}
|
|
912
|
-
|
|
913
1428
|
/**
|
|
914
|
-
* Synchronous rmdir(2)
|
|
915
|
-
*
|
|
1429
|
+
* Synchronous [`rmdir(2)`](http://man7.org/linux/man-pages/man2/rmdir.2.html). Returns `undefined`.
|
|
1430
|
+
*
|
|
1431
|
+
* Using `fs.rmdirSync()` on a file (not a directory) results in an `ENOENT` error
|
|
1432
|
+
* on Windows and an `ENOTDIR` error on POSIX.
|
|
1433
|
+
*
|
|
1434
|
+
* To get a behavior similar to the `rm -rf` Unix command, use {@link rmSync} with options `{ recursive: true, force: true }`.
|
|
1435
|
+
* @since v0.1.21
|
|
916
1436
|
*/
|
|
917
1437
|
export function rmdirSync(path: PathLike, options?: RmDirOptions): void;
|
|
918
|
-
|
|
919
1438
|
export interface RmOptions {
|
|
920
1439
|
/**
|
|
921
1440
|
* When `true`, exceptions will be ignored if `path` does not exist.
|
|
922
1441
|
* @default false
|
|
923
1442
|
*/
|
|
924
|
-
force?: boolean;
|
|
1443
|
+
force?: boolean | undefined;
|
|
925
1444
|
/**
|
|
926
1445
|
* If an `EBUSY`, `EMFILE`, `ENFILE`, `ENOTEMPTY`, or
|
|
927
1446
|
* `EPERM` error is encountered, Node.js will retry the operation with a linear
|
|
@@ -930,71 +1449,110 @@ declare module 'fs' {
|
|
|
930
1449
|
* `true`.
|
|
931
1450
|
* @default 0
|
|
932
1451
|
*/
|
|
933
|
-
maxRetries?: number;
|
|
1452
|
+
maxRetries?: number | undefined;
|
|
934
1453
|
/**
|
|
935
1454
|
* If `true`, perform a recursive directory removal. In
|
|
936
|
-
* recursive mode,
|
|
937
|
-
* operations are retried on failure.
|
|
1455
|
+
* recursive mode, operations are retried on failure.
|
|
938
1456
|
* @default false
|
|
939
1457
|
*/
|
|
940
|
-
recursive?: boolean;
|
|
1458
|
+
recursive?: boolean | undefined;
|
|
941
1459
|
/**
|
|
942
1460
|
* The amount of time in milliseconds to wait between retries.
|
|
943
1461
|
* This option is ignored if the `recursive` option is not `true`.
|
|
944
1462
|
* @default 100
|
|
945
1463
|
*/
|
|
946
|
-
retryDelay?: number;
|
|
1464
|
+
retryDelay?: number | undefined;
|
|
947
1465
|
}
|
|
948
|
-
|
|
949
1466
|
/**
|
|
950
|
-
* Asynchronously removes files and directories (modeled on the standard POSIX `rm`
|
|
1467
|
+
* Asynchronously removes files and directories (modeled on the standard POSIX `rm`utility). No arguments other than a possible exception are given to the
|
|
1468
|
+
* completion callback.
|
|
1469
|
+
* @since v14.14.0
|
|
951
1470
|
*/
|
|
952
1471
|
export function rm(path: PathLike, callback: NoParamCallback): void;
|
|
953
1472
|
export function rm(path: PathLike, options: RmOptions, callback: NoParamCallback): void;
|
|
954
|
-
|
|
955
|
-
// NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
|
|
956
1473
|
export namespace rm {
|
|
957
1474
|
/**
|
|
958
1475
|
* Asynchronously removes files and directories (modeled on the standard POSIX `rm` utility).
|
|
959
1476
|
*/
|
|
960
1477
|
function __promisify__(path: PathLike, options?: RmOptions): Promise<void>;
|
|
961
1478
|
}
|
|
962
|
-
|
|
963
1479
|
/**
|
|
964
|
-
* Synchronously removes files and directories (modeled on the standard POSIX `rm`
|
|
1480
|
+
* Synchronously removes files and directories (modeled on the standard POSIX `rm`utility). Returns `undefined`.
|
|
1481
|
+
* @since v14.14.0
|
|
965
1482
|
*/
|
|
966
1483
|
export function rmSync(path: PathLike, options?: RmOptions): void;
|
|
967
|
-
|
|
968
1484
|
export interface MakeDirectoryOptions {
|
|
969
1485
|
/**
|
|
970
1486
|
* Indicates whether parent folders should be created.
|
|
971
1487
|
* If a folder was created, the path to the first created folder will be returned.
|
|
972
1488
|
* @default false
|
|
973
1489
|
*/
|
|
974
|
-
recursive?: boolean;
|
|
1490
|
+
recursive?: boolean | undefined;
|
|
975
1491
|
/**
|
|
976
1492
|
* A file mode. If a string is passed, it is parsed as an octal integer. If not specified
|
|
977
1493
|
* @default 0o777
|
|
978
1494
|
*/
|
|
979
|
-
mode?: Mode;
|
|
980
|
-
}
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
*
|
|
984
|
-
*
|
|
985
|
-
*
|
|
986
|
-
*
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
1495
|
+
mode?: Mode | undefined;
|
|
1496
|
+
}
|
|
1497
|
+
/**
|
|
1498
|
+
* Asynchronously creates a directory.
|
|
1499
|
+
*
|
|
1500
|
+
* The callback is given a possible exception and, if `recursive` is `true`, the
|
|
1501
|
+
* first directory path created, `(err[, path])`.`path` can still be `undefined` when `recursive` is `true`, if no directory was
|
|
1502
|
+
* created.
|
|
1503
|
+
*
|
|
1504
|
+
* The optional `options` argument can be an integer specifying `mode` (permission
|
|
1505
|
+
* and sticky bits), or an object with a `mode` property and a `recursive`property indicating whether parent directories should be created. Calling`fs.mkdir()` when `path` is a directory that
|
|
1506
|
+
* exists results in an error only
|
|
1507
|
+
* when `recursive` is false.
|
|
1508
|
+
*
|
|
1509
|
+
* ```js
|
|
1510
|
+
* import { mkdir } from 'fs';
|
|
1511
|
+
*
|
|
1512
|
+
* // Creates /tmp/a/apple, regardless of whether `/tmp` and /tmp/a exist.
|
|
1513
|
+
* mkdir('/tmp/a/apple', { recursive: true }, (err) => {
|
|
1514
|
+
* if (err) throw err;
|
|
1515
|
+
* });
|
|
1516
|
+
* ```
|
|
1517
|
+
*
|
|
1518
|
+
* On Windows, using `fs.mkdir()` on the root directory even with recursion will
|
|
1519
|
+
* result in an error:
|
|
1520
|
+
*
|
|
1521
|
+
* ```js
|
|
1522
|
+
* import { mkdir } from 'fs';
|
|
1523
|
+
*
|
|
1524
|
+
* mkdir('/', { recursive: true }, (err) => {
|
|
1525
|
+
* // => [Error: EPERM: operation not permitted, mkdir 'C:\']
|
|
1526
|
+
* });
|
|
1527
|
+
* ```
|
|
1528
|
+
*
|
|
1529
|
+
* See the POSIX [`mkdir(2)`](http://man7.org/linux/man-pages/man2/mkdir.2.html) documentation for more details.
|
|
1530
|
+
* @since v0.1.8
|
|
1531
|
+
*/
|
|
1532
|
+
export function mkdir(
|
|
1533
|
+
path: PathLike,
|
|
1534
|
+
options: MakeDirectoryOptions & {
|
|
1535
|
+
recursive: true;
|
|
1536
|
+
},
|
|
1537
|
+
callback: (err: NodeJS.ErrnoException | null, path?: string) => void
|
|
1538
|
+
): void;
|
|
990
1539
|
/**
|
|
991
1540
|
* Asynchronous mkdir(2) - create a directory.
|
|
992
1541
|
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
993
1542
|
* @param options Either the file mode, or an object optionally specifying the file mode and whether parent folders
|
|
994
1543
|
* should be created. If a string is passed, it is parsed as an octal integer. If not specified, defaults to `0o777`.
|
|
995
1544
|
*/
|
|
996
|
-
export function mkdir(
|
|
997
|
-
|
|
1545
|
+
export function mkdir(
|
|
1546
|
+
path: PathLike,
|
|
1547
|
+
options:
|
|
1548
|
+
| Mode
|
|
1549
|
+
| (MakeDirectoryOptions & {
|
|
1550
|
+
recursive?: false | undefined;
|
|
1551
|
+
})
|
|
1552
|
+
| null
|
|
1553
|
+
| undefined,
|
|
1554
|
+
callback: NoParamCallback
|
|
1555
|
+
): void;
|
|
998
1556
|
/**
|
|
999
1557
|
* Asynchronous mkdir(2) - create a directory.
|
|
1000
1558
|
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
@@ -1002,14 +1560,11 @@ declare module 'fs' {
|
|
|
1002
1560
|
* should be created. If a string is passed, it is parsed as an octal integer. If not specified, defaults to `0o777`.
|
|
1003
1561
|
*/
|
|
1004
1562
|
export function mkdir(path: PathLike, options: Mode | MakeDirectoryOptions | null | undefined, callback: (err: NodeJS.ErrnoException | null, path?: string) => void): void;
|
|
1005
|
-
|
|
1006
1563
|
/**
|
|
1007
1564
|
* Asynchronous mkdir(2) - create a directory with a mode of `0o777`.
|
|
1008
1565
|
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
1009
1566
|
*/
|
|
1010
1567
|
export function mkdir(path: PathLike, callback: NoParamCallback): void;
|
|
1011
|
-
|
|
1012
|
-
// NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
|
|
1013
1568
|
export namespace mkdir {
|
|
1014
1569
|
/**
|
|
1015
1570
|
* Asynchronous mkdir(2) - create a directory.
|
|
@@ -1017,16 +1572,27 @@ declare module 'fs' {
|
|
|
1017
1572
|
* @param options Either the file mode, or an object optionally specifying the file mode and whether parent folders
|
|
1018
1573
|
* should be created. If a string is passed, it is parsed as an octal integer. If not specified, defaults to `0o777`.
|
|
1019
1574
|
*/
|
|
1020
|
-
function __promisify__(
|
|
1021
|
-
|
|
1575
|
+
function __promisify__(
|
|
1576
|
+
path: PathLike,
|
|
1577
|
+
options: MakeDirectoryOptions & {
|
|
1578
|
+
recursive: true;
|
|
1579
|
+
}
|
|
1580
|
+
): Promise<string | undefined>;
|
|
1022
1581
|
/**
|
|
1023
1582
|
* Asynchronous mkdir(2) - create a directory.
|
|
1024
1583
|
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
1025
1584
|
* @param options Either the file mode, or an object optionally specifying the file mode and whether parent folders
|
|
1026
1585
|
* should be created. If a string is passed, it is parsed as an octal integer. If not specified, defaults to `0o777`.
|
|
1027
1586
|
*/
|
|
1028
|
-
function __promisify__(
|
|
1029
|
-
|
|
1587
|
+
function __promisify__(
|
|
1588
|
+
path: PathLike,
|
|
1589
|
+
options?:
|
|
1590
|
+
| Mode
|
|
1591
|
+
| (MakeDirectoryOptions & {
|
|
1592
|
+
recursive?: false | undefined;
|
|
1593
|
+
})
|
|
1594
|
+
| null
|
|
1595
|
+
): Promise<void>;
|
|
1030
1596
|
/**
|
|
1031
1597
|
* Asynchronous mkdir(2) - create a directory.
|
|
1032
1598
|
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
@@ -1035,23 +1601,34 @@ declare module 'fs' {
|
|
|
1035
1601
|
*/
|
|
1036
1602
|
function __promisify__(path: PathLike, options?: Mode | MakeDirectoryOptions | null): Promise<string | undefined>;
|
|
1037
1603
|
}
|
|
1038
|
-
|
|
1039
1604
|
/**
|
|
1040
|
-
*
|
|
1041
|
-
*
|
|
1042
|
-
*
|
|
1043
|
-
*
|
|
1605
|
+
* Synchronously creates a directory. Returns `undefined`, or if `recursive` is`true`, the first directory path created.
|
|
1606
|
+
* This is the synchronous version of {@link mkdir}.
|
|
1607
|
+
*
|
|
1608
|
+
* See the POSIX [`mkdir(2)`](http://man7.org/linux/man-pages/man2/mkdir.2.html) documentation for more details.
|
|
1609
|
+
* @since v0.1.21
|
|
1044
1610
|
*/
|
|
1045
|
-
export function mkdirSync(
|
|
1046
|
-
|
|
1611
|
+
export function mkdirSync(
|
|
1612
|
+
path: PathLike,
|
|
1613
|
+
options: MakeDirectoryOptions & {
|
|
1614
|
+
recursive: true;
|
|
1615
|
+
}
|
|
1616
|
+
): string | undefined;
|
|
1047
1617
|
/**
|
|
1048
1618
|
* Synchronous mkdir(2) - create a directory.
|
|
1049
1619
|
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
1050
1620
|
* @param options Either the file mode, or an object optionally specifying the file mode and whether parent folders
|
|
1051
1621
|
* should be created. If a string is passed, it is parsed as an octal integer. If not specified, defaults to `0o777`.
|
|
1052
1622
|
*/
|
|
1053
|
-
export function mkdirSync(
|
|
1054
|
-
|
|
1623
|
+
export function mkdirSync(
|
|
1624
|
+
path: PathLike,
|
|
1625
|
+
options?:
|
|
1626
|
+
| Mode
|
|
1627
|
+
| (MakeDirectoryOptions & {
|
|
1628
|
+
recursive?: false | undefined;
|
|
1629
|
+
})
|
|
1630
|
+
| null
|
|
1631
|
+
): void;
|
|
1055
1632
|
/**
|
|
1056
1633
|
* Synchronous mkdir(2) - create a directory.
|
|
1057
1634
|
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
@@ -1059,97 +1636,172 @@ declare module 'fs' {
|
|
|
1059
1636
|
* should be created. If a string is passed, it is parsed as an octal integer. If not specified, defaults to `0o777`.
|
|
1060
1637
|
*/
|
|
1061
1638
|
export function mkdirSync(path: PathLike, options?: Mode | MakeDirectoryOptions | null): string | undefined;
|
|
1062
|
-
|
|
1063
1639
|
/**
|
|
1064
|
-
*
|
|
1065
|
-
*
|
|
1066
|
-
*
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1640
|
+
* Creates a unique temporary directory.
|
|
1641
|
+
*
|
|
1642
|
+
* Generates six random characters to be appended behind a required`prefix` to create a unique temporary directory. Due to platform
|
|
1643
|
+
* inconsistencies, avoid trailing `X` characters in `prefix`. Some platforms,
|
|
1644
|
+
* notably the BSDs, can return more than six random characters, and replace
|
|
1645
|
+
* trailing `X` characters in `prefix` with random characters.
|
|
1646
|
+
*
|
|
1647
|
+
* The created directory path is passed as a string to the callback's second
|
|
1648
|
+
* parameter.
|
|
1649
|
+
*
|
|
1650
|
+
* The optional `options` argument can be a string specifying an encoding, or an
|
|
1651
|
+
* object with an `encoding` property specifying the character encoding to use.
|
|
1652
|
+
*
|
|
1653
|
+
* ```js
|
|
1654
|
+
* import { mkdtemp } from 'fs';
|
|
1655
|
+
*
|
|
1656
|
+
* mkdtemp(path.join(os.tmpdir(), 'foo-'), (err, directory) => {
|
|
1657
|
+
* if (err) throw err;
|
|
1658
|
+
* console.log(directory);
|
|
1659
|
+
* // Prints: /tmp/foo-itXde2 or C:\Users\...\AppData\Local\Temp\foo-itXde2
|
|
1660
|
+
* });
|
|
1661
|
+
* ```
|
|
1662
|
+
*
|
|
1663
|
+
* The `fs.mkdtemp()` method will append the six randomly selected characters
|
|
1664
|
+
* directly to the `prefix` string. For instance, given a directory `/tmp`, if the
|
|
1665
|
+
* intention is to create a temporary directory _within_`/tmp`, the `prefix`must end with a trailing platform-specific path separator
|
|
1666
|
+
* (`require('path').sep`).
|
|
1667
|
+
*
|
|
1668
|
+
* ```js
|
|
1669
|
+
* import { tmpdir } from 'os';
|
|
1670
|
+
* import { mkdtemp } from 'fs';
|
|
1671
|
+
*
|
|
1672
|
+
* // The parent directory for the new temporary directory
|
|
1673
|
+
* const tmpDir = tmpdir();
|
|
1674
|
+
*
|
|
1675
|
+
* // This method is *INCORRECT*:
|
|
1676
|
+
* mkdtemp(tmpDir, (err, directory) => {
|
|
1677
|
+
* if (err) throw err;
|
|
1678
|
+
* console.log(directory);
|
|
1679
|
+
* // Will print something similar to `/tmpabc123`.
|
|
1680
|
+
* // A new temporary directory is created at the file system root
|
|
1681
|
+
* // rather than *within* the /tmp directory.
|
|
1682
|
+
* });
|
|
1683
|
+
*
|
|
1684
|
+
* // This method is *CORRECT*:
|
|
1685
|
+
* import { sep } from 'path';
|
|
1686
|
+
* mkdtemp(`${tmpDir}${sep}`, (err, directory) => {
|
|
1687
|
+
* if (err) throw err;
|
|
1688
|
+
* console.log(directory);
|
|
1689
|
+
* // Will print something similar to `/tmp/abc123`.
|
|
1690
|
+
* // A new temporary directory is created within
|
|
1691
|
+
* // the /tmp directory.
|
|
1692
|
+
* });
|
|
1693
|
+
* ```
|
|
1694
|
+
* @since v5.10.0
|
|
1695
|
+
*/
|
|
1696
|
+
export function mkdtemp(prefix: string, options: EncodingOption, callback: (err: NodeJS.ErrnoException | null, folder: string) => void): void;
|
|
1070
1697
|
/**
|
|
1071
1698
|
* Asynchronously creates a unique temporary directory.
|
|
1072
1699
|
* Generates six random characters to be appended behind a required prefix to create a unique temporary directory.
|
|
1073
1700
|
* @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
|
|
1074
1701
|
*/
|
|
1075
|
-
export function mkdtemp(
|
|
1076
|
-
|
|
1702
|
+
export function mkdtemp(
|
|
1703
|
+
prefix: string,
|
|
1704
|
+
options:
|
|
1705
|
+
| 'buffer'
|
|
1706
|
+
| {
|
|
1707
|
+
encoding: 'buffer';
|
|
1708
|
+
},
|
|
1709
|
+
callback: (err: NodeJS.ErrnoException | null, folder: Buffer) => void
|
|
1710
|
+
): void;
|
|
1077
1711
|
/**
|
|
1078
1712
|
* Asynchronously creates a unique temporary directory.
|
|
1079
1713
|
* Generates six random characters to be appended behind a required prefix to create a unique temporary directory.
|
|
1080
1714
|
* @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
|
|
1081
1715
|
*/
|
|
1082
|
-
export function mkdtemp(prefix: string, options:
|
|
1083
|
-
|
|
1716
|
+
export function mkdtemp(prefix: string, options: EncodingOption, callback: (err: NodeJS.ErrnoException | null, folder: string | Buffer) => void): void;
|
|
1084
1717
|
/**
|
|
1085
1718
|
* Asynchronously creates a unique temporary directory.
|
|
1086
1719
|
* Generates six random characters to be appended behind a required prefix to create a unique temporary directory.
|
|
1087
1720
|
*/
|
|
1088
1721
|
export function mkdtemp(prefix: string, callback: (err: NodeJS.ErrnoException | null, folder: string) => void): void;
|
|
1089
|
-
|
|
1090
|
-
// NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
|
|
1091
1722
|
export namespace mkdtemp {
|
|
1092
1723
|
/**
|
|
1093
1724
|
* Asynchronously creates a unique temporary directory.
|
|
1094
1725
|
* Generates six random characters to be appended behind a required prefix to create a unique temporary directory.
|
|
1095
1726
|
* @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
|
|
1096
1727
|
*/
|
|
1097
|
-
function __promisify__(prefix: string, options?:
|
|
1098
|
-
|
|
1728
|
+
function __promisify__(prefix: string, options?: EncodingOption): Promise<string>;
|
|
1099
1729
|
/**
|
|
1100
1730
|
* Asynchronously creates a unique temporary directory.
|
|
1101
1731
|
* Generates six random characters to be appended behind a required prefix to create a unique temporary directory.
|
|
1102
1732
|
* @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
|
|
1103
1733
|
*/
|
|
1104
1734
|
function __promisify__(prefix: string, options: BufferEncodingOption): Promise<Buffer>;
|
|
1105
|
-
|
|
1106
1735
|
/**
|
|
1107
1736
|
* Asynchronously creates a unique temporary directory.
|
|
1108
1737
|
* Generates six random characters to be appended behind a required prefix to create a unique temporary directory.
|
|
1109
1738
|
* @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
|
|
1110
1739
|
*/
|
|
1111
|
-
function __promisify__(prefix: string, options?:
|
|
1740
|
+
function __promisify__(prefix: string, options?: EncodingOption): Promise<string | Buffer>;
|
|
1112
1741
|
}
|
|
1113
|
-
|
|
1114
1742
|
/**
|
|
1115
|
-
*
|
|
1116
|
-
*
|
|
1117
|
-
*
|
|
1743
|
+
* Returns the created directory path.
|
|
1744
|
+
*
|
|
1745
|
+
* For detailed information, see the documentation of the asynchronous version of
|
|
1746
|
+
* this API: {@link mkdtemp}.
|
|
1747
|
+
*
|
|
1748
|
+
* The optional `options` argument can be a string specifying an encoding, or an
|
|
1749
|
+
* object with an `encoding` property specifying the character encoding to use.
|
|
1750
|
+
* @since v5.10.0
|
|
1118
1751
|
*/
|
|
1119
|
-
export function mkdtempSync(prefix: string, options?:
|
|
1120
|
-
|
|
1752
|
+
export function mkdtempSync(prefix: string, options?: EncodingOption): string;
|
|
1121
1753
|
/**
|
|
1122
1754
|
* Synchronously creates a unique temporary directory.
|
|
1123
1755
|
* Generates six random characters to be appended behind a required prefix to create a unique temporary directory.
|
|
1124
1756
|
* @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
|
|
1125
1757
|
*/
|
|
1126
1758
|
export function mkdtempSync(prefix: string, options: BufferEncodingOption): Buffer;
|
|
1127
|
-
|
|
1128
1759
|
/**
|
|
1129
1760
|
* Synchronously creates a unique temporary directory.
|
|
1130
1761
|
* Generates six random characters to be appended behind a required prefix to create a unique temporary directory.
|
|
1131
1762
|
* @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
|
|
1132
1763
|
*/
|
|
1133
|
-
export function mkdtempSync(prefix: string, options?:
|
|
1134
|
-
|
|
1764
|
+
export function mkdtempSync(prefix: string, options?: EncodingOption): string | Buffer;
|
|
1135
1765
|
/**
|
|
1136
|
-
*
|
|
1137
|
-
*
|
|
1138
|
-
*
|
|
1766
|
+
* Reads the contents of a directory. The callback gets two arguments `(err, files)`where `files` is an array of the names of the files in the directory excluding`'.'` and `'..'`.
|
|
1767
|
+
*
|
|
1768
|
+
* See the POSIX [`readdir(3)`](http://man7.org/linux/man-pages/man3/readdir.3.html) documentation for more details.
|
|
1769
|
+
*
|
|
1770
|
+
* The optional `options` argument can be a string specifying an encoding, or an
|
|
1771
|
+
* object with an `encoding` property specifying the character encoding to use for
|
|
1772
|
+
* the filenames passed to the callback. If the `encoding` is set to `'buffer'`,
|
|
1773
|
+
* the filenames returned will be passed as `Buffer` objects.
|
|
1774
|
+
*
|
|
1775
|
+
* If `options.withFileTypes` is set to `true`, the `files` array will contain `fs.Dirent` objects.
|
|
1776
|
+
* @since v0.1.8
|
|
1139
1777
|
*/
|
|
1140
1778
|
export function readdir(
|
|
1141
1779
|
path: PathLike,
|
|
1142
|
-
options:
|
|
1143
|
-
|
|
1780
|
+
options:
|
|
1781
|
+
| {
|
|
1782
|
+
encoding: BufferEncoding | null;
|
|
1783
|
+
withFileTypes?: false | undefined;
|
|
1784
|
+
}
|
|
1785
|
+
| BufferEncoding
|
|
1786
|
+
| undefined
|
|
1787
|
+
| null,
|
|
1788
|
+
callback: (err: NodeJS.ErrnoException | null, files: string[]) => void
|
|
1144
1789
|
): void;
|
|
1145
|
-
|
|
1146
1790
|
/**
|
|
1147
1791
|
* Asynchronous readdir(3) - read a directory.
|
|
1148
1792
|
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
1149
1793
|
* @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
|
|
1150
1794
|
*/
|
|
1151
|
-
export function readdir(
|
|
1152
|
-
|
|
1795
|
+
export function readdir(
|
|
1796
|
+
path: PathLike,
|
|
1797
|
+
options:
|
|
1798
|
+
| {
|
|
1799
|
+
encoding: 'buffer';
|
|
1800
|
+
withFileTypes?: false | undefined;
|
|
1801
|
+
}
|
|
1802
|
+
| 'buffer',
|
|
1803
|
+
callback: (err: NodeJS.ErrnoException | null, files: Buffer[]) => void
|
|
1804
|
+
): void;
|
|
1153
1805
|
/**
|
|
1154
1806
|
* Asynchronous readdir(3) - read a directory.
|
|
1155
1807
|
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
@@ -1157,89 +1809,161 @@ declare module 'fs' {
|
|
|
1157
1809
|
*/
|
|
1158
1810
|
export function readdir(
|
|
1159
1811
|
path: PathLike,
|
|
1160
|
-
options:
|
|
1161
|
-
|
|
1812
|
+
options:
|
|
1813
|
+
| (ObjectEncodingOptions & {
|
|
1814
|
+
withFileTypes?: false | undefined;
|
|
1815
|
+
})
|
|
1816
|
+
| BufferEncoding
|
|
1817
|
+
| undefined
|
|
1818
|
+
| null,
|
|
1819
|
+
callback: (err: NodeJS.ErrnoException | null, files: string[] | Buffer[]) => void
|
|
1162
1820
|
): void;
|
|
1163
|
-
|
|
1164
1821
|
/**
|
|
1165
1822
|
* Asynchronous readdir(3) - read a directory.
|
|
1166
1823
|
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
1167
1824
|
*/
|
|
1168
1825
|
export function readdir(path: PathLike, callback: (err: NodeJS.ErrnoException | null, files: string[]) => void): void;
|
|
1169
|
-
|
|
1170
1826
|
/**
|
|
1171
1827
|
* Asynchronous readdir(3) - read a directory.
|
|
1172
1828
|
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
1173
1829
|
* @param options If called with `withFileTypes: true` the result data will be an array of Dirent.
|
|
1174
1830
|
*/
|
|
1175
|
-
export function readdir(
|
|
1176
|
-
|
|
1177
|
-
|
|
1831
|
+
export function readdir(
|
|
1832
|
+
path: PathLike,
|
|
1833
|
+
options: ObjectEncodingOptions & {
|
|
1834
|
+
withFileTypes: true;
|
|
1835
|
+
},
|
|
1836
|
+
callback: (err: NodeJS.ErrnoException | null, files: Dirent[]) => void
|
|
1837
|
+
): void;
|
|
1178
1838
|
export namespace readdir {
|
|
1179
1839
|
/**
|
|
1180
1840
|
* Asynchronous readdir(3) - read a directory.
|
|
1181
1841
|
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
1182
1842
|
* @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
|
|
1183
1843
|
*/
|
|
1184
|
-
function __promisify__(
|
|
1185
|
-
|
|
1844
|
+
function __promisify__(
|
|
1845
|
+
path: PathLike,
|
|
1846
|
+
options?:
|
|
1847
|
+
| {
|
|
1848
|
+
encoding: BufferEncoding | null;
|
|
1849
|
+
withFileTypes?: false | undefined;
|
|
1850
|
+
}
|
|
1851
|
+
| BufferEncoding
|
|
1852
|
+
| null
|
|
1853
|
+
): Promise<string[]>;
|
|
1186
1854
|
/**
|
|
1187
1855
|
* Asynchronous readdir(3) - read a directory.
|
|
1188
1856
|
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
1189
1857
|
* @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
|
|
1190
1858
|
*/
|
|
1191
|
-
function __promisify__(
|
|
1192
|
-
|
|
1859
|
+
function __promisify__(
|
|
1860
|
+
path: PathLike,
|
|
1861
|
+
options:
|
|
1862
|
+
| 'buffer'
|
|
1863
|
+
| {
|
|
1864
|
+
encoding: 'buffer';
|
|
1865
|
+
withFileTypes?: false | undefined;
|
|
1866
|
+
}
|
|
1867
|
+
): Promise<Buffer[]>;
|
|
1193
1868
|
/**
|
|
1194
1869
|
* Asynchronous readdir(3) - read a directory.
|
|
1195
1870
|
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
1196
1871
|
* @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
|
|
1197
1872
|
*/
|
|
1198
|
-
function __promisify__(
|
|
1199
|
-
|
|
1873
|
+
function __promisify__(
|
|
1874
|
+
path: PathLike,
|
|
1875
|
+
options?:
|
|
1876
|
+
| (ObjectEncodingOptions & {
|
|
1877
|
+
withFileTypes?: false | undefined;
|
|
1878
|
+
})
|
|
1879
|
+
| BufferEncoding
|
|
1880
|
+
| null
|
|
1881
|
+
): Promise<string[] | Buffer[]>;
|
|
1200
1882
|
/**
|
|
1201
1883
|
* Asynchronous readdir(3) - read a directory.
|
|
1202
1884
|
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
1203
1885
|
* @param options If called with `withFileTypes: true` the result data will be an array of Dirent
|
|
1204
1886
|
*/
|
|
1205
|
-
function __promisify__(
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1887
|
+
function __promisify__(
|
|
1888
|
+
path: PathLike,
|
|
1889
|
+
options: ObjectEncodingOptions & {
|
|
1890
|
+
withFileTypes: true;
|
|
1891
|
+
}
|
|
1892
|
+
): Promise<Dirent[]>;
|
|
1893
|
+
}
|
|
1894
|
+
/**
|
|
1895
|
+
* Reads the contents of the directory.
|
|
1896
|
+
*
|
|
1897
|
+
* See the POSIX [`readdir(3)`](http://man7.org/linux/man-pages/man3/readdir.3.html) documentation for more details.
|
|
1898
|
+
*
|
|
1899
|
+
* The optional `options` argument can be a string specifying an encoding, or an
|
|
1900
|
+
* object with an `encoding` property specifying the character encoding to use for
|
|
1901
|
+
* the filenames returned. If the `encoding` is set to `'buffer'`,
|
|
1902
|
+
* the filenames returned will be passed as `Buffer` objects.
|
|
1903
|
+
*
|
|
1904
|
+
* If `options.withFileTypes` is set to `true`, the result will contain `fs.Dirent` objects.
|
|
1905
|
+
* @since v0.1.21
|
|
1906
|
+
*/
|
|
1907
|
+
export function readdirSync(
|
|
1908
|
+
path: PathLike,
|
|
1909
|
+
options?:
|
|
1910
|
+
| {
|
|
1911
|
+
encoding: BufferEncoding | null;
|
|
1912
|
+
withFileTypes?: false | undefined;
|
|
1913
|
+
}
|
|
1914
|
+
| BufferEncoding
|
|
1915
|
+
| null
|
|
1916
|
+
): string[];
|
|
1215
1917
|
/**
|
|
1216
1918
|
* Synchronous readdir(3) - read a directory.
|
|
1217
1919
|
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
1218
1920
|
* @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
|
|
1219
1921
|
*/
|
|
1220
|
-
export function readdirSync(
|
|
1221
|
-
|
|
1922
|
+
export function readdirSync(
|
|
1923
|
+
path: PathLike,
|
|
1924
|
+
options:
|
|
1925
|
+
| {
|
|
1926
|
+
encoding: 'buffer';
|
|
1927
|
+
withFileTypes?: false | undefined;
|
|
1928
|
+
}
|
|
1929
|
+
| 'buffer'
|
|
1930
|
+
): Buffer[];
|
|
1222
1931
|
/**
|
|
1223
1932
|
* Synchronous readdir(3) - read a directory.
|
|
1224
1933
|
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
1225
1934
|
* @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
|
|
1226
1935
|
*/
|
|
1227
|
-
export function readdirSync(
|
|
1228
|
-
|
|
1936
|
+
export function readdirSync(
|
|
1937
|
+
path: PathLike,
|
|
1938
|
+
options?:
|
|
1939
|
+
| (ObjectEncodingOptions & {
|
|
1940
|
+
withFileTypes?: false | undefined;
|
|
1941
|
+
})
|
|
1942
|
+
| BufferEncoding
|
|
1943
|
+
| null
|
|
1944
|
+
): string[] | Buffer[];
|
|
1229
1945
|
/**
|
|
1230
1946
|
* Synchronous readdir(3) - read a directory.
|
|
1231
1947
|
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
1232
1948
|
* @param options If called with `withFileTypes: true` the result data will be an array of Dirent.
|
|
1233
1949
|
*/
|
|
1234
|
-
export function readdirSync(
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1950
|
+
export function readdirSync(
|
|
1951
|
+
path: PathLike,
|
|
1952
|
+
options: ObjectEncodingOptions & {
|
|
1953
|
+
withFileTypes: true;
|
|
1954
|
+
}
|
|
1955
|
+
): Dirent[];
|
|
1956
|
+
/**
|
|
1957
|
+
* Closes the file descriptor. No arguments other than a possible exception are
|
|
1958
|
+
* given to the completion callback.
|
|
1959
|
+
*
|
|
1960
|
+
* Calling `fs.close()` on any file descriptor (`fd`) that is currently in use
|
|
1961
|
+
* through any other `fs` operation may lead to undefined behavior.
|
|
1962
|
+
*
|
|
1963
|
+
* See the POSIX [`close(2)`](http://man7.org/linux/man-pages/man2/close.2.html) documentation for more detail.
|
|
1964
|
+
* @since v0.0.2
|
|
1239
1965
|
*/
|
|
1240
1966
|
export function close(fd: number, callback?: NoParamCallback): void;
|
|
1241
|
-
|
|
1242
|
-
// NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
|
|
1243
1967
|
export namespace close {
|
|
1244
1968
|
/**
|
|
1245
1969
|
* Asynchronous close(2) - close a file descriptor.
|
|
@@ -1247,27 +1971,46 @@ declare module 'fs' {
|
|
|
1247
1971
|
*/
|
|
1248
1972
|
function __promisify__(fd: number): Promise<void>;
|
|
1249
1973
|
}
|
|
1250
|
-
|
|
1251
1974
|
/**
|
|
1252
|
-
*
|
|
1253
|
-
*
|
|
1975
|
+
* Closes the file descriptor. Returns `undefined`.
|
|
1976
|
+
*
|
|
1977
|
+
* Calling `fs.closeSync()` on any file descriptor (`fd`) that is currently in use
|
|
1978
|
+
* through any other `fs` operation may lead to undefined behavior.
|
|
1979
|
+
*
|
|
1980
|
+
* See the POSIX [`close(2)`](http://man7.org/linux/man-pages/man2/close.2.html) documentation for more detail.
|
|
1981
|
+
* @since v0.1.21
|
|
1254
1982
|
*/
|
|
1255
1983
|
export function closeSync(fd: number): void;
|
|
1256
|
-
|
|
1257
1984
|
/**
|
|
1258
|
-
* Asynchronous open(2)
|
|
1985
|
+
* Asynchronous file open. See the POSIX [`open(2)`](http://man7.org/linux/man-pages/man2/open.2.html) documentation for more details.
|
|
1986
|
+
*
|
|
1987
|
+
* `mode` sets the file mode (permission and sticky bits), but only if the file was
|
|
1988
|
+
* created. On Windows, only the write permission can be manipulated; see {@link chmod}.
|
|
1989
|
+
*
|
|
1990
|
+
* The callback gets two arguments `(err, fd)`.
|
|
1991
|
+
*
|
|
1992
|
+
* Some characters (`< > : " / \ | ? *`) are reserved under Windows as documented
|
|
1993
|
+
* by [Naming Files, Paths, and Namespaces](https://docs.microsoft.com/en-us/windows/desktop/FileIO/naming-a-file). Under NTFS, if the filename contains
|
|
1994
|
+
* 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).
|
|
1995
|
+
*
|
|
1996
|
+
* Functions based on `fs.open()` exhibit this behavior as well:`fs.writeFile()`, `fs.readFile()`, etc.
|
|
1997
|
+
* @since v0.0.2
|
|
1998
|
+
* @param [flags='r'] See `support of file system `flags``.
|
|
1999
|
+
* @param [mode=0o666]
|
|
2000
|
+
*/
|
|
2001
|
+
export function open(path: PathLike, flags: OpenMode | undefined, mode: Mode | undefined | null, callback: (err: NodeJS.ErrnoException | null, fd: number) => void): void;
|
|
2002
|
+
/**
|
|
2003
|
+
* Asynchronous open(2) - open and possibly create a file. If the file is created, its mode will be `0o666`.
|
|
1259
2004
|
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
1260
|
-
* @param
|
|
2005
|
+
* @param [flags='r'] See `support of file system `flags``.
|
|
1261
2006
|
*/
|
|
1262
|
-
export function open(path: PathLike, flags: OpenMode
|
|
1263
|
-
|
|
2007
|
+
export function open(path: PathLike, flags: OpenMode | undefined, callback: (err: NodeJS.ErrnoException | null, fd: number) => void): void;
|
|
1264
2008
|
/**
|
|
1265
2009
|
* Asynchronous open(2) - open and possibly create a file. If the file is created, its mode will be `0o666`.
|
|
1266
2010
|
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
1267
2011
|
*/
|
|
1268
|
-
export function open(path: PathLike,
|
|
2012
|
+
export function open(path: PathLike, callback: (err: NodeJS.ErrnoException | null, fd: number) => void): void;
|
|
1269
2013
|
|
|
1270
|
-
// NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
|
|
1271
2014
|
export namespace open {
|
|
1272
2015
|
/**
|
|
1273
2016
|
* Asynchronous open(2) - open and possibly create a file.
|
|
@@ -1276,23 +2019,26 @@ declare module 'fs' {
|
|
|
1276
2019
|
*/
|
|
1277
2020
|
function __promisify__(path: PathLike, flags: OpenMode, mode?: Mode | null): Promise<number>;
|
|
1278
2021
|
}
|
|
1279
|
-
|
|
1280
2022
|
/**
|
|
1281
|
-
*
|
|
1282
|
-
*
|
|
1283
|
-
*
|
|
2023
|
+
* Returns an integer representing the file descriptor.
|
|
2024
|
+
*
|
|
2025
|
+
* For detailed information, see the documentation of the asynchronous version of
|
|
2026
|
+
* this API: {@link open}.
|
|
2027
|
+
* @since v0.1.21
|
|
2028
|
+
* @param [flags='r']
|
|
2029
|
+
* @param [mode=0o666]
|
|
1284
2030
|
*/
|
|
1285
2031
|
export function openSync(path: PathLike, flags: OpenMode, mode?: Mode | null): number;
|
|
1286
|
-
|
|
1287
2032
|
/**
|
|
1288
|
-
*
|
|
1289
|
-
*
|
|
1290
|
-
*
|
|
1291
|
-
*
|
|
2033
|
+
* Change the file system timestamps of the object referenced by `path`.
|
|
2034
|
+
*
|
|
2035
|
+
* The `atime` and `mtime` arguments follow these rules:
|
|
2036
|
+
*
|
|
2037
|
+
* * Values can be either numbers representing Unix epoch time in seconds,`Date`s, or a numeric string like `'123456789.0'`.
|
|
2038
|
+
* * If the value can not be converted to a number, or is `NaN`, `Infinity` or`-Infinity`, an `Error` will be thrown.
|
|
2039
|
+
* @since v0.4.2
|
|
1292
2040
|
*/
|
|
1293
|
-
export function utimes(path: PathLike, atime:
|
|
1294
|
-
|
|
1295
|
-
// NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
|
|
2041
|
+
export function utimes(path: PathLike, atime: TimeLike, mtime: TimeLike, callback: NoParamCallback): void;
|
|
1296
2042
|
export namespace utimes {
|
|
1297
2043
|
/**
|
|
1298
2044
|
* Asynchronously change file timestamps of the file referenced by the supplied path.
|
|
@@ -1300,26 +2046,22 @@ declare module 'fs' {
|
|
|
1300
2046
|
* @param atime The last access time. If a string is provided, it will be coerced to number.
|
|
1301
2047
|
* @param mtime The last modified time. If a string is provided, it will be coerced to number.
|
|
1302
2048
|
*/
|
|
1303
|
-
function __promisify__(path: PathLike, atime:
|
|
2049
|
+
function __promisify__(path: PathLike, atime: TimeLike, mtime: TimeLike): Promise<void>;
|
|
1304
2050
|
}
|
|
1305
|
-
|
|
1306
2051
|
/**
|
|
1307
|
-
*
|
|
1308
|
-
*
|
|
1309
|
-
*
|
|
1310
|
-
*
|
|
2052
|
+
* Returns `undefined`.
|
|
2053
|
+
*
|
|
2054
|
+
* For detailed information, see the documentation of the asynchronous version of
|
|
2055
|
+
* this API: {@link utimes}.
|
|
2056
|
+
* @since v0.4.2
|
|
1311
2057
|
*/
|
|
1312
|
-
export function utimesSync(path: PathLike, atime:
|
|
1313
|
-
|
|
2058
|
+
export function utimesSync(path: PathLike, atime: TimeLike, mtime: TimeLike): void;
|
|
1314
2059
|
/**
|
|
1315
|
-
*
|
|
1316
|
-
*
|
|
1317
|
-
* @
|
|
1318
|
-
* @param mtime The last modified time. If a string is provided, it will be coerced to number.
|
|
2060
|
+
* Change the file system timestamps of the object referenced by the supplied file
|
|
2061
|
+
* descriptor. See {@link utimes}.
|
|
2062
|
+
* @since v0.4.2
|
|
1319
2063
|
*/
|
|
1320
|
-
export function futimes(fd: number, atime:
|
|
1321
|
-
|
|
1322
|
-
// NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
|
|
2064
|
+
export function futimes(fd: number, atime: TimeLike, mtime: TimeLike, callback: NoParamCallback): void;
|
|
1323
2065
|
export namespace futimes {
|
|
1324
2066
|
/**
|
|
1325
2067
|
* Asynchronously change file timestamps of the file referenced by the supplied file descriptor.
|
|
@@ -1327,24 +2069,21 @@ declare module 'fs' {
|
|
|
1327
2069
|
* @param atime The last access time. If a string is provided, it will be coerced to number.
|
|
1328
2070
|
* @param mtime The last modified time. If a string is provided, it will be coerced to number.
|
|
1329
2071
|
*/
|
|
1330
|
-
function __promisify__(fd: number, atime:
|
|
2072
|
+
function __promisify__(fd: number, atime: TimeLike, mtime: TimeLike): Promise<void>;
|
|
1331
2073
|
}
|
|
1332
|
-
|
|
1333
2074
|
/**
|
|
1334
|
-
*
|
|
1335
|
-
* @
|
|
1336
|
-
* @param atime The last access time. If a string is provided, it will be coerced to number.
|
|
1337
|
-
* @param mtime The last modified time. If a string is provided, it will be coerced to number.
|
|
2075
|
+
* Synchronous version of {@link futimes}. Returns `undefined`.
|
|
2076
|
+
* @since v0.4.2
|
|
1338
2077
|
*/
|
|
1339
|
-
export function futimesSync(fd: number, atime:
|
|
1340
|
-
|
|
2078
|
+
export function futimesSync(fd: number, atime: TimeLike, mtime: TimeLike): void;
|
|
1341
2079
|
/**
|
|
1342
|
-
*
|
|
1343
|
-
*
|
|
2080
|
+
* Request that all data for the open file descriptor is flushed to the storage
|
|
2081
|
+
* device. The specific implementation is operating system and device specific.
|
|
2082
|
+
* Refer to the POSIX [`fsync(2)`](http://man7.org/linux/man-pages/man2/fsync.2.html) documentation for more detail. No arguments other
|
|
2083
|
+
* than a possible exception are given to the completion callback.
|
|
2084
|
+
* @since v0.1.96
|
|
1344
2085
|
*/
|
|
1345
2086
|
export function fsync(fd: number, callback: NoParamCallback): void;
|
|
1346
|
-
|
|
1347
|
-
// NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
|
|
1348
2087
|
export namespace fsync {
|
|
1349
2088
|
/**
|
|
1350
2089
|
* Asynchronous fsync(2) - synchronize a file's in-core state with the underlying storage device.
|
|
@@ -1352,19 +2091,36 @@ declare module 'fs' {
|
|
|
1352
2091
|
*/
|
|
1353
2092
|
function __promisify__(fd: number): Promise<void>;
|
|
1354
2093
|
}
|
|
1355
|
-
|
|
1356
2094
|
/**
|
|
1357
|
-
*
|
|
1358
|
-
*
|
|
2095
|
+
* Request that all data for the open file descriptor is flushed to the storage
|
|
2096
|
+
* device. The specific implementation is operating system and device specific.
|
|
2097
|
+
* Refer to the POSIX [`fsync(2)`](http://man7.org/linux/man-pages/man2/fsync.2.html) documentation for more detail. Returns `undefined`.
|
|
2098
|
+
* @since v0.1.96
|
|
1359
2099
|
*/
|
|
1360
2100
|
export function fsyncSync(fd: number): void;
|
|
1361
|
-
|
|
1362
2101
|
/**
|
|
1363
|
-
*
|
|
1364
|
-
*
|
|
1365
|
-
*
|
|
1366
|
-
*
|
|
1367
|
-
*
|
|
2102
|
+
* Write `buffer` to the file specified by `fd`.
|
|
2103
|
+
*
|
|
2104
|
+
* `offset` determines the part of the buffer to be written, and `length` is
|
|
2105
|
+
* an integer specifying the number of bytes to write.
|
|
2106
|
+
*
|
|
2107
|
+
* `position` refers to the offset from the beginning of the file where this data
|
|
2108
|
+
* should be written. If `typeof position !== 'number'`, the data will be written
|
|
2109
|
+
* at the current position. See [`pwrite(2)`](http://man7.org/linux/man-pages/man2/pwrite.2.html).
|
|
2110
|
+
*
|
|
2111
|
+
* The callback will be given three arguments `(err, bytesWritten, buffer)` where`bytesWritten` specifies how many _bytes_ were written from `buffer`.
|
|
2112
|
+
*
|
|
2113
|
+
* If this method is invoked as its `util.promisify()` ed version, it returns
|
|
2114
|
+
* a promise for an `Object` with `bytesWritten` and `buffer` properties.
|
|
2115
|
+
*
|
|
2116
|
+
* It is unsafe to use `fs.write()` multiple times on the same file without waiting
|
|
2117
|
+
* for the callback. For this scenario, {@link createWriteStream} is
|
|
2118
|
+
* recommended.
|
|
2119
|
+
*
|
|
2120
|
+
* On Linux, positional writes don't work when the file is opened in append mode.
|
|
2121
|
+
* The kernel ignores the position argument and always appends the data to
|
|
2122
|
+
* the end of the file.
|
|
2123
|
+
* @since v0.0.2
|
|
1368
2124
|
*/
|
|
1369
2125
|
export function write<TBuffer extends NodeJS.ArrayBufferView>(
|
|
1370
2126
|
fd: number,
|
|
@@ -1372,9 +2128,8 @@ declare module 'fs' {
|
|
|
1372
2128
|
offset: number | undefined | null,
|
|
1373
2129
|
length: number | undefined | null,
|
|
1374
2130
|
position: number | undefined | null,
|
|
1375
|
-
callback: (err: NodeJS.ErrnoException | null, written: number, buffer: TBuffer) => void
|
|
2131
|
+
callback: (err: NodeJS.ErrnoException | null, written: number, buffer: TBuffer) => void
|
|
1376
2132
|
): void;
|
|
1377
|
-
|
|
1378
2133
|
/**
|
|
1379
2134
|
* Asynchronously writes `buffer` to the file referenced by the supplied file descriptor.
|
|
1380
2135
|
* @param fd A file descriptor.
|
|
@@ -1386,9 +2141,8 @@ declare module 'fs' {
|
|
|
1386
2141
|
buffer: TBuffer,
|
|
1387
2142
|
offset: number | undefined | null,
|
|
1388
2143
|
length: number | undefined | null,
|
|
1389
|
-
callback: (err: NodeJS.ErrnoException | null, written: number, buffer: TBuffer) => void
|
|
2144
|
+
callback: (err: NodeJS.ErrnoException | null, written: number, buffer: TBuffer) => void
|
|
1390
2145
|
): void;
|
|
1391
|
-
|
|
1392
2146
|
/**
|
|
1393
2147
|
* Asynchronously writes `buffer` to the file referenced by the supplied file descriptor.
|
|
1394
2148
|
* @param fd A file descriptor.
|
|
@@ -1400,13 +2154,11 @@ declare module 'fs' {
|
|
|
1400
2154
|
offset: number | undefined | null,
|
|
1401
2155
|
callback: (err: NodeJS.ErrnoException | null, written: number, buffer: TBuffer) => void
|
|
1402
2156
|
): void;
|
|
1403
|
-
|
|
1404
2157
|
/**
|
|
1405
2158
|
* Asynchronously writes `buffer` to the file referenced by the supplied file descriptor.
|
|
1406
2159
|
* @param fd A file descriptor.
|
|
1407
2160
|
*/
|
|
1408
2161
|
export function write<TBuffer extends NodeJS.ArrayBufferView>(fd: number, buffer: TBuffer, callback: (err: NodeJS.ErrnoException | null, written: number, buffer: TBuffer) => void): void;
|
|
1409
|
-
|
|
1410
2162
|
/**
|
|
1411
2163
|
* Asynchronously writes `string` to the file referenced by the supplied file descriptor.
|
|
1412
2164
|
* @param fd A file descriptor.
|
|
@@ -1419,9 +2171,8 @@ declare module 'fs' {
|
|
|
1419
2171
|
string: string,
|
|
1420
2172
|
position: number | undefined | null,
|
|
1421
2173
|
encoding: BufferEncoding | undefined | null,
|
|
1422
|
-
callback: (err: NodeJS.ErrnoException | null, written: number, str: string) => void
|
|
2174
|
+
callback: (err: NodeJS.ErrnoException | null, written: number, str: string) => void
|
|
1423
2175
|
): void;
|
|
1424
|
-
|
|
1425
2176
|
/**
|
|
1426
2177
|
* Asynchronously writes `string` to the file referenced by the supplied file descriptor.
|
|
1427
2178
|
* @param fd A file descriptor.
|
|
@@ -1429,15 +2180,12 @@ declare module 'fs' {
|
|
|
1429
2180
|
* @param position The offset from the beginning of the file where this data should be written. If not supplied, defaults to the current position.
|
|
1430
2181
|
*/
|
|
1431
2182
|
export function write(fd: number, string: string, position: number | undefined | null, callback: (err: NodeJS.ErrnoException | null, written: number, str: string) => void): void;
|
|
1432
|
-
|
|
1433
2183
|
/**
|
|
1434
2184
|
* Asynchronously writes `string` to the file referenced by the supplied file descriptor.
|
|
1435
2185
|
* @param fd A file descriptor.
|
|
1436
2186
|
* @param string A string to write.
|
|
1437
2187
|
*/
|
|
1438
2188
|
export function write(fd: number, string: string, callback: (err: NodeJS.ErrnoException | null, written: number, str: string) => void): void;
|
|
1439
|
-
|
|
1440
|
-
// NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
|
|
1441
2189
|
export namespace write {
|
|
1442
2190
|
/**
|
|
1443
2191
|
* Asynchronously writes `buffer` to the file referenced by the supplied file descriptor.
|
|
@@ -1451,9 +2199,11 @@ declare module 'fs' {
|
|
|
1451
2199
|
buffer?: TBuffer,
|
|
1452
2200
|
offset?: number,
|
|
1453
2201
|
length?: number,
|
|
1454
|
-
position?: number | null
|
|
1455
|
-
): Promise<{
|
|
1456
|
-
|
|
2202
|
+
position?: number | null
|
|
2203
|
+
): Promise<{
|
|
2204
|
+
bytesWritten: number;
|
|
2205
|
+
buffer: TBuffer;
|
|
2206
|
+
}>;
|
|
1457
2207
|
/**
|
|
1458
2208
|
* Asynchronously writes `string` to the file referenced by the supplied file descriptor.
|
|
1459
2209
|
* @param fd A file descriptor.
|
|
@@ -1461,18 +2211,23 @@ declare module 'fs' {
|
|
|
1461
2211
|
* @param position The offset from the beginning of the file where this data should be written. If not supplied, defaults to the current position.
|
|
1462
2212
|
* @param encoding The expected string encoding.
|
|
1463
2213
|
*/
|
|
1464
|
-
function __promisify__(
|
|
2214
|
+
function __promisify__(
|
|
2215
|
+
fd: number,
|
|
2216
|
+
string: string,
|
|
2217
|
+
position?: number | null,
|
|
2218
|
+
encoding?: BufferEncoding | null
|
|
2219
|
+
): Promise<{
|
|
2220
|
+
bytesWritten: number;
|
|
2221
|
+
buffer: string;
|
|
2222
|
+
}>;
|
|
1465
2223
|
}
|
|
1466
|
-
|
|
1467
2224
|
/**
|
|
1468
|
-
*
|
|
1469
|
-
*
|
|
1470
|
-
* @
|
|
1471
|
-
* @
|
|
1472
|
-
* @param position The offset from the beginning of the file where this data should be written. If not supplied, defaults to the current position.
|
|
2225
|
+
* For detailed information, see the documentation of the asynchronous version of
|
|
2226
|
+
* this API: {@link write}.
|
|
2227
|
+
* @since v0.1.21
|
|
2228
|
+
* @return The number of bytes written.
|
|
1473
2229
|
*/
|
|
1474
2230
|
export function writeSync(fd: number, buffer: NodeJS.ArrayBufferView, offset?: number | null, length?: number | null, position?: number | null): number;
|
|
1475
|
-
|
|
1476
2231
|
/**
|
|
1477
2232
|
* Synchronously writes `string` to the file referenced by the supplied file descriptor, returning the number of bytes written.
|
|
1478
2233
|
* @param fd A file descriptor.
|
|
@@ -1481,16 +2236,40 @@ declare module 'fs' {
|
|
|
1481
2236
|
* @param encoding The expected string encoding.
|
|
1482
2237
|
*/
|
|
1483
2238
|
export function writeSync(fd: number, string: string, position?: number | null, encoding?: BufferEncoding | null): number;
|
|
1484
|
-
|
|
1485
2239
|
export type ReadPosition = number | bigint;
|
|
1486
|
-
|
|
2240
|
+
export interface ReadSyncOptions {
|
|
2241
|
+
/**
|
|
2242
|
+
* @default 0
|
|
2243
|
+
*/
|
|
2244
|
+
offset?: number | undefined;
|
|
2245
|
+
/**
|
|
2246
|
+
* @default `length of buffer`
|
|
2247
|
+
*/
|
|
2248
|
+
length?: number | undefined;
|
|
2249
|
+
/**
|
|
2250
|
+
* @default null
|
|
2251
|
+
*/
|
|
2252
|
+
position?: ReadPosition | null | undefined;
|
|
2253
|
+
}
|
|
2254
|
+
export interface ReadAsyncOptions<TBuffer extends NodeJS.ArrayBufferView> extends ReadSyncOptions {
|
|
2255
|
+
buffer?: TBuffer;
|
|
2256
|
+
}
|
|
1487
2257
|
/**
|
|
1488
|
-
*
|
|
1489
|
-
*
|
|
2258
|
+
* Read data from the file specified by `fd`.
|
|
2259
|
+
*
|
|
2260
|
+
* The callback is given the three arguments, `(err, bytesRead, buffer)`.
|
|
2261
|
+
*
|
|
2262
|
+
* If the file is not modified concurrently, the end-of-file is reached when the
|
|
2263
|
+
* number of bytes read is zero.
|
|
2264
|
+
*
|
|
2265
|
+
* If this method is invoked as its `util.promisify()` ed version, it returns
|
|
2266
|
+
* a promise for an `Object` with `bytesRead` and `buffer` properties.
|
|
2267
|
+
* @since v0.0.2
|
|
1490
2268
|
* @param buffer The buffer that the data will be written to.
|
|
1491
|
-
* @param offset The
|
|
2269
|
+
* @param offset The position in `buffer` to write the data to.
|
|
1492
2270
|
* @param length The number of bytes to read.
|
|
1493
|
-
* @param position
|
|
2271
|
+
* @param position Specifies where to begin reading from in the file. If `position` is `null` or `-1 `, data will be read from the current file position, and the file position will be updated. If
|
|
2272
|
+
* `position` is an integer, the file position will be unchanged.
|
|
1494
2273
|
*/
|
|
1495
2274
|
export function read<TBuffer extends NodeJS.ArrayBufferView>(
|
|
1496
2275
|
fd: number,
|
|
@@ -1498,10 +2277,23 @@ declare module 'fs' {
|
|
|
1498
2277
|
offset: number,
|
|
1499
2278
|
length: number,
|
|
1500
2279
|
position: ReadPosition | null,
|
|
1501
|
-
callback: (err: NodeJS.ErrnoException | null, bytesRead: number, buffer: TBuffer) => void
|
|
2280
|
+
callback: (err: NodeJS.ErrnoException | null, bytesRead: number, buffer: TBuffer) => void
|
|
1502
2281
|
): void;
|
|
1503
|
-
|
|
1504
|
-
|
|
2282
|
+
/**
|
|
2283
|
+
* Similar to the above `fs.read` function, this version takes an optional `options` object.
|
|
2284
|
+
* If not otherwise specified in an `options` object,
|
|
2285
|
+
* `buffer` defaults to `Buffer.alloc(16384)`,
|
|
2286
|
+
* `offset` defaults to `0`,
|
|
2287
|
+
* `length` defaults to `buffer.byteLength`, `- offset` as of Node 17.6.0
|
|
2288
|
+
* `position` defaults to `null`
|
|
2289
|
+
* @since v12.17.0, 13.11.0
|
|
2290
|
+
*/
|
|
2291
|
+
export function read<TBuffer extends NodeJS.ArrayBufferView>(
|
|
2292
|
+
fd: number,
|
|
2293
|
+
options: ReadAsyncOptions<TBuffer>,
|
|
2294
|
+
callback: (err: NodeJS.ErrnoException | null, bytesRead: number, buffer: TBuffer) => void
|
|
2295
|
+
): void;
|
|
2296
|
+
export function read(fd: number, callback: (err: NodeJS.ErrnoException | null, bytesRead: number, buffer: NodeJS.ArrayBufferView) => void): void;
|
|
1505
2297
|
export namespace read {
|
|
1506
2298
|
/**
|
|
1507
2299
|
* @param fd A file descriptor.
|
|
@@ -1516,53 +2308,112 @@ declare module 'fs' {
|
|
|
1516
2308
|
offset: number,
|
|
1517
2309
|
length: number,
|
|
1518
2310
|
position: number | null
|
|
1519
|
-
): Promise<{
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
*
|
|
1539
|
-
*
|
|
1540
|
-
* @
|
|
1541
|
-
* @param offset The offset in the buffer at which to start writing.
|
|
1542
|
-
* @param length The number of bytes to read.
|
|
1543
|
-
* @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.
|
|
2311
|
+
): Promise<{
|
|
2312
|
+
bytesRead: number;
|
|
2313
|
+
buffer: TBuffer;
|
|
2314
|
+
}>;
|
|
2315
|
+
function __promisify__<TBuffer extends NodeJS.ArrayBufferView>(
|
|
2316
|
+
fd: number,
|
|
2317
|
+
options: ReadAsyncOptions<TBuffer>
|
|
2318
|
+
): Promise<{
|
|
2319
|
+
bytesRead: number;
|
|
2320
|
+
buffer: TBuffer;
|
|
2321
|
+
}>;
|
|
2322
|
+
function __promisify__(fd: number): Promise<{
|
|
2323
|
+
bytesRead: number;
|
|
2324
|
+
buffer: NodeJS.ArrayBufferView;
|
|
2325
|
+
}>;
|
|
2326
|
+
}
|
|
2327
|
+
/**
|
|
2328
|
+
* Returns the number of `bytesRead`.
|
|
2329
|
+
*
|
|
2330
|
+
* For detailed information, see the documentation of the asynchronous version of
|
|
2331
|
+
* this API: {@link read}.
|
|
2332
|
+
* @since v0.1.21
|
|
1544
2333
|
*/
|
|
1545
2334
|
export function readSync(fd: number, buffer: NodeJS.ArrayBufferView, offset: number, length: number, position: ReadPosition | null): number;
|
|
1546
|
-
|
|
1547
2335
|
/**
|
|
1548
2336
|
* Similar to the above `fs.readSync` function, this version takes an optional `options` object.
|
|
1549
2337
|
* If no `options` object is specified, it will default with the above values.
|
|
1550
2338
|
*/
|
|
1551
2339
|
export function readSync(fd: number, buffer: NodeJS.ArrayBufferView, opts?: ReadSyncOptions): number;
|
|
1552
|
-
|
|
1553
2340
|
/**
|
|
1554
2341
|
* Asynchronously reads the entire contents of a file.
|
|
1555
|
-
*
|
|
1556
|
-
*
|
|
1557
|
-
*
|
|
1558
|
-
*
|
|
2342
|
+
*
|
|
2343
|
+
* ```js
|
|
2344
|
+
* import { readFile } from 'fs';
|
|
2345
|
+
*
|
|
2346
|
+
* readFile('/etc/passwd', (err, data) => {
|
|
2347
|
+
* if (err) throw err;
|
|
2348
|
+
* console.log(data);
|
|
2349
|
+
* });
|
|
2350
|
+
* ```
|
|
2351
|
+
*
|
|
2352
|
+
* The callback is passed two arguments `(err, data)`, where `data` is the
|
|
2353
|
+
* contents of the file.
|
|
2354
|
+
*
|
|
2355
|
+
* If no encoding is specified, then the raw buffer is returned.
|
|
2356
|
+
*
|
|
2357
|
+
* If `options` is a string, then it specifies the encoding:
|
|
2358
|
+
*
|
|
2359
|
+
* ```js
|
|
2360
|
+
* import { readFile } from 'fs';
|
|
2361
|
+
*
|
|
2362
|
+
* readFile('/etc/passwd', 'utf8', callback);
|
|
2363
|
+
* ```
|
|
2364
|
+
*
|
|
2365
|
+
* When the path is a directory, the behavior of `fs.readFile()` and {@link readFileSync} is platform-specific. On macOS, Linux, and Windows, an
|
|
2366
|
+
* error will be returned. On FreeBSD, a representation of the directory's contents
|
|
2367
|
+
* will be returned.
|
|
2368
|
+
*
|
|
2369
|
+
* ```js
|
|
2370
|
+
* import { readFile } from 'fs';
|
|
2371
|
+
*
|
|
2372
|
+
* // macOS, Linux, and Windows
|
|
2373
|
+
* readFile('<directory>', (err, data) => {
|
|
2374
|
+
* // => [Error: EISDIR: illegal operation on a directory, read <directory>]
|
|
2375
|
+
* });
|
|
2376
|
+
*
|
|
2377
|
+
* // FreeBSD
|
|
2378
|
+
* readFile('<directory>', (err, data) => {
|
|
2379
|
+
* // => null, <data>
|
|
2380
|
+
* });
|
|
2381
|
+
* ```
|
|
2382
|
+
*
|
|
2383
|
+
* It is possible to abort an ongoing request using an `AbortSignal`. If a
|
|
2384
|
+
* request is aborted the callback is called with an `AbortError`:
|
|
2385
|
+
*
|
|
2386
|
+
* ```js
|
|
2387
|
+
* import { readFile } from 'fs';
|
|
2388
|
+
*
|
|
2389
|
+
* const controller = new AbortController();
|
|
2390
|
+
* const signal = controller.signal;
|
|
2391
|
+
* readFile(fileInfo[0].name, { signal }, (err, buf) => {
|
|
2392
|
+
* // ...
|
|
2393
|
+
* });
|
|
2394
|
+
* // When you want to abort the request
|
|
2395
|
+
* controller.abort();
|
|
2396
|
+
* ```
|
|
2397
|
+
*
|
|
2398
|
+
* The `fs.readFile()` function buffers the entire file. To minimize memory costs,
|
|
2399
|
+
* when possible prefer streaming via `fs.createReadStream()`.
|
|
2400
|
+
*
|
|
2401
|
+
* Aborting an ongoing request does not abort individual operating
|
|
2402
|
+
* system requests but rather the internal buffering `fs.readFile` performs.
|
|
2403
|
+
* @since v0.1.29
|
|
2404
|
+
* @param path filename or file descriptor
|
|
1559
2405
|
*/
|
|
1560
2406
|
export function readFile(
|
|
1561
|
-
path:
|
|
1562
|
-
options:
|
|
1563
|
-
|
|
2407
|
+
path: PathOrFileDescriptor,
|
|
2408
|
+
options:
|
|
2409
|
+
| ({
|
|
2410
|
+
encoding?: null | undefined;
|
|
2411
|
+
flag?: string | undefined;
|
|
2412
|
+
} & Abortable)
|
|
2413
|
+
| undefined
|
|
2414
|
+
| null,
|
|
2415
|
+
callback: (err: NodeJS.ErrnoException | null, data: Buffer) => void
|
|
1564
2416
|
): void;
|
|
1565
|
-
|
|
1566
2417
|
/**
|
|
1567
2418
|
* Asynchronously reads the entire contents of a file.
|
|
1568
2419
|
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
@@ -1571,11 +2422,15 @@ declare module 'fs' {
|
|
|
1571
2422
|
* If a flag is not provided, it defaults to `'r'`.
|
|
1572
2423
|
*/
|
|
1573
2424
|
export function readFile(
|
|
1574
|
-
path:
|
|
1575
|
-
options:
|
|
1576
|
-
|
|
2425
|
+
path: PathOrFileDescriptor,
|
|
2426
|
+
options:
|
|
2427
|
+
| ({
|
|
2428
|
+
encoding: BufferEncoding;
|
|
2429
|
+
flag?: string | undefined;
|
|
2430
|
+
} & Abortable)
|
|
2431
|
+
| BufferEncoding,
|
|
2432
|
+
callback: (err: NodeJS.ErrnoException | null, data: string) => void
|
|
1577
2433
|
): void;
|
|
1578
|
-
|
|
1579
2434
|
/**
|
|
1580
2435
|
* Asynchronously reads the entire contents of a file.
|
|
1581
2436
|
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
@@ -1584,20 +2439,22 @@ declare module 'fs' {
|
|
|
1584
2439
|
* If a flag is not provided, it defaults to `'r'`.
|
|
1585
2440
|
*/
|
|
1586
2441
|
export function readFile(
|
|
1587
|
-
path:
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
2442
|
+
path: PathOrFileDescriptor,
|
|
2443
|
+
options:
|
|
2444
|
+
| (ObjectEncodingOptions & {
|
|
2445
|
+
flag?: string | undefined;
|
|
2446
|
+
} & Abortable)
|
|
2447
|
+
| BufferEncoding
|
|
2448
|
+
| undefined
|
|
2449
|
+
| null,
|
|
2450
|
+
callback: (err: NodeJS.ErrnoException | null, data: string | Buffer) => void
|
|
1591
2451
|
): void;
|
|
1592
|
-
|
|
1593
2452
|
/**
|
|
1594
2453
|
* Asynchronously reads the entire contents of a file.
|
|
1595
2454
|
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
1596
2455
|
* If a file descriptor is provided, the underlying file will _not_ be closed automatically.
|
|
1597
2456
|
*/
|
|
1598
|
-
export function readFile(path:
|
|
1599
|
-
|
|
1600
|
-
// NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
|
|
2457
|
+
export function readFile(path: PathOrFileDescriptor, callback: (err: NodeJS.ErrnoException | null, data: Buffer) => void): void;
|
|
1601
2458
|
export namespace readFile {
|
|
1602
2459
|
/**
|
|
1603
2460
|
* Asynchronously reads the entire contents of a file.
|
|
@@ -1606,8 +2463,13 @@ declare module 'fs' {
|
|
|
1606
2463
|
* @param options An object that may contain an optional flag.
|
|
1607
2464
|
* If a flag is not provided, it defaults to `'r'`.
|
|
1608
2465
|
*/
|
|
1609
|
-
function __promisify__(
|
|
1610
|
-
|
|
2466
|
+
function __promisify__(
|
|
2467
|
+
path: PathOrFileDescriptor,
|
|
2468
|
+
options?: {
|
|
2469
|
+
encoding?: null | undefined;
|
|
2470
|
+
flag?: string | undefined;
|
|
2471
|
+
} | null
|
|
2472
|
+
): Promise<Buffer>;
|
|
1611
2473
|
/**
|
|
1612
2474
|
* Asynchronously reads the entire contents of a file.
|
|
1613
2475
|
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
@@ -1616,8 +2478,15 @@ declare module 'fs' {
|
|
|
1616
2478
|
* @param options Either the encoding for the result, or an object that contains the encoding and an optional flag.
|
|
1617
2479
|
* If a flag is not provided, it defaults to `'r'`.
|
|
1618
2480
|
*/
|
|
1619
|
-
function __promisify__(
|
|
1620
|
-
|
|
2481
|
+
function __promisify__(
|
|
2482
|
+
path: PathOrFileDescriptor,
|
|
2483
|
+
options:
|
|
2484
|
+
| {
|
|
2485
|
+
encoding: BufferEncoding;
|
|
2486
|
+
flag?: string | undefined;
|
|
2487
|
+
}
|
|
2488
|
+
| BufferEncoding
|
|
2489
|
+
): Promise<string>;
|
|
1621
2490
|
/**
|
|
1622
2491
|
* Asynchronously reads the entire contents of a file.
|
|
1623
2492
|
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
@@ -1626,17 +2495,47 @@ declare module 'fs' {
|
|
|
1626
2495
|
* @param options Either the encoding for the result, or an object that contains the encoding and an optional flag.
|
|
1627
2496
|
* If a flag is not provided, it defaults to `'r'`.
|
|
1628
2497
|
*/
|
|
1629
|
-
function __promisify__(
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
2498
|
+
function __promisify__(
|
|
2499
|
+
path: PathOrFileDescriptor,
|
|
2500
|
+
options?:
|
|
2501
|
+
| (ObjectEncodingOptions & {
|
|
2502
|
+
flag?: string | undefined;
|
|
2503
|
+
})
|
|
2504
|
+
| BufferEncoding
|
|
2505
|
+
| null
|
|
2506
|
+
): Promise<string | Buffer>;
|
|
2507
|
+
}
|
|
2508
|
+
/**
|
|
2509
|
+
* Returns the contents of the `path`.
|
|
2510
|
+
*
|
|
2511
|
+
* For detailed information, see the documentation of the asynchronous version of
|
|
2512
|
+
* this API: {@link readFile}.
|
|
2513
|
+
*
|
|
2514
|
+
* If the `encoding` option is specified then this function returns a
|
|
2515
|
+
* string. Otherwise it returns a buffer.
|
|
2516
|
+
*
|
|
2517
|
+
* Similar to {@link readFile}, when the path is a directory, the behavior of`fs.readFileSync()` is platform-specific.
|
|
2518
|
+
*
|
|
2519
|
+
* ```js
|
|
2520
|
+
* import { readFileSync } from 'fs';
|
|
2521
|
+
*
|
|
2522
|
+
* // macOS, Linux, and Windows
|
|
2523
|
+
* readFileSync('<directory>');
|
|
2524
|
+
* // => [Error: EISDIR: illegal operation on a directory, read <directory>]
|
|
2525
|
+
*
|
|
2526
|
+
* // FreeBSD
|
|
2527
|
+
* readFileSync('<directory>'); // => <data>
|
|
2528
|
+
* ```
|
|
2529
|
+
* @since v0.1.8
|
|
2530
|
+
* @param path filename or file descriptor
|
|
2531
|
+
*/
|
|
2532
|
+
export function readFileSync(
|
|
2533
|
+
path: PathOrFileDescriptor,
|
|
2534
|
+
options?: {
|
|
2535
|
+
encoding?: null | undefined;
|
|
2536
|
+
flag?: string | undefined;
|
|
2537
|
+
} | null
|
|
2538
|
+
): Buffer;
|
|
1640
2539
|
/**
|
|
1641
2540
|
* Synchronously reads the entire contents of a file.
|
|
1642
2541
|
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
@@ -1644,8 +2543,15 @@ declare module 'fs' {
|
|
|
1644
2543
|
* @param options Either the encoding for the result, or an object that contains the encoding and an optional flag.
|
|
1645
2544
|
* If a flag is not provided, it defaults to `'r'`.
|
|
1646
2545
|
*/
|
|
1647
|
-
export function readFileSync(
|
|
1648
|
-
|
|
2546
|
+
export function readFileSync(
|
|
2547
|
+
path: PathOrFileDescriptor,
|
|
2548
|
+
options:
|
|
2549
|
+
| {
|
|
2550
|
+
encoding: BufferEncoding;
|
|
2551
|
+
flag?: string | undefined;
|
|
2552
|
+
}
|
|
2553
|
+
| BufferEncoding
|
|
2554
|
+
): string;
|
|
1649
2555
|
/**
|
|
1650
2556
|
* Synchronously reads the entire contents of a file.
|
|
1651
2557
|
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
@@ -1653,32 +2559,92 @@ declare module 'fs' {
|
|
|
1653
2559
|
* @param options Either the encoding for the result, or an object that contains the encoding and an optional flag.
|
|
1654
2560
|
* If a flag is not provided, it defaults to `'r'`.
|
|
1655
2561
|
*/
|
|
1656
|
-
export function readFileSync(
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
2562
|
+
export function readFileSync(
|
|
2563
|
+
path: PathOrFileDescriptor,
|
|
2564
|
+
options?:
|
|
2565
|
+
| (ObjectEncodingOptions & {
|
|
2566
|
+
flag?: string | undefined;
|
|
2567
|
+
})
|
|
2568
|
+
| BufferEncoding
|
|
2569
|
+
| null
|
|
2570
|
+
): string | Buffer;
|
|
2571
|
+
export type WriteFileOptions =
|
|
2572
|
+
| (ObjectEncodingOptions &
|
|
2573
|
+
Abortable & {
|
|
2574
|
+
mode?: Mode | undefined;
|
|
2575
|
+
flag?: string | undefined;
|
|
2576
|
+
})
|
|
2577
|
+
| BufferEncoding
|
|
2578
|
+
| null;
|
|
2579
|
+
/**
|
|
2580
|
+
* When `file` is a filename, asynchronously writes data to the file, replacing the
|
|
2581
|
+
* file if it already exists. `data` can be a string or a buffer.
|
|
2582
|
+
*
|
|
2583
|
+
* When `file` is a file descriptor, the behavior is similar to calling`fs.write()` directly (which is recommended). See the notes below on using
|
|
2584
|
+
* a file descriptor.
|
|
2585
|
+
*
|
|
2586
|
+
* The `encoding` option is ignored if `data` is a buffer.
|
|
2587
|
+
*
|
|
2588
|
+
* The `mode` option only affects the newly created file. See {@link open} for more details.
|
|
2589
|
+
*
|
|
2590
|
+
* ```js
|
|
2591
|
+
* import { writeFile } from 'fs';
|
|
2592
|
+
* import { Buffer } from 'buffer';
|
|
2593
|
+
*
|
|
2594
|
+
* const data = new Uint8Array(Buffer.from('Hello Node.js'));
|
|
2595
|
+
* writeFile('message.txt', data, (err) => {
|
|
2596
|
+
* if (err) throw err;
|
|
2597
|
+
* console.log('The file has been saved!');
|
|
2598
|
+
* });
|
|
2599
|
+
* ```
|
|
2600
|
+
*
|
|
2601
|
+
* If `options` is a string, then it specifies the encoding:
|
|
2602
|
+
*
|
|
2603
|
+
* ```js
|
|
2604
|
+
* import { writeFile } from 'fs';
|
|
2605
|
+
*
|
|
2606
|
+
* writeFile('message.txt', 'Hello Node.js', 'utf8', callback);
|
|
2607
|
+
* ```
|
|
2608
|
+
*
|
|
2609
|
+
* It is unsafe to use `fs.writeFile()` multiple times on the same file without
|
|
2610
|
+
* waiting for the callback. For this scenario, {@link createWriteStream} is
|
|
2611
|
+
* recommended.
|
|
2612
|
+
*
|
|
2613
|
+
* Similarly to `fs.readFile` \- `fs.writeFile` is a convenience method that
|
|
2614
|
+
* performs multiple `write` calls internally to write the buffer passed to it.
|
|
2615
|
+
* For performance sensitive code consider using {@link createWriteStream}.
|
|
2616
|
+
*
|
|
2617
|
+
* It is possible to use an `AbortSignal` to cancel an `fs.writeFile()`.
|
|
2618
|
+
* Cancelation is "best effort", and some amount of data is likely still
|
|
2619
|
+
* to be written.
|
|
2620
|
+
*
|
|
2621
|
+
* ```js
|
|
2622
|
+
* import { writeFile } from 'fs';
|
|
2623
|
+
* import { Buffer } from 'buffer';
|
|
2624
|
+
*
|
|
2625
|
+
* const controller = new AbortController();
|
|
2626
|
+
* const { signal } = controller;
|
|
2627
|
+
* const data = new Uint8Array(Buffer.from('Hello Node.js'));
|
|
2628
|
+
* writeFile('message.txt', data, { signal }, (err) => {
|
|
2629
|
+
* // When a request is aborted - the callback is called with an AbortError
|
|
2630
|
+
* });
|
|
2631
|
+
* // When the request should be aborted
|
|
2632
|
+
* controller.abort();
|
|
2633
|
+
* ```
|
|
2634
|
+
*
|
|
2635
|
+
* Aborting an ongoing request does not abort individual operating
|
|
2636
|
+
* system requests but rather the internal buffering `fs.writeFile` performs.
|
|
2637
|
+
* @since v0.1.29
|
|
2638
|
+
* @param file filename or file descriptor
|
|
2639
|
+
*/
|
|
2640
|
+
export function writeFile(file: PathOrFileDescriptor, data: string | NodeJS.ArrayBufferView, options: WriteFileOptions, callback: NoParamCallback): void;
|
|
1660
2641
|
/**
|
|
1661
2642
|
* Asynchronously writes data to a file, replacing the file if it already exists.
|
|
1662
2643
|
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
1663
2644
|
* If a file descriptor is provided, the underlying file will _not_ be closed automatically.
|
|
1664
2645
|
* @param data The data to write. If something other than a Buffer or Uint8Array is provided, the value is coerced to a string.
|
|
1665
|
-
* @param options Either the encoding for the file, or an object optionally specifying the encoding, file mode, and flag.
|
|
1666
|
-
* If `encoding` is not supplied, the default of `'utf8'` is used.
|
|
1667
|
-
* If `mode` is not supplied, the default of `0o666` is used.
|
|
1668
|
-
* If `mode` is a string, it is parsed as an octal integer.
|
|
1669
|
-
* If `flag` is not supplied, the default of `'w'` is used.
|
|
1670
2646
|
*/
|
|
1671
|
-
export function writeFile(path:
|
|
1672
|
-
|
|
1673
|
-
/**
|
|
1674
|
-
* Asynchronously writes data to a file, replacing the file if it already exists.
|
|
1675
|
-
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
1676
|
-
* If a file descriptor is provided, the underlying file will _not_ be closed automatically.
|
|
1677
|
-
* @param data The data to write. If something other than a Buffer or Uint8Array is provided, the value is coerced to a string.
|
|
1678
|
-
*/
|
|
1679
|
-
export function writeFile(path: PathLike | number, data: string | NodeJS.ArrayBufferView, callback: NoParamCallback): void;
|
|
1680
|
-
|
|
1681
|
-
// NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
|
|
2647
|
+
export function writeFile(path: PathOrFileDescriptor, data: string | NodeJS.ArrayBufferView, callback: NoParamCallback): void;
|
|
1682
2648
|
export namespace writeFile {
|
|
1683
2649
|
/**
|
|
1684
2650
|
* Asynchronously writes data to a file, replacing the file if it already exists.
|
|
@@ -1692,44 +2658,80 @@ declare module 'fs' {
|
|
|
1692
2658
|
* If `mode` is a string, it is parsed as an octal integer.
|
|
1693
2659
|
* If `flag` is not supplied, the default of `'w'` is used.
|
|
1694
2660
|
*/
|
|
1695
|
-
function __promisify__(path:
|
|
1696
|
-
}
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
*
|
|
1700
|
-
*
|
|
1701
|
-
*
|
|
1702
|
-
*
|
|
1703
|
-
*
|
|
1704
|
-
*
|
|
1705
|
-
*
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
2661
|
+
function __promisify__(path: PathOrFileDescriptor, data: string | NodeJS.ArrayBufferView, options?: WriteFileOptions): Promise<void>;
|
|
2662
|
+
}
|
|
2663
|
+
/**
|
|
2664
|
+
* Returns `undefined`.
|
|
2665
|
+
*
|
|
2666
|
+
* The `mode` option only affects the newly created file. See {@link open} for more details.
|
|
2667
|
+
*
|
|
2668
|
+
* For detailed information, see the documentation of the asynchronous version of
|
|
2669
|
+
* this API: {@link writeFile}.
|
|
2670
|
+
* @since v0.1.29
|
|
2671
|
+
* @param file filename or file descriptor
|
|
2672
|
+
*/
|
|
2673
|
+
export function writeFileSync(file: PathOrFileDescriptor, data: string | NodeJS.ArrayBufferView, options?: WriteFileOptions): void;
|
|
2674
|
+
/**
|
|
2675
|
+
* Asynchronously append data to a file, creating the file if it does not yet
|
|
2676
|
+
* exist. `data` can be a string or a `Buffer`.
|
|
2677
|
+
*
|
|
2678
|
+
* The `mode` option only affects the newly created file. See {@link open} for more details.
|
|
2679
|
+
*
|
|
2680
|
+
* ```js
|
|
2681
|
+
* import { appendFile } from 'fs';
|
|
2682
|
+
*
|
|
2683
|
+
* appendFile('message.txt', 'data to append', (err) => {
|
|
2684
|
+
* if (err) throw err;
|
|
2685
|
+
* console.log('The "data to append" was appended to file!');
|
|
2686
|
+
* });
|
|
2687
|
+
* ```
|
|
2688
|
+
*
|
|
2689
|
+
* If `options` is a string, then it specifies the encoding:
|
|
2690
|
+
*
|
|
2691
|
+
* ```js
|
|
2692
|
+
* import { appendFile } from 'fs';
|
|
2693
|
+
*
|
|
2694
|
+
* appendFile('message.txt', 'data to append', 'utf8', callback);
|
|
2695
|
+
* ```
|
|
2696
|
+
*
|
|
2697
|
+
* The `path` may be specified as a numeric file descriptor that has been opened
|
|
2698
|
+
* for appending (using `fs.open()` or `fs.openSync()`). The file descriptor will
|
|
2699
|
+
* not be closed automatically.
|
|
2700
|
+
*
|
|
2701
|
+
* ```js
|
|
2702
|
+
* import { open, close, appendFile } from 'fs';
|
|
2703
|
+
*
|
|
2704
|
+
* function closeFd(fd) {
|
|
2705
|
+
* close(fd, (err) => {
|
|
2706
|
+
* if (err) throw err;
|
|
2707
|
+
* });
|
|
2708
|
+
* }
|
|
2709
|
+
*
|
|
2710
|
+
* open('message.txt', 'a', (err, fd) => {
|
|
2711
|
+
* if (err) throw err;
|
|
2712
|
+
*
|
|
2713
|
+
* try {
|
|
2714
|
+
* appendFile(fd, 'data to append', 'utf8', (err) => {
|
|
2715
|
+
* closeFd(fd);
|
|
2716
|
+
* if (err) throw err;
|
|
2717
|
+
* });
|
|
2718
|
+
* } catch (err) {
|
|
2719
|
+
* closeFd(fd);
|
|
2720
|
+
* throw err;
|
|
2721
|
+
* }
|
|
2722
|
+
* });
|
|
2723
|
+
* ```
|
|
2724
|
+
* @since v0.6.7
|
|
2725
|
+
* @param path filename or file descriptor
|
|
2726
|
+
*/
|
|
2727
|
+
export function appendFile(path: PathOrFileDescriptor, data: string | Uint8Array, options: WriteFileOptions, callback: NoParamCallback): void;
|
|
1711
2728
|
/**
|
|
1712
2729
|
* Asynchronously append data to a file, creating the file if it does not exist.
|
|
1713
2730
|
* @param file A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
1714
2731
|
* If a file descriptor is provided, the underlying file will _not_ be closed automatically.
|
|
1715
2732
|
* @param data The data to write. If something other than a Buffer or Uint8Array is provided, the value is coerced to a string.
|
|
1716
|
-
* @param options Either the encoding for the file, or an object optionally specifying the encoding, file mode, and flag.
|
|
1717
|
-
* If `encoding` is not supplied, the default of `'utf8'` is used.
|
|
1718
|
-
* If `mode` is not supplied, the default of `0o666` is used.
|
|
1719
|
-
* If `mode` is a string, it is parsed as an octal integer.
|
|
1720
|
-
* If `flag` is not supplied, the default of `'a'` is used.
|
|
1721
2733
|
*/
|
|
1722
|
-
export function appendFile(file:
|
|
1723
|
-
|
|
1724
|
-
/**
|
|
1725
|
-
* Asynchronously append data to a file, creating the file if it does not exist.
|
|
1726
|
-
* @param file A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
1727
|
-
* If a file descriptor is provided, the underlying file will _not_ be closed automatically.
|
|
1728
|
-
* @param data The data to write. If something other than a Buffer or Uint8Array is provided, the value is coerced to a string.
|
|
1729
|
-
*/
|
|
1730
|
-
export function appendFile(file: PathLike | number, data: string | Uint8Array, callback: NoParamCallback): void;
|
|
1731
|
-
|
|
1732
|
-
// NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
|
|
2734
|
+
export function appendFile(file: PathOrFileDescriptor, data: string | Uint8Array, callback: NoParamCallback): void;
|
|
1733
2735
|
export namespace appendFile {
|
|
1734
2736
|
/**
|
|
1735
2737
|
* Asynchronously append data to a file, creating the file if it does not exist.
|
|
@@ -1743,57 +2745,225 @@ declare module 'fs' {
|
|
|
1743
2745
|
* If `mode` is a string, it is parsed as an octal integer.
|
|
1744
2746
|
* If `flag` is not supplied, the default of `'a'` is used.
|
|
1745
2747
|
*/
|
|
1746
|
-
function __promisify__(file:
|
|
1747
|
-
}
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
*
|
|
1751
|
-
*
|
|
1752
|
-
*
|
|
1753
|
-
*
|
|
1754
|
-
*
|
|
1755
|
-
*
|
|
1756
|
-
*
|
|
1757
|
-
*
|
|
1758
|
-
*
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
*
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
2748
|
+
function __promisify__(file: PathOrFileDescriptor, data: string | Uint8Array, options?: WriteFileOptions): Promise<void>;
|
|
2749
|
+
}
|
|
2750
|
+
/**
|
|
2751
|
+
* Synchronously append data to a file, creating the file if it does not yet
|
|
2752
|
+
* exist. `data` can be a string or a `Buffer`.
|
|
2753
|
+
*
|
|
2754
|
+
* The `mode` option only affects the newly created file. See {@link open} for more details.
|
|
2755
|
+
*
|
|
2756
|
+
* ```js
|
|
2757
|
+
* import { appendFileSync } from 'fs';
|
|
2758
|
+
*
|
|
2759
|
+
* try {
|
|
2760
|
+
* appendFileSync('message.txt', 'data to append');
|
|
2761
|
+
* console.log('The "data to append" was appended to file!');
|
|
2762
|
+
* } catch (err) {
|
|
2763
|
+
* // Handle the error
|
|
2764
|
+
* }
|
|
2765
|
+
* ```
|
|
2766
|
+
*
|
|
2767
|
+
* If `options` is a string, then it specifies the encoding:
|
|
2768
|
+
*
|
|
2769
|
+
* ```js
|
|
2770
|
+
* import { appendFileSync } from 'fs';
|
|
2771
|
+
*
|
|
2772
|
+
* appendFileSync('message.txt', 'data to append', 'utf8');
|
|
2773
|
+
* ```
|
|
2774
|
+
*
|
|
2775
|
+
* The `path` may be specified as a numeric file descriptor that has been opened
|
|
2776
|
+
* for appending (using `fs.open()` or `fs.openSync()`). The file descriptor will
|
|
2777
|
+
* not be closed automatically.
|
|
2778
|
+
*
|
|
2779
|
+
* ```js
|
|
2780
|
+
* import { openSync, closeSync, appendFileSync } from 'fs';
|
|
2781
|
+
*
|
|
2782
|
+
* let fd;
|
|
2783
|
+
*
|
|
2784
|
+
* try {
|
|
2785
|
+
* fd = openSync('message.txt', 'a');
|
|
2786
|
+
* appendFileSync(fd, 'data to append', 'utf8');
|
|
2787
|
+
* } catch (err) {
|
|
2788
|
+
* // Handle the error
|
|
2789
|
+
* } finally {
|
|
2790
|
+
* if (fd !== undefined)
|
|
2791
|
+
* closeSync(fd);
|
|
2792
|
+
* }
|
|
2793
|
+
* ```
|
|
2794
|
+
* @since v0.6.7
|
|
2795
|
+
* @param path filename or file descriptor
|
|
2796
|
+
*/
|
|
2797
|
+
export function appendFileSync(path: PathOrFileDescriptor, data: string | Uint8Array, options?: WriteFileOptions): void;
|
|
2798
|
+
/**
|
|
2799
|
+
* Watch for changes on `filename`. The callback `listener` will be called each
|
|
2800
|
+
* time the file is accessed.
|
|
2801
|
+
*
|
|
2802
|
+
* The `options` argument may be omitted. If provided, it should be an object. The`options` object may contain a boolean named `persistent` that indicates
|
|
2803
|
+
* whether the process should continue to run as long as files are being watched.
|
|
2804
|
+
* The `options` object may specify an `interval` property indicating how often the
|
|
2805
|
+
* target should be polled in milliseconds.
|
|
2806
|
+
*
|
|
2807
|
+
* The `listener` gets two arguments the current stat object and the previous
|
|
2808
|
+
* stat object:
|
|
2809
|
+
*
|
|
2810
|
+
* ```js
|
|
2811
|
+
* import { watchFile } from 'fs';
|
|
2812
|
+
*
|
|
2813
|
+
* watchFile('message.text', (curr, prev) => {
|
|
2814
|
+
* console.log(`the current mtime is: ${curr.mtime}`);
|
|
2815
|
+
* console.log(`the previous mtime was: ${prev.mtime}`);
|
|
2816
|
+
* });
|
|
2817
|
+
* ```
|
|
2818
|
+
*
|
|
2819
|
+
* These stat objects are instances of `fs.Stat`. If the `bigint` option is `true`,
|
|
2820
|
+
* the numeric values in these objects are specified as `BigInt`s.
|
|
2821
|
+
*
|
|
2822
|
+
* To be notified when the file was modified, not just accessed, it is necessary
|
|
2823
|
+
* to compare `curr.mtimeMs` and `prev.mtimeMs`.
|
|
2824
|
+
*
|
|
2825
|
+
* When an `fs.watchFile` operation results in an `ENOENT` error, it
|
|
2826
|
+
* will invoke the listener once, with all the fields zeroed (or, for dates, the
|
|
2827
|
+
* Unix Epoch). If the file is created later on, the listener will be called
|
|
2828
|
+
* again, with the latest stat objects. This is a change in functionality since
|
|
2829
|
+
* v0.10.
|
|
2830
|
+
*
|
|
2831
|
+
* Using {@link watch} is more efficient than `fs.watchFile` and`fs.unwatchFile`. `fs.watch` should be used instead of `fs.watchFile` and`fs.unwatchFile` when possible.
|
|
2832
|
+
*
|
|
2833
|
+
* When a file being watched by `fs.watchFile()` disappears and reappears,
|
|
2834
|
+
* then the contents of `previous` in the second callback event (the file's
|
|
2835
|
+
* reappearance) will be the same as the contents of `previous` in the first
|
|
2836
|
+
* callback event (its disappearance).
|
|
2837
|
+
*
|
|
2838
|
+
* This happens when:
|
|
2839
|
+
*
|
|
2840
|
+
* * the file is deleted, followed by a restore
|
|
2841
|
+
* * the file is renamed and then renamed a second time back to its original name
|
|
2842
|
+
* @since v0.1.31
|
|
2843
|
+
*/
|
|
2844
|
+
export interface WatchFileOptions {
|
|
2845
|
+
bigint?: boolean | undefined;
|
|
2846
|
+
persistent?: boolean | undefined;
|
|
2847
|
+
interval?: number | undefined;
|
|
2848
|
+
}
|
|
2849
|
+
/**
|
|
2850
|
+
* Watch for changes on `filename`. The callback `listener` will be called each
|
|
2851
|
+
* time the file is accessed.
|
|
2852
|
+
*
|
|
2853
|
+
* The `options` argument may be omitted. If provided, it should be an object. The`options` object may contain a boolean named `persistent` that indicates
|
|
2854
|
+
* whether the process should continue to run as long as files are being watched.
|
|
2855
|
+
* The `options` object may specify an `interval` property indicating how often the
|
|
2856
|
+
* target should be polled in milliseconds.
|
|
2857
|
+
*
|
|
2858
|
+
* The `listener` gets two arguments the current stat object and the previous
|
|
2859
|
+
* stat object:
|
|
2860
|
+
*
|
|
2861
|
+
* ```js
|
|
2862
|
+
* import { watchFile } from 'fs';
|
|
2863
|
+
*
|
|
2864
|
+
* watchFile('message.text', (curr, prev) => {
|
|
2865
|
+
* console.log(`the current mtime is: ${curr.mtime}`);
|
|
2866
|
+
* console.log(`the previous mtime was: ${prev.mtime}`);
|
|
2867
|
+
* });
|
|
2868
|
+
* ```
|
|
2869
|
+
*
|
|
2870
|
+
* These stat objects are instances of `fs.Stat`. If the `bigint` option is `true`,
|
|
2871
|
+
* the numeric values in these objects are specified as `BigInt`s.
|
|
2872
|
+
*
|
|
2873
|
+
* To be notified when the file was modified, not just accessed, it is necessary
|
|
2874
|
+
* to compare `curr.mtimeMs` and `prev.mtimeMs`.
|
|
2875
|
+
*
|
|
2876
|
+
* When an `fs.watchFile` operation results in an `ENOENT` error, it
|
|
2877
|
+
* will invoke the listener once, with all the fields zeroed (or, for dates, the
|
|
2878
|
+
* Unix Epoch). If the file is created later on, the listener will be called
|
|
2879
|
+
* again, with the latest stat objects. This is a change in functionality since
|
|
2880
|
+
* v0.10.
|
|
2881
|
+
*
|
|
2882
|
+
* Using {@link watch} is more efficient than `fs.watchFile` and`fs.unwatchFile`. `fs.watch` should be used instead of `fs.watchFile` and`fs.unwatchFile` when possible.
|
|
2883
|
+
*
|
|
2884
|
+
* When a file being watched by `fs.watchFile()` disappears and reappears,
|
|
2885
|
+
* then the contents of `previous` in the second callback event (the file's
|
|
2886
|
+
* reappearance) will be the same as the contents of `previous` in the first
|
|
2887
|
+
* callback event (its disappearance).
|
|
2888
|
+
*
|
|
2889
|
+
* This happens when:
|
|
2890
|
+
*
|
|
2891
|
+
* * the file is deleted, followed by a restore
|
|
2892
|
+
* * the file is renamed and then renamed a second time back to its original name
|
|
2893
|
+
* @since v0.1.31
|
|
2894
|
+
*/
|
|
2895
|
+
export function watchFile(
|
|
2896
|
+
filename: PathLike,
|
|
2897
|
+
options:
|
|
2898
|
+
| (WatchFileOptions & {
|
|
2899
|
+
bigint?: false | undefined;
|
|
2900
|
+
})
|
|
2901
|
+
| undefined,
|
|
2902
|
+
listener: (curr: Stats, prev: Stats) => void
|
|
2903
|
+
): StatWatcher;
|
|
2904
|
+
export function watchFile(
|
|
2905
|
+
filename: PathLike,
|
|
2906
|
+
options:
|
|
2907
|
+
| (WatchFileOptions & {
|
|
2908
|
+
bigint: true;
|
|
2909
|
+
})
|
|
2910
|
+
| undefined,
|
|
2911
|
+
listener: (curr: BigIntStats, prev: BigIntStats) => void
|
|
2912
|
+
): StatWatcher;
|
|
1767
2913
|
/**
|
|
1768
2914
|
* Watch for changes on `filename`. The callback `listener` will be called each time the file is accessed.
|
|
1769
2915
|
* @param filename A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
|
|
1770
2916
|
*/
|
|
1771
|
-
export function watchFile(filename: PathLike, listener: (curr: Stats, prev: Stats) => void):
|
|
1772
|
-
|
|
2917
|
+
export function watchFile(filename: PathLike, listener: (curr: Stats, prev: Stats) => void): StatWatcher;
|
|
1773
2918
|
/**
|
|
1774
|
-
* Stop watching for changes on `filename`.
|
|
1775
|
-
*
|
|
2919
|
+
* Stop watching for changes on `filename`. If `listener` is specified, only that
|
|
2920
|
+
* particular listener is removed. Otherwise, _all_ listeners are removed,
|
|
2921
|
+
* effectively stopping watching of `filename`.
|
|
2922
|
+
*
|
|
2923
|
+
* Calling `fs.unwatchFile()` with a filename that is not being watched is a
|
|
2924
|
+
* no-op, not an error.
|
|
2925
|
+
*
|
|
2926
|
+
* Using {@link watch} is more efficient than `fs.watchFile()` and`fs.unwatchFile()`. `fs.watch()` should be used instead of `fs.watchFile()`and `fs.unwatchFile()` when possible.
|
|
2927
|
+
* @since v0.1.31
|
|
2928
|
+
* @param listener Optional, a listener previously attached using `fs.watchFile()`
|
|
1776
2929
|
*/
|
|
1777
2930
|
export function unwatchFile(filename: PathLike, listener?: (curr: Stats, prev: Stats) => void): void;
|
|
1778
|
-
|
|
1779
2931
|
export interface WatchOptions extends Abortable {
|
|
1780
|
-
encoding?: BufferEncoding |
|
|
1781
|
-
persistent?: boolean;
|
|
1782
|
-
recursive?: boolean;
|
|
1783
|
-
}
|
|
1784
|
-
|
|
1785
|
-
export type WatchListener<T> = (event:
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
*
|
|
1789
|
-
*
|
|
1790
|
-
*
|
|
1791
|
-
*
|
|
1792
|
-
*
|
|
1793
|
-
*
|
|
2932
|
+
encoding?: BufferEncoding | 'buffer' | undefined;
|
|
2933
|
+
persistent?: boolean | undefined;
|
|
2934
|
+
recursive?: boolean | undefined;
|
|
2935
|
+
}
|
|
2936
|
+
export type WatchEventType = 'rename' | 'change';
|
|
2937
|
+
export type WatchListener<T> = (event: WatchEventType, filename: T) => void;
|
|
2938
|
+
/**
|
|
2939
|
+
* Watch for changes on `filename`, where `filename` is either a file or a
|
|
2940
|
+
* directory.
|
|
2941
|
+
*
|
|
2942
|
+
* The second argument is optional. If `options` is provided as a string, it
|
|
2943
|
+
* specifies the `encoding`. Otherwise `options` should be passed as an object.
|
|
2944
|
+
*
|
|
2945
|
+
* The listener callback gets two arguments `(eventType, filename)`. `eventType`is either `'rename'` or `'change'`, and `filename` is the name of the file
|
|
2946
|
+
* which triggered the event.
|
|
2947
|
+
*
|
|
2948
|
+
* On most platforms, `'rename'` is emitted whenever a filename appears or
|
|
2949
|
+
* disappears in the directory.
|
|
2950
|
+
*
|
|
2951
|
+
* The listener callback is attached to the `'change'` event fired by `fs.FSWatcher`, but it is not the same thing as the `'change'` value of`eventType`.
|
|
2952
|
+
*
|
|
2953
|
+
* If a `signal` is passed, aborting the corresponding AbortController will close
|
|
2954
|
+
* the returned `fs.FSWatcher`.
|
|
2955
|
+
* @since v0.5.10
|
|
2956
|
+
* @param listener
|
|
1794
2957
|
*/
|
|
1795
|
-
export function watch(
|
|
1796
|
-
|
|
2958
|
+
export function watch(
|
|
2959
|
+
filename: PathLike,
|
|
2960
|
+
options:
|
|
2961
|
+
| (WatchOptions & {
|
|
2962
|
+
encoding: 'buffer';
|
|
2963
|
+
})
|
|
2964
|
+
| 'buffer',
|
|
2965
|
+
listener?: WatchListener<Buffer>
|
|
2966
|
+
): FSWatcher;
|
|
1797
2967
|
/**
|
|
1798
2968
|
* Watch for changes on `filename`, where `filename` is either a file or a directory, returning an `FSWatcher`.
|
|
1799
2969
|
* @param filename A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
|
|
@@ -1802,12 +2972,7 @@ declare module 'fs' {
|
|
|
1802
2972
|
* If `persistent` is not supplied, the default of `true` is used.
|
|
1803
2973
|
* If `recursive` is not supplied, the default of `false` is used.
|
|
1804
2974
|
*/
|
|
1805
|
-
export function watch(
|
|
1806
|
-
filename: PathLike,
|
|
1807
|
-
options?: WatchOptions | BufferEncoding | null,
|
|
1808
|
-
listener?: WatchListener<string>,
|
|
1809
|
-
): FSWatcher;
|
|
1810
|
-
|
|
2975
|
+
export function watch(filename: PathLike, options?: WatchOptions | BufferEncoding | null, listener?: WatchListener<string>): FSWatcher;
|
|
1811
2976
|
/**
|
|
1812
2977
|
* Watch for changes on `filename`, where `filename` is either a file or a directory, returning an `FSWatcher`.
|
|
1813
2978
|
* @param filename A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
|
|
@@ -1817,21 +2982,142 @@ declare module 'fs' {
|
|
|
1817
2982
|
* If `recursive` is not supplied, the default of `false` is used.
|
|
1818
2983
|
*/
|
|
1819
2984
|
export function watch(filename: PathLike, options: WatchOptions | string, listener?: WatchListener<string | Buffer>): FSWatcher;
|
|
1820
|
-
|
|
1821
2985
|
/**
|
|
1822
2986
|
* Watch for changes on `filename`, where `filename` is either a file or a directory, returning an `FSWatcher`.
|
|
1823
2987
|
* @param filename A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
|
|
1824
2988
|
*/
|
|
1825
2989
|
export function watch(filename: PathLike, listener?: WatchListener<string>): FSWatcher;
|
|
1826
|
-
|
|
1827
2990
|
/**
|
|
1828
|
-
*
|
|
1829
|
-
*
|
|
1830
|
-
*
|
|
2991
|
+
* Test whether or not the given path exists by checking with the file system.
|
|
2992
|
+
* Then call the `callback` argument with either true or false:
|
|
2993
|
+
*
|
|
2994
|
+
* ```js
|
|
2995
|
+
* import { exists } from 'fs';
|
|
2996
|
+
*
|
|
2997
|
+
* exists('/etc/passwd', (e) => {
|
|
2998
|
+
* console.log(e ? 'it exists' : 'no passwd!');
|
|
2999
|
+
* });
|
|
3000
|
+
* ```
|
|
3001
|
+
*
|
|
3002
|
+
* **The parameters for this callback are not consistent with other Node.js**
|
|
3003
|
+
* **callbacks.** Normally, the first parameter to a Node.js callback is an `err`parameter, optionally followed by other parameters. The `fs.exists()` callback
|
|
3004
|
+
* has only one boolean parameter. This is one reason `fs.access()` is recommended
|
|
3005
|
+
* instead of `fs.exists()`.
|
|
3006
|
+
*
|
|
3007
|
+
* Using `fs.exists()` to check for the existence of a file before calling`fs.open()`, `fs.readFile()` or `fs.writeFile()` is not recommended. Doing
|
|
3008
|
+
* so introduces a race condition, since other processes may change the file's
|
|
3009
|
+
* state between the two calls. Instead, user code should open/read/write the
|
|
3010
|
+
* file directly and handle the error raised if the file does not exist.
|
|
3011
|
+
*
|
|
3012
|
+
* **write (NOT RECOMMENDED)**
|
|
3013
|
+
*
|
|
3014
|
+
* ```js
|
|
3015
|
+
* import { exists, open, close } from 'fs';
|
|
3016
|
+
*
|
|
3017
|
+
* exists('myfile', (e) => {
|
|
3018
|
+
* if (e) {
|
|
3019
|
+
* console.error('myfile already exists');
|
|
3020
|
+
* } else {
|
|
3021
|
+
* open('myfile', 'wx', (err, fd) => {
|
|
3022
|
+
* if (err) throw err;
|
|
3023
|
+
*
|
|
3024
|
+
* try {
|
|
3025
|
+
* writeMyData(fd);
|
|
3026
|
+
* } finally {
|
|
3027
|
+
* close(fd, (err) => {
|
|
3028
|
+
* if (err) throw err;
|
|
3029
|
+
* });
|
|
3030
|
+
* }
|
|
3031
|
+
* });
|
|
3032
|
+
* }
|
|
3033
|
+
* });
|
|
3034
|
+
* ```
|
|
3035
|
+
*
|
|
3036
|
+
* **write (RECOMMENDED)**
|
|
3037
|
+
*
|
|
3038
|
+
* ```js
|
|
3039
|
+
* import { open, close } from 'fs';
|
|
3040
|
+
* open('myfile', 'wx', (err, fd) => {
|
|
3041
|
+
* if (err) {
|
|
3042
|
+
* if (err.code === 'EEXIST') {
|
|
3043
|
+
* console.error('myfile already exists');
|
|
3044
|
+
* return;
|
|
3045
|
+
* }
|
|
3046
|
+
*
|
|
3047
|
+
* throw err;
|
|
3048
|
+
* }
|
|
3049
|
+
*
|
|
3050
|
+
* try {
|
|
3051
|
+
* writeMyData(fd);
|
|
3052
|
+
* } finally {
|
|
3053
|
+
* close(fd, (err) => {
|
|
3054
|
+
* if (err) throw err;
|
|
3055
|
+
* });
|
|
3056
|
+
* }
|
|
3057
|
+
* });
|
|
3058
|
+
* ```
|
|
3059
|
+
*
|
|
3060
|
+
* **read (NOT RECOMMENDED)**
|
|
3061
|
+
*
|
|
3062
|
+
* ```js
|
|
3063
|
+
* import { open, close, exists } from 'fs';
|
|
3064
|
+
*
|
|
3065
|
+
* exists('myfile', (e) => {
|
|
3066
|
+
* if (e) {
|
|
3067
|
+
* open('myfile', 'r', (err, fd) => {
|
|
3068
|
+
* if (err) throw err;
|
|
3069
|
+
*
|
|
3070
|
+
* try {
|
|
3071
|
+
* readMyData(fd);
|
|
3072
|
+
* } finally {
|
|
3073
|
+
* close(fd, (err) => {
|
|
3074
|
+
* if (err) throw err;
|
|
3075
|
+
* });
|
|
3076
|
+
* }
|
|
3077
|
+
* });
|
|
3078
|
+
* } else {
|
|
3079
|
+
* console.error('myfile does not exist');
|
|
3080
|
+
* }
|
|
3081
|
+
* });
|
|
3082
|
+
* ```
|
|
3083
|
+
*
|
|
3084
|
+
* **read (RECOMMENDED)**
|
|
3085
|
+
*
|
|
3086
|
+
* ```js
|
|
3087
|
+
* import { open, close } from 'fs';
|
|
3088
|
+
*
|
|
3089
|
+
* open('myfile', 'r', (err, fd) => {
|
|
3090
|
+
* if (err) {
|
|
3091
|
+
* if (err.code === 'ENOENT') {
|
|
3092
|
+
* console.error('myfile does not exist');
|
|
3093
|
+
* return;
|
|
3094
|
+
* }
|
|
3095
|
+
*
|
|
3096
|
+
* throw err;
|
|
3097
|
+
* }
|
|
3098
|
+
*
|
|
3099
|
+
* try {
|
|
3100
|
+
* readMyData(fd);
|
|
3101
|
+
* } finally {
|
|
3102
|
+
* close(fd, (err) => {
|
|
3103
|
+
* if (err) throw err;
|
|
3104
|
+
* });
|
|
3105
|
+
* }
|
|
3106
|
+
* });
|
|
3107
|
+
* ```
|
|
3108
|
+
*
|
|
3109
|
+
* The "not recommended" examples above check for existence and then use the
|
|
3110
|
+
* file; the "recommended" examples are better because they use the file directly
|
|
3111
|
+
* and handle the error, if any.
|
|
3112
|
+
*
|
|
3113
|
+
* In general, check for the existence of a file only if the file won’t be
|
|
3114
|
+
* used directly, for example when its existence is a signal from another
|
|
3115
|
+
* process.
|
|
3116
|
+
* @since v0.0.2
|
|
3117
|
+
* @deprecated Since v1.0.0 - Use {@link stat} or {@link access} instead.
|
|
1831
3118
|
*/
|
|
1832
3119
|
export function exists(path: PathLike, callback: (exists: boolean) => void): void;
|
|
1833
|
-
|
|
1834
|
-
// NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
|
|
3120
|
+
/** @deprecated */
|
|
1835
3121
|
export namespace exists {
|
|
1836
3122
|
/**
|
|
1837
3123
|
* @param path A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
|
|
@@ -1839,78 +3125,70 @@ declare module 'fs' {
|
|
|
1839
3125
|
*/
|
|
1840
3126
|
function __promisify__(path: PathLike): Promise<boolean>;
|
|
1841
3127
|
}
|
|
1842
|
-
|
|
1843
3128
|
/**
|
|
1844
|
-
*
|
|
1845
|
-
*
|
|
3129
|
+
* Returns `true` if the path exists, `false` otherwise.
|
|
3130
|
+
*
|
|
3131
|
+
* For detailed information, see the documentation of the asynchronous version of
|
|
3132
|
+
* this API: {@link exists}.
|
|
3133
|
+
*
|
|
3134
|
+
* `fs.exists()` is deprecated, but `fs.existsSync()` is not. The `callback`parameter to `fs.exists()` accepts parameters that are inconsistent with other
|
|
3135
|
+
* Node.js callbacks. `fs.existsSync()` does not use a callback.
|
|
3136
|
+
*
|
|
3137
|
+
* ```js
|
|
3138
|
+
* import { existsSync } from 'fs';
|
|
3139
|
+
*
|
|
3140
|
+
* if (existsSync('/etc/passwd'))
|
|
3141
|
+
* console.log('The path exists.');
|
|
3142
|
+
* ```
|
|
3143
|
+
* @since v0.1.21
|
|
1846
3144
|
*/
|
|
1847
3145
|
export function existsSync(path: PathLike): boolean;
|
|
1848
|
-
|
|
1849
3146
|
export namespace constants {
|
|
1850
3147
|
// File Access Constants
|
|
1851
|
-
|
|
1852
3148
|
/** Constant for fs.access(). File is visible to the calling process. */
|
|
1853
3149
|
const F_OK: number;
|
|
1854
|
-
|
|
1855
3150
|
/** Constant for fs.access(). File can be read by the calling process. */
|
|
1856
3151
|
const R_OK: number;
|
|
1857
|
-
|
|
1858
3152
|
/** Constant for fs.access(). File can be written by the calling process. */
|
|
1859
3153
|
const W_OK: number;
|
|
1860
|
-
|
|
1861
3154
|
/** Constant for fs.access(). File can be executed by the calling process. */
|
|
1862
3155
|
const X_OK: number;
|
|
1863
|
-
|
|
1864
3156
|
// File Copy Constants
|
|
1865
|
-
|
|
1866
3157
|
/** Constant for fs.copyFile. Flag indicating the destination file should not be overwritten if it already exists. */
|
|
1867
3158
|
const COPYFILE_EXCL: number;
|
|
1868
|
-
|
|
1869
3159
|
/**
|
|
1870
3160
|
* Constant for fs.copyFile. copy operation will attempt to create a copy-on-write reflink.
|
|
1871
3161
|
* If the underlying platform does not support copy-on-write, then a fallback copy mechanism is used.
|
|
1872
3162
|
*/
|
|
1873
3163
|
const COPYFILE_FICLONE: number;
|
|
1874
|
-
|
|
1875
3164
|
/**
|
|
1876
3165
|
* Constant for fs.copyFile. Copy operation will attempt to create a copy-on-write reflink.
|
|
1877
3166
|
* If the underlying platform does not support copy-on-write, then the operation will fail with an error.
|
|
1878
3167
|
*/
|
|
1879
3168
|
const COPYFILE_FICLONE_FORCE: number;
|
|
1880
|
-
|
|
1881
3169
|
// File Open Constants
|
|
1882
|
-
|
|
1883
3170
|
/** Constant for fs.open(). Flag indicating to open a file for read-only access. */
|
|
1884
3171
|
const O_RDONLY: number;
|
|
1885
|
-
|
|
1886
3172
|
/** Constant for fs.open(). Flag indicating to open a file for write-only access. */
|
|
1887
3173
|
const O_WRONLY: number;
|
|
1888
|
-
|
|
1889
3174
|
/** Constant for fs.open(). Flag indicating to open a file for read-write access. */
|
|
1890
3175
|
const O_RDWR: number;
|
|
1891
|
-
|
|
1892
3176
|
/** Constant for fs.open(). Flag indicating to create the file if it does not already exist. */
|
|
1893
3177
|
const O_CREAT: number;
|
|
1894
|
-
|
|
1895
3178
|
/** Constant for fs.open(). Flag indicating that opening a file should fail if the O_CREAT flag is set and the file already exists. */
|
|
1896
3179
|
const O_EXCL: number;
|
|
1897
|
-
|
|
1898
3180
|
/**
|
|
1899
3181
|
* Constant for fs.open(). Flag indicating that if path identifies a terminal device,
|
|
1900
3182
|
* opening the path shall not cause that terminal to become the controlling terminal for the process
|
|
1901
3183
|
* (if the process does not already have one).
|
|
1902
3184
|
*/
|
|
1903
3185
|
const O_NOCTTY: number;
|
|
1904
|
-
|
|
1905
3186
|
/** Constant for fs.open(). Flag indicating that if the file exists and is a regular file, and the file is opened successfully for write access, its length shall be truncated to zero. */
|
|
1906
3187
|
const O_TRUNC: number;
|
|
1907
|
-
|
|
1908
3188
|
/** Constant for fs.open(). Flag indicating that data will be appended to the end of the file. */
|
|
1909
3189
|
const O_APPEND: number;
|
|
1910
|
-
|
|
1911
3190
|
/** Constant for fs.open(). Flag indicating that the open should fail if the path is not a directory. */
|
|
1912
3191
|
const O_DIRECTORY: number;
|
|
1913
|
-
|
|
1914
3192
|
/**
|
|
1915
3193
|
* constant for fs.open().
|
|
1916
3194
|
* Flag indicating reading accesses to the file system will no longer result in
|
|
@@ -1918,89 +3196,60 @@ declare module 'fs' {
|
|
|
1918
3196
|
* This flag is available on Linux operating systems only.
|
|
1919
3197
|
*/
|
|
1920
3198
|
const O_NOATIME: number;
|
|
1921
|
-
|
|
1922
3199
|
/** Constant for fs.open(). Flag indicating that the open should fail if the path is a symbolic link. */
|
|
1923
3200
|
const O_NOFOLLOW: number;
|
|
1924
|
-
|
|
1925
3201
|
/** Constant for fs.open(). Flag indicating that the file is opened for synchronous I/O. */
|
|
1926
3202
|
const O_SYNC: number;
|
|
1927
|
-
|
|
1928
3203
|
/** Constant for fs.open(). Flag indicating that the file is opened for synchronous I/O with write operations waiting for data integrity. */
|
|
1929
3204
|
const O_DSYNC: number;
|
|
1930
|
-
|
|
1931
3205
|
/** Constant for fs.open(). Flag indicating to open the symbolic link itself rather than the resource it is pointing to. */
|
|
1932
3206
|
const O_SYMLINK: number;
|
|
1933
|
-
|
|
1934
3207
|
/** Constant for fs.open(). When set, an attempt will be made to minimize caching effects of file I/O. */
|
|
1935
3208
|
const O_DIRECT: number;
|
|
1936
|
-
|
|
1937
3209
|
/** Constant for fs.open(). Flag indicating to open the file in nonblocking mode when possible. */
|
|
1938
3210
|
const O_NONBLOCK: number;
|
|
1939
|
-
|
|
1940
3211
|
// File Type Constants
|
|
1941
|
-
|
|
1942
3212
|
/** Constant for fs.Stats mode property for determining a file's type. Bit mask used to extract the file type code. */
|
|
1943
3213
|
const S_IFMT: number;
|
|
1944
|
-
|
|
1945
3214
|
/** Constant for fs.Stats mode property for determining a file's type. File type constant for a regular file. */
|
|
1946
3215
|
const S_IFREG: number;
|
|
1947
|
-
|
|
1948
3216
|
/** Constant for fs.Stats mode property for determining a file's type. File type constant for a directory. */
|
|
1949
3217
|
const S_IFDIR: number;
|
|
1950
|
-
|
|
1951
3218
|
/** Constant for fs.Stats mode property for determining a file's type. File type constant for a character-oriented device file. */
|
|
1952
3219
|
const S_IFCHR: number;
|
|
1953
|
-
|
|
1954
3220
|
/** Constant for fs.Stats mode property for determining a file's type. File type constant for a block-oriented device file. */
|
|
1955
3221
|
const S_IFBLK: number;
|
|
1956
|
-
|
|
1957
3222
|
/** Constant for fs.Stats mode property for determining a file's type. File type constant for a FIFO/pipe. */
|
|
1958
3223
|
const S_IFIFO: number;
|
|
1959
|
-
|
|
1960
3224
|
/** Constant for fs.Stats mode property for determining a file's type. File type constant for a symbolic link. */
|
|
1961
3225
|
const S_IFLNK: number;
|
|
1962
|
-
|
|
1963
3226
|
/** Constant for fs.Stats mode property for determining a file's type. File type constant for a socket. */
|
|
1964
3227
|
const S_IFSOCK: number;
|
|
1965
|
-
|
|
1966
3228
|
// File Mode Constants
|
|
1967
|
-
|
|
1968
3229
|
/** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating readable, writable and executable by owner. */
|
|
1969
3230
|
const S_IRWXU: number;
|
|
1970
|
-
|
|
1971
3231
|
/** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating readable by owner. */
|
|
1972
3232
|
const S_IRUSR: number;
|
|
1973
|
-
|
|
1974
3233
|
/** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating writable by owner. */
|
|
1975
3234
|
const S_IWUSR: number;
|
|
1976
|
-
|
|
1977
3235
|
/** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating executable by owner. */
|
|
1978
3236
|
const S_IXUSR: number;
|
|
1979
|
-
|
|
1980
3237
|
/** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating readable, writable and executable by group. */
|
|
1981
3238
|
const S_IRWXG: number;
|
|
1982
|
-
|
|
1983
3239
|
/** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating readable by group. */
|
|
1984
3240
|
const S_IRGRP: number;
|
|
1985
|
-
|
|
1986
3241
|
/** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating writable by group. */
|
|
1987
3242
|
const S_IWGRP: number;
|
|
1988
|
-
|
|
1989
3243
|
/** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating executable by group. */
|
|
1990
3244
|
const S_IXGRP: number;
|
|
1991
|
-
|
|
1992
3245
|
/** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating readable, writable and executable by others. */
|
|
1993
3246
|
const S_IRWXO: number;
|
|
1994
|
-
|
|
1995
3247
|
/** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating readable by others. */
|
|
1996
3248
|
const S_IROTH: number;
|
|
1997
|
-
|
|
1998
3249
|
/** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating writable by others. */
|
|
1999
3250
|
const S_IWOTH: number;
|
|
2000
|
-
|
|
2001
3251
|
/** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating executable by others. */
|
|
2002
3252
|
const S_IXOTH: number;
|
|
2003
|
-
|
|
2004
3253
|
/**
|
|
2005
3254
|
* When set, a memory file mapping is used to access the file. This flag
|
|
2006
3255
|
* is available on Windows operating systems only. On other operating systems,
|
|
@@ -2008,20 +3257,172 @@ declare module 'fs' {
|
|
|
2008
3257
|
*/
|
|
2009
3258
|
const UV_FS_O_FILEMAP: number;
|
|
2010
3259
|
}
|
|
2011
|
-
|
|
2012
3260
|
/**
|
|
2013
|
-
*
|
|
2014
|
-
*
|
|
3261
|
+
* Tests a user's permissions for the file or directory specified by `path`.
|
|
3262
|
+
* The `mode` argument is an optional integer that specifies the accessibility
|
|
3263
|
+
* 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`
|
|
3264
|
+
* (e.g.`fs.constants.W_OK | fs.constants.R_OK`). Check `File access constants` for
|
|
3265
|
+
* possible values of `mode`.
|
|
3266
|
+
*
|
|
3267
|
+
* The final argument, `callback`, is a callback function that is invoked with
|
|
3268
|
+
* a possible error argument. If any of the accessibility checks fail, the error
|
|
3269
|
+
* argument will be an `Error` object. The following examples check if`package.json` exists, and if it is readable or writable.
|
|
3270
|
+
*
|
|
3271
|
+
* ```js
|
|
3272
|
+
* import { access, constants } from 'fs';
|
|
3273
|
+
*
|
|
3274
|
+
* const file = 'package.json';
|
|
3275
|
+
*
|
|
3276
|
+
* // Check if the file exists in the current directory.
|
|
3277
|
+
* access(file, constants.F_OK, (err) => {
|
|
3278
|
+
* console.log(`${file} ${err ? 'does not exist' : 'exists'}`);
|
|
3279
|
+
* });
|
|
3280
|
+
*
|
|
3281
|
+
* // Check if the file is readable.
|
|
3282
|
+
* access(file, constants.R_OK, (err) => {
|
|
3283
|
+
* console.log(`${file} ${err ? 'is not readable' : 'is readable'}`);
|
|
3284
|
+
* });
|
|
3285
|
+
*
|
|
3286
|
+
* // Check if the file is writable.
|
|
3287
|
+
* access(file, constants.W_OK, (err) => {
|
|
3288
|
+
* console.log(`${file} ${err ? 'is not writable' : 'is writable'}`);
|
|
3289
|
+
* });
|
|
3290
|
+
*
|
|
3291
|
+
* // Check if the file is readable and writable.
|
|
3292
|
+
* access(file, constants.R_OK | constants.W_OK, (err) => {
|
|
3293
|
+
* console.log(`${file} ${err ? 'is not' : 'is'} readable and writable`);
|
|
3294
|
+
* });
|
|
3295
|
+
* ```
|
|
3296
|
+
*
|
|
3297
|
+
* Do not use `fs.access()` to check for the accessibility of a file before calling`fs.open()`, `fs.readFile()` or `fs.writeFile()`. Doing
|
|
3298
|
+
* so introduces a race condition, since other processes may change the file's
|
|
3299
|
+
* state between the two calls. Instead, user code should open/read/write the
|
|
3300
|
+
* file directly and handle the error raised if the file is not accessible.
|
|
3301
|
+
*
|
|
3302
|
+
* **write (NOT RECOMMENDED)**
|
|
3303
|
+
*
|
|
3304
|
+
* ```js
|
|
3305
|
+
* import { access, open, close } from 'fs';
|
|
3306
|
+
*
|
|
3307
|
+
* access('myfile', (err) => {
|
|
3308
|
+
* if (!err) {
|
|
3309
|
+
* console.error('myfile already exists');
|
|
3310
|
+
* return;
|
|
3311
|
+
* }
|
|
3312
|
+
*
|
|
3313
|
+
* open('myfile', 'wx', (err, fd) => {
|
|
3314
|
+
* if (err) throw err;
|
|
3315
|
+
*
|
|
3316
|
+
* try {
|
|
3317
|
+
* writeMyData(fd);
|
|
3318
|
+
* } finally {
|
|
3319
|
+
* close(fd, (err) => {
|
|
3320
|
+
* if (err) throw err;
|
|
3321
|
+
* });
|
|
3322
|
+
* }
|
|
3323
|
+
* });
|
|
3324
|
+
* });
|
|
3325
|
+
* ```
|
|
3326
|
+
*
|
|
3327
|
+
* **write (RECOMMENDED)**
|
|
3328
|
+
*
|
|
3329
|
+
* ```js
|
|
3330
|
+
* import { open, close } from 'fs';
|
|
3331
|
+
*
|
|
3332
|
+
* open('myfile', 'wx', (err, fd) => {
|
|
3333
|
+
* if (err) {
|
|
3334
|
+
* if (err.code === 'EEXIST') {
|
|
3335
|
+
* console.error('myfile already exists');
|
|
3336
|
+
* return;
|
|
3337
|
+
* }
|
|
3338
|
+
*
|
|
3339
|
+
* throw err;
|
|
3340
|
+
* }
|
|
3341
|
+
*
|
|
3342
|
+
* try {
|
|
3343
|
+
* writeMyData(fd);
|
|
3344
|
+
* } finally {
|
|
3345
|
+
* close(fd, (err) => {
|
|
3346
|
+
* if (err) throw err;
|
|
3347
|
+
* });
|
|
3348
|
+
* }
|
|
3349
|
+
* });
|
|
3350
|
+
* ```
|
|
3351
|
+
*
|
|
3352
|
+
* **read (NOT RECOMMENDED)**
|
|
3353
|
+
*
|
|
3354
|
+
* ```js
|
|
3355
|
+
* import { access, open, close } from 'fs';
|
|
3356
|
+
* access('myfile', (err) => {
|
|
3357
|
+
* if (err) {
|
|
3358
|
+
* if (err.code === 'ENOENT') {
|
|
3359
|
+
* console.error('myfile does not exist');
|
|
3360
|
+
* return;
|
|
3361
|
+
* }
|
|
3362
|
+
*
|
|
3363
|
+
* throw err;
|
|
3364
|
+
* }
|
|
3365
|
+
*
|
|
3366
|
+
* open('myfile', 'r', (err, fd) => {
|
|
3367
|
+
* if (err) throw err;
|
|
3368
|
+
*
|
|
3369
|
+
* try {
|
|
3370
|
+
* readMyData(fd);
|
|
3371
|
+
* } finally {
|
|
3372
|
+
* close(fd, (err) => {
|
|
3373
|
+
* if (err) throw err;
|
|
3374
|
+
* });
|
|
3375
|
+
* }
|
|
3376
|
+
* });
|
|
3377
|
+
* });
|
|
3378
|
+
* ```
|
|
3379
|
+
*
|
|
3380
|
+
* **read (RECOMMENDED)**
|
|
3381
|
+
*
|
|
3382
|
+
* ```js
|
|
3383
|
+
* import { open, close } from 'fs';
|
|
3384
|
+
*
|
|
3385
|
+
* open('myfile', 'r', (err, fd) => {
|
|
3386
|
+
* if (err) {
|
|
3387
|
+
* if (err.code === 'ENOENT') {
|
|
3388
|
+
* console.error('myfile does not exist');
|
|
3389
|
+
* return;
|
|
3390
|
+
* }
|
|
3391
|
+
*
|
|
3392
|
+
* throw err;
|
|
3393
|
+
* }
|
|
3394
|
+
*
|
|
3395
|
+
* try {
|
|
3396
|
+
* readMyData(fd);
|
|
3397
|
+
* } finally {
|
|
3398
|
+
* close(fd, (err) => {
|
|
3399
|
+
* if (err) throw err;
|
|
3400
|
+
* });
|
|
3401
|
+
* }
|
|
3402
|
+
* });
|
|
3403
|
+
* ```
|
|
3404
|
+
*
|
|
3405
|
+
* The "not recommended" examples above check for accessibility and then use the
|
|
3406
|
+
* file; the "recommended" examples are better because they use the file directly
|
|
3407
|
+
* and handle the error, if any.
|
|
3408
|
+
*
|
|
3409
|
+
* In general, check for the accessibility of a file only if the file will not be
|
|
3410
|
+
* used directly, for example when its accessibility is a signal from another
|
|
3411
|
+
* process.
|
|
3412
|
+
*
|
|
3413
|
+
* On Windows, access-control policies (ACLs) on a directory may limit access to
|
|
3414
|
+
* a file or directory. The `fs.access()` function, however, does not check the
|
|
3415
|
+
* ACL and therefore may report that a path is accessible even if the ACL restricts
|
|
3416
|
+
* the user from reading or writing to it.
|
|
3417
|
+
* @since v0.11.15
|
|
3418
|
+
* @param [mode=fs.constants.F_OK]
|
|
2015
3419
|
*/
|
|
2016
3420
|
export function access(path: PathLike, mode: number | undefined, callback: NoParamCallback): void;
|
|
2017
|
-
|
|
2018
3421
|
/**
|
|
2019
3422
|
* Asynchronously tests a user's permissions for the file specified by path.
|
|
2020
3423
|
* @param path A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
|
|
2021
3424
|
*/
|
|
2022
3425
|
export function access(path: PathLike, callback: NoParamCallback): void;
|
|
2023
|
-
|
|
2024
|
-
// NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
|
|
2025
3426
|
export namespace access {
|
|
2026
3427
|
/**
|
|
2027
3428
|
* Asynchronously tests a user's permissions for the file specified by path.
|
|
@@ -2030,50 +3431,147 @@ declare module 'fs' {
|
|
|
2030
3431
|
*/
|
|
2031
3432
|
function __promisify__(path: PathLike, mode?: number): Promise<void>;
|
|
2032
3433
|
}
|
|
2033
|
-
|
|
2034
3434
|
/**
|
|
2035
|
-
* Synchronously tests a user's permissions for the file
|
|
2036
|
-
*
|
|
3435
|
+
* Synchronously tests a user's permissions for the file or directory specified
|
|
3436
|
+
* by `path`. The `mode` argument is an optional integer that specifies the
|
|
3437
|
+
* accessibility 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
|
|
3438
|
+
* `fs.constants.X_OK` (e.g.`fs.constants.W_OK | fs.constants.R_OK`). Check `File access constants` for
|
|
3439
|
+
* possible values of `mode`.
|
|
3440
|
+
*
|
|
3441
|
+
* If any of the accessibility checks fail, an `Error` will be thrown. Otherwise,
|
|
3442
|
+
* the method will return `undefined`.
|
|
3443
|
+
*
|
|
3444
|
+
* ```js
|
|
3445
|
+
* import { accessSync, constants } from 'fs';
|
|
3446
|
+
*
|
|
3447
|
+
* try {
|
|
3448
|
+
* accessSync('etc/passwd', constants.R_OK | constants.W_OK);
|
|
3449
|
+
* console.log('can read/write');
|
|
3450
|
+
* } catch (err) {
|
|
3451
|
+
* console.error('no access!');
|
|
3452
|
+
* }
|
|
3453
|
+
* ```
|
|
3454
|
+
* @since v0.11.15
|
|
3455
|
+
* @param [mode=fs.constants.F_OK]
|
|
2037
3456
|
*/
|
|
2038
3457
|
export function accessSync(path: PathLike, mode?: number): void;
|
|
2039
|
-
|
|
2040
3458
|
interface StreamOptions {
|
|
2041
|
-
flags?: string;
|
|
2042
|
-
encoding?: BufferEncoding;
|
|
2043
|
-
fd?: number | promises.FileHandle;
|
|
2044
|
-
mode?: number;
|
|
2045
|
-
autoClose?: boolean;
|
|
3459
|
+
flags?: string | undefined;
|
|
3460
|
+
encoding?: BufferEncoding | undefined;
|
|
3461
|
+
fd?: number | promises.FileHandle | undefined;
|
|
3462
|
+
mode?: number | undefined;
|
|
3463
|
+
autoClose?: boolean | undefined;
|
|
2046
3464
|
/**
|
|
2047
3465
|
* @default false
|
|
2048
3466
|
*/
|
|
2049
|
-
emitClose?: boolean;
|
|
2050
|
-
start?: number;
|
|
2051
|
-
highWaterMark?: number;
|
|
3467
|
+
emitClose?: boolean | undefined;
|
|
3468
|
+
start?: number | undefined;
|
|
3469
|
+
highWaterMark?: number | undefined;
|
|
2052
3470
|
}
|
|
2053
|
-
|
|
2054
3471
|
interface ReadStreamOptions extends StreamOptions {
|
|
2055
|
-
end?: number;
|
|
2056
|
-
}
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
*
|
|
2060
|
-
*
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
*
|
|
2066
|
-
*
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
*
|
|
2072
|
-
*
|
|
3472
|
+
end?: number | undefined;
|
|
3473
|
+
}
|
|
3474
|
+
/**
|
|
3475
|
+
* Unlike the 16 kb default `highWaterMark` for a `stream.Readable`, the stream
|
|
3476
|
+
* returned by this method has a default `highWaterMark` of 64 kb.
|
|
3477
|
+
*
|
|
3478
|
+
* `options` can include `start` and `end` values to read a range of bytes from
|
|
3479
|
+
* the file instead of the entire file. Both `start` and `end` are inclusive and
|
|
3480
|
+
* start counting at 0, allowed values are in the
|
|
3481
|
+
* \[0, [`Number.MAX_SAFE_INTEGER`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER)\] range. If `fd` is specified and `start` is
|
|
3482
|
+
* omitted or `undefined`, `fs.createReadStream()` reads sequentially from the
|
|
3483
|
+
* current file position. The `encoding` can be any one of those accepted by `Buffer`.
|
|
3484
|
+
*
|
|
3485
|
+
* If `fd` is specified, `ReadStream` will ignore the `path` argument and will use
|
|
3486
|
+
* the specified file descriptor. This means that no `'open'` event will be
|
|
3487
|
+
* emitted. `fd` should be blocking; non-blocking `fd`s should be passed to `net.Socket`.
|
|
3488
|
+
*
|
|
3489
|
+
* If `fd` points to a character device that only supports blocking reads
|
|
3490
|
+
* (such as keyboard or sound card), read operations do not finish until data is
|
|
3491
|
+
* available. This can prevent the process from exiting and the stream from
|
|
3492
|
+
* closing naturally.
|
|
3493
|
+
*
|
|
3494
|
+
* By default, the stream will emit a `'close'` event after it has been
|
|
3495
|
+
* destroyed. Set the `emitClose` option to `false` to change this behavior.
|
|
3496
|
+
*
|
|
3497
|
+
* By providing the `fs` option, it is possible to override the corresponding `fs`implementations for `open`, `read`, and `close`. When providing the `fs` option,
|
|
3498
|
+
* an override for `read` is required. If no `fd` is provided, an override for`open` is also required. If `autoClose` is `true`, an override for `close` is
|
|
3499
|
+
* also required.
|
|
3500
|
+
*
|
|
3501
|
+
* ```js
|
|
3502
|
+
* import { createReadStream } from 'fs';
|
|
3503
|
+
*
|
|
3504
|
+
* // Create a stream from some character device.
|
|
3505
|
+
* const stream = createReadStream('/dev/input/event0');
|
|
3506
|
+
* setTimeout(() => {
|
|
3507
|
+
* stream.close(); // This may not close the stream.
|
|
3508
|
+
* // Artificially marking end-of-stream, as if the underlying resource had
|
|
3509
|
+
* // indicated end-of-file by itself, allows the stream to close.
|
|
3510
|
+
* // This does not cancel pending read operations, and if there is such an
|
|
3511
|
+
* // operation, the process may still not be able to exit successfully
|
|
3512
|
+
* // until it finishes.
|
|
3513
|
+
* stream.push(null);
|
|
3514
|
+
* stream.read(0);
|
|
3515
|
+
* }, 100);
|
|
3516
|
+
* ```
|
|
3517
|
+
*
|
|
3518
|
+
* If `autoClose` is false, then the file descriptor won't be closed, even if
|
|
3519
|
+
* there's an error. It is the application's responsibility to close it and make
|
|
3520
|
+
* sure there's no file descriptor leak. If `autoClose` is set to true (default
|
|
3521
|
+
* behavior), on `'error'` or `'end'` the file descriptor will be closed
|
|
3522
|
+
* automatically.
|
|
3523
|
+
*
|
|
3524
|
+
* `mode` sets the file mode (permission and sticky bits), but only if the
|
|
3525
|
+
* file was created.
|
|
3526
|
+
*
|
|
3527
|
+
* An example to read the last 10 bytes of a file which is 100 bytes long:
|
|
3528
|
+
*
|
|
3529
|
+
* ```js
|
|
3530
|
+
* import { createReadStream } from 'fs';
|
|
3531
|
+
*
|
|
3532
|
+
* createReadStream('sample.txt', { start: 90, end: 99 });
|
|
3533
|
+
* ```
|
|
3534
|
+
*
|
|
3535
|
+
* If `options` is a string, then it specifies the encoding.
|
|
3536
|
+
* @since v0.1.31
|
|
3537
|
+
*/
|
|
3538
|
+
export function createReadStream(path: PathLike, options?: BufferEncoding | ReadStreamOptions): ReadStream;
|
|
3539
|
+
/**
|
|
3540
|
+
* `options` may also include a `start` option to allow writing data at some
|
|
3541
|
+
* position past the beginning of the file, allowed values are in the
|
|
3542
|
+
* \[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
|
|
3543
|
+
* replacing it may require the `flags` option to be set to `r+` rather than the
|
|
3544
|
+
* default `w`. The `encoding` can be any one of those accepted by `Buffer`.
|
|
3545
|
+
*
|
|
3546
|
+
* If `autoClose` is set to true (default behavior) on `'error'` or `'finish'`the file descriptor will be closed automatically. If `autoClose` is false,
|
|
3547
|
+
* then the file descriptor won't be closed, even if there's an error.
|
|
3548
|
+
* It is the application's responsibility to close it and make sure there's no
|
|
3549
|
+
* file descriptor leak.
|
|
3550
|
+
*
|
|
3551
|
+
* By default, the stream will emit a `'close'` event after it has been
|
|
3552
|
+
* destroyed. Set the `emitClose` option to `false` to change this behavior.
|
|
3553
|
+
*
|
|
3554
|
+
* By providing the `fs` option it is possible to override the corresponding `fs`implementations for `open`, `write`, `writev` and `close`. Overriding `write()`without `writev()` can reduce
|
|
3555
|
+
* performance as some optimizations (`_writev()`)
|
|
3556
|
+
* will be disabled. When providing the `fs` option, overrides for at least one of`write` and `writev` are required. If no `fd` option is supplied, an override
|
|
3557
|
+
* for `open` is also required. If `autoClose` is `true`, an override for `close`is also required.
|
|
3558
|
+
*
|
|
3559
|
+
* Like `fs.ReadStream`, if `fd` is specified, `fs.WriteStream` will ignore the`path` argument and will use the specified file descriptor. This means that no`'open'` event will be
|
|
3560
|
+
* emitted. `fd` should be blocking; non-blocking `fd`s
|
|
3561
|
+
* should be passed to `net.Socket`.
|
|
3562
|
+
*
|
|
3563
|
+
* If `options` is a string, then it specifies the encoding.
|
|
3564
|
+
* @since v0.1.31
|
|
3565
|
+
*/
|
|
3566
|
+
export function createWriteStream(path: PathLike, options?: BufferEncoding | StreamOptions): WriteStream;
|
|
3567
|
+
/**
|
|
3568
|
+
* Forces all currently queued I/O operations associated with the file to the
|
|
3569
|
+
* 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. No arguments other
|
|
3570
|
+
* than a possible
|
|
3571
|
+
* exception are given to the completion callback.
|
|
3572
|
+
* @since v0.1.96
|
|
2073
3573
|
*/
|
|
2074
3574
|
export function fdatasync(fd: number, callback: NoParamCallback): void;
|
|
2075
|
-
|
|
2076
|
-
// NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
|
|
2077
3575
|
export namespace fdatasync {
|
|
2078
3576
|
/**
|
|
2079
3577
|
* Asynchronous fdatasync(2) - synchronize a file's in-core state with storage device.
|
|
@@ -2081,159 +3579,294 @@ declare module 'fs' {
|
|
|
2081
3579
|
*/
|
|
2082
3580
|
function __promisify__(fd: number): Promise<void>;
|
|
2083
3581
|
}
|
|
2084
|
-
|
|
2085
3582
|
/**
|
|
2086
|
-
*
|
|
2087
|
-
*
|
|
3583
|
+
* Forces all currently queued I/O operations associated with the file to the
|
|
3584
|
+
* 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. Returns `undefined`.
|
|
3585
|
+
* @since v0.1.96
|
|
2088
3586
|
*/
|
|
2089
3587
|
export function fdatasyncSync(fd: number): void;
|
|
2090
|
-
|
|
2091
3588
|
/**
|
|
2092
|
-
* Asynchronously copies src to dest
|
|
2093
|
-
* No arguments other than a possible exception are given to the
|
|
2094
|
-
* Node.js makes no guarantees about the atomicity of the copy
|
|
2095
|
-
* If an error occurs after the destination file has been opened for
|
|
2096
|
-
* to remove the destination.
|
|
2097
|
-
*
|
|
2098
|
-
*
|
|
3589
|
+
* Asynchronously copies `src` to `dest`. By default, `dest` is overwritten if it
|
|
3590
|
+
* already exists. No arguments other than a possible exception are given to the
|
|
3591
|
+
* callback function. Node.js makes no guarantees about the atomicity of the copy
|
|
3592
|
+
* operation. If an error occurs after the destination file has been opened for
|
|
3593
|
+
* writing, Node.js will attempt to remove the destination.
|
|
3594
|
+
*
|
|
3595
|
+
* `mode` is an optional integer that specifies the behavior
|
|
3596
|
+
* of the copy operation. It is possible to create a mask consisting of the bitwise
|
|
3597
|
+
* OR of two or more values (e.g.`fs.constants.COPYFILE_EXCL | fs.constants.COPYFILE_FICLONE`).
|
|
3598
|
+
*
|
|
3599
|
+
* * `fs.constants.COPYFILE_EXCL`: The copy operation will fail if `dest` already
|
|
3600
|
+
* exists.
|
|
3601
|
+
* * `fs.constants.COPYFILE_FICLONE`: The copy operation will attempt to create a
|
|
3602
|
+
* copy-on-write reflink. If the platform does not support copy-on-write, then a
|
|
3603
|
+
* fallback copy mechanism is used.
|
|
3604
|
+
* * `fs.constants.COPYFILE_FICLONE_FORCE`: The copy operation will attempt to
|
|
3605
|
+
* create a copy-on-write reflink. If the platform does not support
|
|
3606
|
+
* copy-on-write, then the operation will fail.
|
|
3607
|
+
*
|
|
3608
|
+
* ```js
|
|
3609
|
+
* import { copyFile, constants } from 'fs';
|
|
3610
|
+
*
|
|
3611
|
+
* function callback(err) {
|
|
3612
|
+
* if (err) throw err;
|
|
3613
|
+
* console.log('source.txt was copied to destination.txt');
|
|
3614
|
+
* }
|
|
3615
|
+
*
|
|
3616
|
+
* // destination.txt will be created or overwritten by default.
|
|
3617
|
+
* copyFile('source.txt', 'destination.txt', callback);
|
|
3618
|
+
*
|
|
3619
|
+
* // By using COPYFILE_EXCL, the operation will fail if destination.txt exists.
|
|
3620
|
+
* copyFile('source.txt', 'destination.txt', constants.COPYFILE_EXCL, callback);
|
|
3621
|
+
* ```
|
|
3622
|
+
* @since v8.5.0
|
|
3623
|
+
* @param src source filename to copy
|
|
3624
|
+
* @param dest destination filename of the copy operation
|
|
3625
|
+
* @param [mode=0] modifiers for copy operation.
|
|
2099
3626
|
*/
|
|
2100
3627
|
export function copyFile(src: PathLike, dest: PathLike, callback: NoParamCallback): void;
|
|
2101
|
-
|
|
2102
|
-
* Asynchronously copies src to dest. By default, dest is overwritten if it already exists.
|
|
2103
|
-
* No arguments other than a possible exception are given to the callback function.
|
|
2104
|
-
* Node.js makes no guarantees about the atomicity of the copy operation.
|
|
2105
|
-
* If an error occurs after the destination file has been opened for writing, Node.js will attempt
|
|
2106
|
-
* to remove the destination.
|
|
2107
|
-
* @param src A path to the source file.
|
|
2108
|
-
* @param dest A path to the destination file.
|
|
2109
|
-
* @param flags An integer that specifies the behavior of the copy operation. The only supported flag is fs.constants.COPYFILE_EXCL, which causes the copy operation to fail if dest already exists.
|
|
2110
|
-
*/
|
|
2111
|
-
export function copyFile(src: PathLike, dest: PathLike, flags: number, callback: NoParamCallback): void;
|
|
2112
|
-
|
|
2113
|
-
// NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
|
|
3628
|
+
export function copyFile(src: PathLike, dest: PathLike, mode: number, callback: NoParamCallback): void;
|
|
2114
3629
|
export namespace copyFile {
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
*
|
|
2132
|
-
*
|
|
2133
|
-
*
|
|
2134
|
-
*
|
|
2135
|
-
*
|
|
2136
|
-
*
|
|
2137
|
-
*
|
|
2138
|
-
*
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
*
|
|
2144
|
-
*
|
|
2145
|
-
*
|
|
3630
|
+
function __promisify__(src: PathLike, dst: PathLike, mode?: number): Promise<void>;
|
|
3631
|
+
}
|
|
3632
|
+
/**
|
|
3633
|
+
* Synchronously copies `src` to `dest`. By default, `dest` is overwritten if it
|
|
3634
|
+
* already exists. Returns `undefined`. Node.js makes no guarantees about the
|
|
3635
|
+
* atomicity of the copy operation. If an error occurs after the destination file
|
|
3636
|
+
* has been opened for writing, Node.js will attempt to remove the destination.
|
|
3637
|
+
*
|
|
3638
|
+
* `mode` is an optional integer that specifies the behavior
|
|
3639
|
+
* of the copy operation. It is possible to create a mask consisting of the bitwise
|
|
3640
|
+
* OR of two or more values (e.g.`fs.constants.COPYFILE_EXCL | fs.constants.COPYFILE_FICLONE`).
|
|
3641
|
+
*
|
|
3642
|
+
* * `fs.constants.COPYFILE_EXCL`: The copy operation will fail if `dest` already
|
|
3643
|
+
* exists.
|
|
3644
|
+
* * `fs.constants.COPYFILE_FICLONE`: The copy operation will attempt to create a
|
|
3645
|
+
* copy-on-write reflink. If the platform does not support copy-on-write, then a
|
|
3646
|
+
* fallback copy mechanism is used.
|
|
3647
|
+
* * `fs.constants.COPYFILE_FICLONE_FORCE`: The copy operation will attempt to
|
|
3648
|
+
* create a copy-on-write reflink. If the platform does not support
|
|
3649
|
+
* copy-on-write, then the operation will fail.
|
|
3650
|
+
*
|
|
3651
|
+
* ```js
|
|
3652
|
+
* import { copyFileSync, constants } from 'fs';
|
|
3653
|
+
*
|
|
3654
|
+
* // destination.txt will be created or overwritten by default.
|
|
3655
|
+
* copyFileSync('source.txt', 'destination.txt');
|
|
3656
|
+
* console.log('source.txt was copied to destination.txt');
|
|
3657
|
+
*
|
|
3658
|
+
* // By using COPYFILE_EXCL, the operation will fail if destination.txt exists.
|
|
3659
|
+
* copyFileSync('source.txt', 'destination.txt', constants.COPYFILE_EXCL);
|
|
3660
|
+
* ```
|
|
3661
|
+
* @since v8.5.0
|
|
3662
|
+
* @param src source filename to copy
|
|
3663
|
+
* @param dest destination filename of the copy operation
|
|
3664
|
+
* @param [mode=0] modifiers for copy operation.
|
|
3665
|
+
*/
|
|
3666
|
+
export function copyFileSync(src: PathLike, dest: PathLike, mode?: number): void;
|
|
3667
|
+
/**
|
|
3668
|
+
* Write an array of `ArrayBufferView`s to the file specified by `fd` using`writev()`.
|
|
3669
|
+
*
|
|
3670
|
+
* `position` is the offset from the beginning of the file where this data
|
|
3671
|
+
* should be written. If `typeof position !== 'number'`, the data will be written
|
|
3672
|
+
* at the current position.
|
|
3673
|
+
*
|
|
3674
|
+
* The callback will be given three arguments: `err`, `bytesWritten`, and`buffers`. `bytesWritten` is how many bytes were written from `buffers`.
|
|
3675
|
+
*
|
|
3676
|
+
* If this method is `util.promisify()` ed, it returns a promise for an`Object` with `bytesWritten` and `buffers` properties.
|
|
3677
|
+
*
|
|
3678
|
+
* It is unsafe to use `fs.writev()` multiple times on the same file without
|
|
3679
|
+
* waiting for the callback. For this scenario, use {@link createWriteStream}.
|
|
3680
|
+
*
|
|
2146
3681
|
* On Linux, positional writes don't work when the file is opened in append mode.
|
|
2147
|
-
* The kernel ignores the position argument and always appends the data to
|
|
3682
|
+
* The kernel ignores the position argument and always appends the data to
|
|
3683
|
+
* the end of the file.
|
|
3684
|
+
* @since v12.9.0
|
|
2148
3685
|
*/
|
|
2149
|
-
export function writev(
|
|
2150
|
-
fd: number,
|
|
2151
|
-
buffers: ReadonlyArray<NodeJS.ArrayBufferView>,
|
|
2152
|
-
cb: (err: NodeJS.ErrnoException | null, bytesWritten: number, buffers: NodeJS.ArrayBufferView[]) => void
|
|
2153
|
-
): void;
|
|
3686
|
+
export function writev(fd: number, buffers: ReadonlyArray<NodeJS.ArrayBufferView>, cb: (err: NodeJS.ErrnoException | null, bytesWritten: number, buffers: NodeJS.ArrayBufferView[]) => void): void;
|
|
2154
3687
|
export function writev(
|
|
2155
3688
|
fd: number,
|
|
2156
3689
|
buffers: ReadonlyArray<NodeJS.ArrayBufferView>,
|
|
2157
3690
|
position: number,
|
|
2158
3691
|
cb: (err: NodeJS.ErrnoException | null, bytesWritten: number, buffers: NodeJS.ArrayBufferView[]) => void
|
|
2159
3692
|
): void;
|
|
2160
|
-
|
|
2161
3693
|
export interface WriteVResult {
|
|
2162
3694
|
bytesWritten: number;
|
|
2163
3695
|
buffers: NodeJS.ArrayBufferView[];
|
|
2164
3696
|
}
|
|
2165
|
-
|
|
2166
3697
|
export namespace writev {
|
|
2167
3698
|
function __promisify__(fd: number, buffers: ReadonlyArray<NodeJS.ArrayBufferView>, position?: number): Promise<WriteVResult>;
|
|
2168
3699
|
}
|
|
2169
|
-
|
|
2170
3700
|
/**
|
|
2171
|
-
*
|
|
3701
|
+
* For detailed information, see the documentation of the asynchronous version of
|
|
3702
|
+
* this API: {@link writev}.
|
|
3703
|
+
* @since v12.9.0
|
|
3704
|
+
* @return The number of bytes written.
|
|
2172
3705
|
*/
|
|
2173
3706
|
export function writevSync(fd: number, buffers: ReadonlyArray<NodeJS.ArrayBufferView>, position?: number): number;
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
3707
|
+
/**
|
|
3708
|
+
* Read from a file specified by `fd` and write to an array of `ArrayBufferView`s
|
|
3709
|
+
* using `readv()`.
|
|
3710
|
+
*
|
|
3711
|
+
* `position` is the offset from the beginning of the file from where data
|
|
3712
|
+
* should be read. If `typeof position !== 'number'`, the data will be read
|
|
3713
|
+
* from the current position.
|
|
3714
|
+
*
|
|
3715
|
+
* The callback will be given three arguments: `err`, `bytesRead`, and`buffers`. `bytesRead` is how many bytes were read from the file.
|
|
3716
|
+
*
|
|
3717
|
+
* If this method is invoked as its `util.promisify()` ed version, it returns
|
|
3718
|
+
* a promise for an `Object` with `bytesRead` and `buffers` properties.
|
|
3719
|
+
* @since v13.13.0, v12.17.0
|
|
3720
|
+
*/
|
|
3721
|
+
export function readv(fd: number, buffers: ReadonlyArray<NodeJS.ArrayBufferView>, cb: (err: NodeJS.ErrnoException | null, bytesRead: number, buffers: NodeJS.ArrayBufferView[]) => void): void;
|
|
2180
3722
|
export function readv(
|
|
2181
3723
|
fd: number,
|
|
2182
3724
|
buffers: ReadonlyArray<NodeJS.ArrayBufferView>,
|
|
2183
3725
|
position: number,
|
|
2184
3726
|
cb: (err: NodeJS.ErrnoException | null, bytesRead: number, buffers: NodeJS.ArrayBufferView[]) => void
|
|
2185
3727
|
): void;
|
|
2186
|
-
|
|
2187
3728
|
export interface ReadVResult {
|
|
2188
3729
|
bytesRead: number;
|
|
2189
3730
|
buffers: NodeJS.ArrayBufferView[];
|
|
2190
3731
|
}
|
|
2191
|
-
|
|
2192
3732
|
export namespace readv {
|
|
2193
3733
|
function __promisify__(fd: number, buffers: ReadonlyArray<NodeJS.ArrayBufferView>, position?: number): Promise<ReadVResult>;
|
|
2194
3734
|
}
|
|
2195
|
-
|
|
2196
3735
|
/**
|
|
2197
|
-
*
|
|
3736
|
+
* For detailed information, see the documentation of the asynchronous version of
|
|
3737
|
+
* this API: {@link readv}.
|
|
3738
|
+
* @since v13.13.0, v12.17.0
|
|
3739
|
+
* @return The number of bytes read.
|
|
2198
3740
|
*/
|
|
2199
3741
|
export function readvSync(fd: number, buffers: ReadonlyArray<NodeJS.ArrayBufferView>, position?: number): number;
|
|
2200
|
-
|
|
2201
3742
|
export interface OpenDirOptions {
|
|
2202
|
-
encoding?: BufferEncoding;
|
|
3743
|
+
encoding?: BufferEncoding | undefined;
|
|
2203
3744
|
/**
|
|
2204
3745
|
* Number of directory entries that are buffered
|
|
2205
3746
|
* internally when reading from the directory. Higher values lead to better
|
|
2206
3747
|
* performance but higher memory usage.
|
|
2207
3748
|
* @default 32
|
|
2208
3749
|
*/
|
|
2209
|
-
bufferSize?: number;
|
|
3750
|
+
bufferSize?: number | undefined;
|
|
2210
3751
|
}
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
3752
|
+
/**
|
|
3753
|
+
* Synchronously open a directory. See [`opendir(3)`](http://man7.org/linux/man-pages/man3/opendir.3.html).
|
|
3754
|
+
*
|
|
3755
|
+
* Creates an `fs.Dir`, which contains all further functions for reading from
|
|
3756
|
+
* and cleaning up the directory.
|
|
3757
|
+
*
|
|
3758
|
+
* The `encoding` option sets the encoding for the `path` while opening the
|
|
3759
|
+
* directory and subsequent read operations.
|
|
3760
|
+
* @since v12.12.0
|
|
3761
|
+
*/
|
|
3762
|
+
export function opendirSync(path: PathLike, options?: OpenDirOptions): Dir;
|
|
3763
|
+
/**
|
|
3764
|
+
* Asynchronously open a directory. See the POSIX [`opendir(3)`](http://man7.org/linux/man-pages/man3/opendir.3.html) documentation for
|
|
3765
|
+
* more details.
|
|
3766
|
+
*
|
|
3767
|
+
* Creates an `fs.Dir`, which contains all further functions for reading from
|
|
3768
|
+
* and cleaning up the directory.
|
|
3769
|
+
*
|
|
3770
|
+
* The `encoding` option sets the encoding for the `path` while opening the
|
|
3771
|
+
* directory and subsequent read operations.
|
|
3772
|
+
* @since v12.12.0
|
|
3773
|
+
*/
|
|
3774
|
+
export function opendir(path: PathLike, cb: (err: NodeJS.ErrnoException | null, dir: Dir) => void): void;
|
|
3775
|
+
export function opendir(path: PathLike, options: OpenDirOptions, cb: (err: NodeJS.ErrnoException | null, dir: Dir) => void): void;
|
|
2217
3776
|
export namespace opendir {
|
|
2218
|
-
function __promisify__(path:
|
|
3777
|
+
function __promisify__(path: PathLike, options?: OpenDirOptions): Promise<Dir>;
|
|
2219
3778
|
}
|
|
2220
|
-
|
|
2221
3779
|
export interface BigIntStats extends StatsBase<bigint> {
|
|
2222
|
-
}
|
|
2223
|
-
|
|
2224
|
-
export class BigIntStats {
|
|
2225
3780
|
atimeNs: bigint;
|
|
2226
3781
|
mtimeNs: bigint;
|
|
2227
3782
|
ctimeNs: bigint;
|
|
2228
3783
|
birthtimeNs: bigint;
|
|
2229
3784
|
}
|
|
2230
|
-
|
|
2231
3785
|
export interface BigIntOptions {
|
|
2232
3786
|
bigint: true;
|
|
2233
3787
|
}
|
|
2234
|
-
|
|
2235
3788
|
export interface StatOptions {
|
|
2236
|
-
bigint?: boolean;
|
|
2237
|
-
throwIfNoEntry?: boolean;
|
|
3789
|
+
bigint?: boolean | undefined;
|
|
2238
3790
|
}
|
|
3791
|
+
export interface StatSyncOptions extends StatOptions {
|
|
3792
|
+
throwIfNoEntry?: boolean | undefined;
|
|
3793
|
+
}
|
|
3794
|
+
interface CopyOptionsBase {
|
|
3795
|
+
/**
|
|
3796
|
+
* Dereference symlinks
|
|
3797
|
+
* @default false
|
|
3798
|
+
*/
|
|
3799
|
+
dereference?: boolean;
|
|
3800
|
+
/**
|
|
3801
|
+
* When `force` is `false`, and the destination
|
|
3802
|
+
* exists, throw an error.
|
|
3803
|
+
* @default false
|
|
3804
|
+
*/
|
|
3805
|
+
errorOnExist?: boolean;
|
|
3806
|
+
/**
|
|
3807
|
+
* Overwrite existing file or directory. _The copy
|
|
3808
|
+
* operation will ignore errors if you set this to false and the destination
|
|
3809
|
+
* exists. Use the `errorOnExist` option to change this behavior.
|
|
3810
|
+
* @default true
|
|
3811
|
+
*/
|
|
3812
|
+
force?: boolean;
|
|
3813
|
+
/**
|
|
3814
|
+
* When `true` timestamps from `src` will
|
|
3815
|
+
* be preserved.
|
|
3816
|
+
* @default false
|
|
3817
|
+
*/
|
|
3818
|
+
preserveTimestamps?: boolean;
|
|
3819
|
+
/**
|
|
3820
|
+
* Copy directories recursively.
|
|
3821
|
+
* @default false
|
|
3822
|
+
*/
|
|
3823
|
+
recursive?: boolean;
|
|
3824
|
+
/**
|
|
3825
|
+
* When true, path resolution for symlinks will be skipped
|
|
3826
|
+
* @default false
|
|
3827
|
+
*/
|
|
3828
|
+
verbatimSymlinks?: boolean;
|
|
3829
|
+
}
|
|
3830
|
+
export interface CopyOptions extends CopyOptionsBase {
|
|
3831
|
+
/**
|
|
3832
|
+
* Function to filter copied files/directories. Return
|
|
3833
|
+
* `true` to copy the item, `false` to ignore it.
|
|
3834
|
+
*/
|
|
3835
|
+
filter?(source: string, destination: string): boolean | Promise<boolean>;
|
|
3836
|
+
}
|
|
3837
|
+
export interface CopySyncOptions extends CopyOptionsBase {
|
|
3838
|
+
/**
|
|
3839
|
+
* Function to filter copied files/directories. Return
|
|
3840
|
+
* `true` to copy the item, `false` to ignore it.
|
|
3841
|
+
*/
|
|
3842
|
+
filter?(source: string, destination: string): boolean;
|
|
3843
|
+
}
|
|
3844
|
+
/**
|
|
3845
|
+
* Asynchronously copies the entire directory structure from `src` to `dest`,
|
|
3846
|
+
* including subdirectories and files.
|
|
3847
|
+
*
|
|
3848
|
+
* When copying a directory to another directory, globs are not supported and
|
|
3849
|
+
* behavior is similar to `cp dir1/ dir2/`.
|
|
3850
|
+
* @since v16.7.0
|
|
3851
|
+
* @experimental
|
|
3852
|
+
* @param src source path to copy.
|
|
3853
|
+
* @param dest destination path to copy to.
|
|
3854
|
+
*/
|
|
3855
|
+
export function cp(source: string | URL, destination: string | URL, callback: (err: NodeJS.ErrnoException | null) => void): void;
|
|
3856
|
+
export function cp(source: string | URL, destination: string | URL, opts: CopyOptions, callback: (err: NodeJS.ErrnoException | null) => void): void;
|
|
3857
|
+
/**
|
|
3858
|
+
* Synchronously copies the entire directory structure from `src` to `dest`,
|
|
3859
|
+
* including subdirectories and files.
|
|
3860
|
+
*
|
|
3861
|
+
* When copying a directory to another directory, globs are not supported and
|
|
3862
|
+
* behavior is similar to `cp dir1/ dir2/`.
|
|
3863
|
+
* @since v16.7.0
|
|
3864
|
+
* @experimental
|
|
3865
|
+
* @param src source path to copy.
|
|
3866
|
+
* @param dest destination path to copy to.
|
|
3867
|
+
*/
|
|
3868
|
+
export function cpSync(source: string | URL, destination: string | URL, opts?: CopySyncOptions): void;
|
|
3869
|
+
}
|
|
3870
|
+
declare module 'node:fs' {
|
|
3871
|
+
export * from 'fs';
|
|
2239
3872
|
}
|