@types/node 18.11.5 → 20.2.5
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.
- node/README.md +2 -2
- node/assert.d.ts +86 -75
- node/async_hooks.d.ts +66 -37
- node/buffer.d.ts +193 -100
- node/child_process.d.ts +82 -56
- node/cluster.d.ts +12 -12
- node/console.d.ts +5 -5
- node/crypto.d.ts +233 -235
- node/dgram.d.ts +15 -15
- node/diagnostics_channel.d.ts +59 -21
- node/dns/promises.d.ts +50 -6
- node/dns.d.ts +26 -17
- node/domain.d.ts +4 -4
- node/events.d.ts +111 -65
- node/fs/promises.d.ts +99 -47
- node/fs.d.ts +244 -73
- node/globals.d.ts +6 -3
- node/http.d.ts +265 -148
- node/http2.d.ts +42 -47
- node/https.d.ts +53 -153
- node/index.d.ts +2 -1
- node/inspector.d.ts +10 -3
- node/module.d.ts +6 -4
- node/net.d.ts +32 -15
- node/os.d.ts +27 -16
- node/package.json +9 -4
- node/path.d.ts +4 -4
- node/perf_hooks.d.ts +28 -15
- node/process.d.ts +49 -46
- node/punycode.d.ts +1 -1
- node/querystring.d.ts +5 -5
- node/readline/promises.d.ts +65 -63
- node/readline.d.ts +32 -159
- node/repl.d.ts +20 -20
- node/stream/consumers.d.ts +1 -1
- node/stream.d.ts +950 -869
- node/string_decoder.d.ts +6 -6
- node/test.d.ts +877 -139
- node/timers/promises.d.ts +26 -1
- node/timers.d.ts +125 -4
- node/tls.d.ts +120 -29
- node/trace_events.d.ts +20 -9
- node/ts4.8/assert.d.ts +86 -75
- node/ts4.8/async_hooks.d.ts +66 -37
- node/ts4.8/buffer.d.ts +193 -101
- node/ts4.8/child_process.d.ts +82 -56
- node/ts4.8/cluster.d.ts +12 -12
- node/ts4.8/console.d.ts +5 -5
- node/ts4.8/crypto.d.ts +230 -233
- node/ts4.8/dgram.d.ts +15 -15
- node/ts4.8/diagnostics_channel.d.ts +59 -21
- node/ts4.8/dns/promises.d.ts +50 -6
- node/ts4.8/dns.d.ts +26 -17
- node/ts4.8/domain.d.ts +4 -4
- node/ts4.8/events.d.ts +111 -65
- node/ts4.8/fs/promises.d.ts +97 -46
- node/ts4.8/fs.d.ts +244 -73
- node/ts4.8/globals.d.ts +21 -12
- node/ts4.8/http.d.ts +265 -148
- node/ts4.8/http2.d.ts +42 -47
- node/ts4.8/https.d.ts +53 -153
- node/ts4.8/inspector.d.ts +10 -3
- node/ts4.8/module.d.ts +6 -4
- node/ts4.8/net.d.ts +33 -16
- node/ts4.8/os.d.ts +27 -16
- node/ts4.8/path.d.ts +4 -4
- node/ts4.8/perf_hooks.d.ts +28 -15
- node/ts4.8/process.d.ts +49 -46
- node/ts4.8/punycode.d.ts +1 -1
- node/ts4.8/querystring.d.ts +5 -5
- node/ts4.8/readline/promises.d.ts +65 -63
- node/ts4.8/readline.d.ts +32 -159
- node/ts4.8/repl.d.ts +20 -20
- node/ts4.8/stream/consumers.d.ts +1 -1
- node/ts4.8/stream.d.ts +192 -140
- node/ts4.8/string_decoder.d.ts +6 -6
- node/ts4.8/test.d.ts +877 -139
- node/ts4.8/timers/promises.d.ts +26 -1
- node/ts4.8/timers.d.ts +125 -4
- node/ts4.8/tls.d.ts +120 -29
- node/ts4.8/trace_events.d.ts +20 -9
- node/ts4.8/tty.d.ts +4 -5
- node/ts4.8/url.d.ts +46 -42
- node/ts4.8/util.d.ts +325 -123
- node/ts4.8/v8.d.ts +253 -14
- node/ts4.8/vm.d.ts +417 -32
- node/ts4.8/wasi.d.ts +13 -19
- node/ts4.8/worker_threads.d.ts +38 -34
- node/ts4.8/zlib.d.ts +11 -11
- node/tty.d.ts +4 -5
- node/url.d.ts +46 -42
- node/util.d.ts +325 -123
- node/v8.d.ts +253 -14
- node/vm.d.ts +417 -32
- node/wasi.d.ts +13 -19
- node/worker_threads.d.ts +38 -34
- node/zlib.d.ts +11 -11
node/ts4.8/fs.d.ts
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The `fs` module enables interacting with the file system in a
|
|
2
|
+
* The `node:fs` module enables interacting with the file system in a
|
|
3
3
|
* way modeled on standard POSIX functions.
|
|
4
4
|
*
|
|
5
5
|
* To use the promise-based APIs:
|
|
6
6
|
*
|
|
7
7
|
* ```js
|
|
8
|
-
* import * as fs from 'fs/promises';
|
|
8
|
+
* import * as fs from 'node:fs/promises';
|
|
9
9
|
* ```
|
|
10
10
|
*
|
|
11
11
|
* To use the callback and sync APIs:
|
|
12
12
|
*
|
|
13
13
|
* ```js
|
|
14
|
-
* import * as fs from 'fs';
|
|
14
|
+
* import * as fs from 'node:fs';
|
|
15
15
|
* ```
|
|
16
16
|
*
|
|
17
17
|
* All file system operations have synchronous, callback, and promise-based
|
|
18
18
|
* forms, and are accessible using both CommonJS syntax and ES6 Modules (ESM).
|
|
19
|
-
* @see [source](https://github.com/nodejs/node/blob/
|
|
19
|
+
* @see [source](https://github.com/nodejs/node/blob/v20.2.0/lib/fs.js)
|
|
20
20
|
*/
|
|
21
21
|
declare module 'fs' {
|
|
22
22
|
import * as stream from 'node:stream';
|
|
@@ -73,7 +73,7 @@ declare module 'fs' {
|
|
|
73
73
|
/**
|
|
74
74
|
* A `fs.Stats` object provides information about a file.
|
|
75
75
|
*
|
|
76
|
-
* Objects returned from {@link stat}, {@link lstat}
|
|
76
|
+
* Objects returned from {@link stat}, {@link lstat}, {@link fstat}, and
|
|
77
77
|
* their synchronous counterparts are of this type.
|
|
78
78
|
* If `bigint` in the `options` passed to those methods is true, the numeric values
|
|
79
79
|
* will be `bigint` instead of `number`, and the object will contain additional
|
|
@@ -131,6 +131,62 @@ declare module 'fs' {
|
|
|
131
131
|
* @since v0.1.21
|
|
132
132
|
*/
|
|
133
133
|
export class Stats {}
|
|
134
|
+
export interface StatsFsBase<T> {
|
|
135
|
+
/** Type of file system. */
|
|
136
|
+
type: T;
|
|
137
|
+
/** Optimal transfer block size. */
|
|
138
|
+
bsize: T;
|
|
139
|
+
/** Total data blocks in file system. */
|
|
140
|
+
blocks: T;
|
|
141
|
+
/** Free blocks in file system. */
|
|
142
|
+
bfree: T;
|
|
143
|
+
/** Available blocks for unprivileged users */
|
|
144
|
+
bavail: T;
|
|
145
|
+
/** Total file nodes in file system. */
|
|
146
|
+
files: T;
|
|
147
|
+
/** Free file nodes in file system. */
|
|
148
|
+
ffree: T;
|
|
149
|
+
}
|
|
150
|
+
export interface StatsFs extends StatsFsBase<number> {}
|
|
151
|
+
/**
|
|
152
|
+
* Provides information about a mounted file system.
|
|
153
|
+
*
|
|
154
|
+
* Objects returned from {@link statfs} and its synchronous counterpart are of
|
|
155
|
+
* this type. If `bigint` in the `options` passed to those methods is `true`, the
|
|
156
|
+
* numeric values will be `bigint` instead of `number`.
|
|
157
|
+
*
|
|
158
|
+
* ```console
|
|
159
|
+
* StatFs {
|
|
160
|
+
* type: 1397114950,
|
|
161
|
+
* bsize: 4096,
|
|
162
|
+
* blocks: 121938943,
|
|
163
|
+
* bfree: 61058895,
|
|
164
|
+
* bavail: 61058895,
|
|
165
|
+
* files: 999,
|
|
166
|
+
* ffree: 1000000
|
|
167
|
+
* }
|
|
168
|
+
* ```
|
|
169
|
+
*
|
|
170
|
+
* `bigint` version:
|
|
171
|
+
*
|
|
172
|
+
* ```console
|
|
173
|
+
* StatFs {
|
|
174
|
+
* type: 1397114950n,
|
|
175
|
+
* bsize: 4096n,
|
|
176
|
+
* blocks: 121938943n,
|
|
177
|
+
* bfree: 61058895n,
|
|
178
|
+
* bavail: 61058895n,
|
|
179
|
+
* files: 999n,
|
|
180
|
+
* ffree: 1000000n
|
|
181
|
+
* }
|
|
182
|
+
* ```
|
|
183
|
+
* @since v19.6.0, v18.15.0
|
|
184
|
+
*/
|
|
185
|
+
export class StatsFs {}
|
|
186
|
+
export interface BigIntStatsFs extends StatsFsBase<bigint> {}
|
|
187
|
+
export interface StatFsOptions {
|
|
188
|
+
bigint?: boolean | undefined;
|
|
189
|
+
}
|
|
134
190
|
/**
|
|
135
191
|
* A representation of a directory entry, which can be a file or a subdirectory
|
|
136
192
|
* within the directory, as returned by reading from an `fs.Dir`. The
|
|
@@ -184,6 +240,11 @@ declare module 'fs' {
|
|
|
184
240
|
* @since v10.10.0
|
|
185
241
|
*/
|
|
186
242
|
name: string;
|
|
243
|
+
/**
|
|
244
|
+
* The base path that this `fs.Dirent` object refers to.
|
|
245
|
+
* @since v20.1.0
|
|
246
|
+
*/
|
|
247
|
+
path: string;
|
|
187
248
|
}
|
|
188
249
|
/**
|
|
189
250
|
* A class representing a directory stream.
|
|
@@ -191,7 +252,7 @@ declare module 'fs' {
|
|
|
191
252
|
* Created by {@link opendir}, {@link opendirSync}, or `fsPromises.opendir()`.
|
|
192
253
|
*
|
|
193
254
|
* ```js
|
|
194
|
-
* import { opendir } from 'fs/promises';
|
|
255
|
+
* import { opendir } from 'node:fs/promises';
|
|
195
256
|
*
|
|
196
257
|
* try {
|
|
197
258
|
* const dir = await opendir('./');
|
|
@@ -494,7 +555,7 @@ declare module 'fs' {
|
|
|
494
555
|
* See also: [`rename(2)`](http://man7.org/linux/man-pages/man2/rename.2.html).
|
|
495
556
|
*
|
|
496
557
|
* ```js
|
|
497
|
-
* import { rename } from 'fs';
|
|
558
|
+
* import { rename } from 'node:fs';
|
|
498
559
|
*
|
|
499
560
|
* rename('oldFile.txt', 'newFile.txt', (err) => {
|
|
500
561
|
* if (err) throw err;
|
|
@@ -527,7 +588,7 @@ declare module 'fs' {
|
|
|
527
588
|
* first argument. In this case, `fs.ftruncate()` is called.
|
|
528
589
|
*
|
|
529
590
|
* ```js
|
|
530
|
-
* import { truncate } from 'fs';
|
|
591
|
+
* import { truncate } from 'node:fs';
|
|
531
592
|
* // Assuming that 'path/file.txt' is a regular file.
|
|
532
593
|
* truncate('path/file.txt', (err) => {
|
|
533
594
|
* if (err) throw err;
|
|
@@ -579,7 +640,7 @@ declare module 'fs' {
|
|
|
579
640
|
* file:
|
|
580
641
|
*
|
|
581
642
|
* ```js
|
|
582
|
-
* import { open, close, ftruncate } from 'fs';
|
|
643
|
+
* import { open, close, ftruncate } from 'node:fs';
|
|
583
644
|
*
|
|
584
645
|
* function closeFd(fd) {
|
|
585
646
|
* close(fd, (err) => {
|
|
@@ -736,7 +797,7 @@ declare module 'fs' {
|
|
|
736
797
|
* See the POSIX [`chmod(2)`](http://man7.org/linux/man-pages/man2/chmod.2.html) documentation for more detail.
|
|
737
798
|
*
|
|
738
799
|
* ```js
|
|
739
|
-
* import { chmod } from 'fs';
|
|
800
|
+
* import { chmod } from 'node:fs';
|
|
740
801
|
*
|
|
741
802
|
* chmod('my_file.txt', 0o775, (err) => {
|
|
742
803
|
* if (err) throw err;
|
|
@@ -818,7 +879,10 @@ declare module 'fs' {
|
|
|
818
879
|
*
|
|
819
880
|
* In case of an error, the `err.code` will be one of `Common System Errors`.
|
|
820
881
|
*
|
|
821
|
-
*
|
|
882
|
+
* {@link stat} follows symbolic links. Use {@link lstat} to look at the
|
|
883
|
+
* links themselves.
|
|
884
|
+
*
|
|
885
|
+
* Using `fs.stat()` to check for the existence of a file before calling`fs.open()`, `fs.readFile()`, or `fs.writeFile()` is not recommended.
|
|
822
886
|
* Instead, user code should open/read/write the file directly and handle the
|
|
823
887
|
* error raised if the file is not available.
|
|
824
888
|
*
|
|
@@ -835,7 +899,7 @@ declare module 'fs' {
|
|
|
835
899
|
* The next program will check for the stats of the given paths:
|
|
836
900
|
*
|
|
837
901
|
* ```js
|
|
838
|
-
* import { stat } from 'fs';
|
|
902
|
+
* import { stat } from 'node:fs';
|
|
839
903
|
*
|
|
840
904
|
* const pathsToCheck = ['./txtDir', './txtDir/file.txt'];
|
|
841
905
|
*
|
|
@@ -1081,6 +1145,72 @@ declare module 'fs' {
|
|
|
1081
1145
|
): Promise<BigIntStats>;
|
|
1082
1146
|
function __promisify__(path: PathLike, options?: StatOptions): Promise<Stats | BigIntStats>;
|
|
1083
1147
|
}
|
|
1148
|
+
/**
|
|
1149
|
+
* Asynchronous [`statfs(2)`](http://man7.org/linux/man-pages/man2/statfs.2.html). Returns information about the mounted file system which
|
|
1150
|
+
* contains `path`. The callback gets two arguments `(err, stats)` where `stats`is an `fs.StatFs` object.
|
|
1151
|
+
*
|
|
1152
|
+
* In case of an error, the `err.code` will be one of `Common System Errors`.
|
|
1153
|
+
* @since v19.6.0, v18.15.0
|
|
1154
|
+
* @param path A path to an existing file or directory on the file system to be queried.
|
|
1155
|
+
*/
|
|
1156
|
+
export function statfs(path: PathLike, callback: (err: NodeJS.ErrnoException | null, stats: StatsFs) => void): void;
|
|
1157
|
+
export function statfs(
|
|
1158
|
+
path: PathLike,
|
|
1159
|
+
options:
|
|
1160
|
+
| (StatFsOptions & {
|
|
1161
|
+
bigint?: false | undefined;
|
|
1162
|
+
})
|
|
1163
|
+
| undefined,
|
|
1164
|
+
callback: (err: NodeJS.ErrnoException | null, stats: StatsFs) => void
|
|
1165
|
+
): void;
|
|
1166
|
+
export function statfs(
|
|
1167
|
+
path: PathLike,
|
|
1168
|
+
options: StatFsOptions & {
|
|
1169
|
+
bigint: true;
|
|
1170
|
+
},
|
|
1171
|
+
callback: (err: NodeJS.ErrnoException | null, stats: BigIntStatsFs) => void
|
|
1172
|
+
): void;
|
|
1173
|
+
export function statfs(path: PathLike, options: StatFsOptions | undefined, callback: (err: NodeJS.ErrnoException | null, stats: StatsFs | BigIntStatsFs) => void): void;
|
|
1174
|
+
export namespace statfs {
|
|
1175
|
+
/**
|
|
1176
|
+
* Asynchronous statfs(2) - Returns information about the mounted file system which contains path. The callback gets two arguments (err, stats) where stats is an <fs.StatFs> object.
|
|
1177
|
+
* @param path A path to an existing file or directory on the file system to be queried.
|
|
1178
|
+
*/
|
|
1179
|
+
function __promisify__(
|
|
1180
|
+
path: PathLike,
|
|
1181
|
+
options?: StatFsOptions & {
|
|
1182
|
+
bigint?: false | undefined;
|
|
1183
|
+
}
|
|
1184
|
+
): Promise<StatsFs>;
|
|
1185
|
+
function __promisify__(
|
|
1186
|
+
path: PathLike,
|
|
1187
|
+
options: StatFsOptions & {
|
|
1188
|
+
bigint: true;
|
|
1189
|
+
}
|
|
1190
|
+
): Promise<BigIntStatsFs>;
|
|
1191
|
+
function __promisify__(path: PathLike, options?: StatFsOptions): Promise<StatsFs | BigIntStatsFs>;
|
|
1192
|
+
}
|
|
1193
|
+
/**
|
|
1194
|
+
* Synchronous [`statfs(2)`](http://man7.org/linux/man-pages/man2/statfs.2.html). Returns information about the mounted file system which
|
|
1195
|
+
* contains `path`.
|
|
1196
|
+
*
|
|
1197
|
+
* In case of an error, the `err.code` will be one of `Common System Errors`.
|
|
1198
|
+
* @since v19.6.0, v18.15.0
|
|
1199
|
+
* @param path A path to an existing file or directory on the file system to be queried.
|
|
1200
|
+
*/
|
|
1201
|
+
export function statfsSync(
|
|
1202
|
+
path: PathLike,
|
|
1203
|
+
options?: StatFsOptions & {
|
|
1204
|
+
bigint?: false | undefined;
|
|
1205
|
+
}
|
|
1206
|
+
): StatsFs;
|
|
1207
|
+
export function statfsSync(
|
|
1208
|
+
path: PathLike,
|
|
1209
|
+
options: StatFsOptions & {
|
|
1210
|
+
bigint: true;
|
|
1211
|
+
}
|
|
1212
|
+
): BigIntStatsFs;
|
|
1213
|
+
export function statfsSync(path: PathLike, options?: StatFsOptions): StatsFs | BigIntStatsFs;
|
|
1084
1214
|
/**
|
|
1085
1215
|
* Synchronous lstat(2) - Get file status. Does not dereference symbolic links.
|
|
1086
1216
|
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
@@ -1114,14 +1244,15 @@ declare module 'fs' {
|
|
|
1114
1244
|
*
|
|
1115
1245
|
* The `type` argument is only available on Windows and ignored on other platforms.
|
|
1116
1246
|
* It can be set to `'dir'`, `'file'`, or `'junction'`. If the `type` argument is
|
|
1117
|
-
* not
|
|
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.
|
|
1247
|
+
* not a string, Node.js will autodetect `target` type and use `'file'` or `'dir'`.
|
|
1248
|
+
* If the `target` does not exist, `'file'` will be used. Windows junction points
|
|
1249
|
+
* require the destination path to be absolute. When using `'junction'`, the`target` argument will automatically be normalized to absolute path. Junction
|
|
1250
|
+
* points on NTFS volumes can only point to directories.
|
|
1120
1251
|
*
|
|
1121
|
-
* Relative targets are relative to the link
|
|
1252
|
+
* Relative targets are relative to the link's parent directory.
|
|
1122
1253
|
*
|
|
1123
1254
|
* ```js
|
|
1124
|
-
* import { symlink } from 'fs';
|
|
1255
|
+
* import { symlink } from 'node:fs';
|
|
1125
1256
|
*
|
|
1126
1257
|
* symlink('./mew', './mewtwo', callback);
|
|
1127
1258
|
* ```
|
|
@@ -1136,6 +1267,7 @@ declare module 'fs' {
|
|
|
1136
1267
|
* └── mewtwo -> ./mew
|
|
1137
1268
|
* ```
|
|
1138
1269
|
* @since v0.1.31
|
|
1270
|
+
* @param [type='null']
|
|
1139
1271
|
*/
|
|
1140
1272
|
export function symlink(target: PathLike, path: PathLike, type: symlink.Type | undefined | null, callback: NoParamCallback): void;
|
|
1141
1273
|
/**
|
|
@@ -1161,6 +1293,7 @@ declare module 'fs' {
|
|
|
1161
1293
|
* For detailed information, see the documentation of the asynchronous version of
|
|
1162
1294
|
* this API: {@link symlink}.
|
|
1163
1295
|
* @since v0.1.31
|
|
1296
|
+
* @param [type='null']
|
|
1164
1297
|
*/
|
|
1165
1298
|
export function symlinkSync(target: PathLike, path: PathLike, type?: symlink.Type | null): void;
|
|
1166
1299
|
/**
|
|
@@ -1238,7 +1371,7 @@ declare module 'fs' {
|
|
|
1238
1371
|
*/
|
|
1239
1372
|
export function readlinkSync(path: PathLike, options?: EncodingOption): string | Buffer;
|
|
1240
1373
|
/**
|
|
1241
|
-
* Asynchronously computes the canonical pathname by resolving `.`,
|
|
1374
|
+
* Asynchronously computes the canonical pathname by resolving `.`, `..`, and
|
|
1242
1375
|
* symbolic links.
|
|
1243
1376
|
*
|
|
1244
1377
|
* A canonical pathname is not necessarily unique. Hard links and bind mounts can
|
|
@@ -1352,7 +1485,7 @@ declare module 'fs' {
|
|
|
1352
1485
|
* possible exception are given to the completion callback.
|
|
1353
1486
|
*
|
|
1354
1487
|
* ```js
|
|
1355
|
-
* import { unlink } from 'fs';
|
|
1488
|
+
* import { unlink } from 'node:fs';
|
|
1356
1489
|
* // Assuming that 'path/file.txt' is a regular file.
|
|
1357
1490
|
* unlink('path/file.txt', (err) => {
|
|
1358
1491
|
* if (err) throw err;
|
|
@@ -1507,7 +1640,7 @@ declare module 'fs' {
|
|
|
1507
1640
|
* when `recursive` is false.
|
|
1508
1641
|
*
|
|
1509
1642
|
* ```js
|
|
1510
|
-
* import { mkdir } from 'fs';
|
|
1643
|
+
* import { mkdir } from 'node:fs';
|
|
1511
1644
|
*
|
|
1512
1645
|
* // Creates /tmp/a/apple, regardless of whether `/tmp` and /tmp/a exist.
|
|
1513
1646
|
* mkdir('/tmp/a/apple', { recursive: true }, (err) => {
|
|
@@ -1519,7 +1652,7 @@ declare module 'fs' {
|
|
|
1519
1652
|
* result in an error:
|
|
1520
1653
|
*
|
|
1521
1654
|
* ```js
|
|
1522
|
-
* import { mkdir } from 'fs';
|
|
1655
|
+
* import { mkdir } from 'node:fs';
|
|
1523
1656
|
*
|
|
1524
1657
|
* mkdir('/', { recursive: true }, (err) => {
|
|
1525
1658
|
* // => [Error: EPERM: operation not permitted, mkdir 'C:\']
|
|
@@ -1651,9 +1784,11 @@ declare module 'fs' {
|
|
|
1651
1784
|
* object with an `encoding` property specifying the character encoding to use.
|
|
1652
1785
|
*
|
|
1653
1786
|
* ```js
|
|
1654
|
-
* import { mkdtemp } from 'fs';
|
|
1787
|
+
* import { mkdtemp } from 'node:fs';
|
|
1788
|
+
* import { join } from 'node:path';
|
|
1789
|
+
* import { tmpdir } from 'node:os';
|
|
1655
1790
|
*
|
|
1656
|
-
* mkdtemp(
|
|
1791
|
+
* mkdtemp(join(tmpdir(), 'foo-'), (err, directory) => {
|
|
1657
1792
|
* if (err) throw err;
|
|
1658
1793
|
* console.log(directory);
|
|
1659
1794
|
* // Prints: /tmp/foo-itXde2 or C:\Users\...\AppData\Local\Temp\foo-itXde2
|
|
@@ -1663,11 +1798,11 @@ declare module 'fs' {
|
|
|
1663
1798
|
* The `fs.mkdtemp()` method will append the six randomly selected characters
|
|
1664
1799
|
* directly to the `prefix` string. For instance, given a directory `/tmp`, if the
|
|
1665
1800
|
* intention is to create a temporary directory _within_`/tmp`, the `prefix`must end with a trailing platform-specific path separator
|
|
1666
|
-
* (`require('path').sep`).
|
|
1801
|
+
* (`require('node:path').sep`).
|
|
1667
1802
|
*
|
|
1668
1803
|
* ```js
|
|
1669
|
-
* import { tmpdir } from 'os';
|
|
1670
|
-
* import { mkdtemp } from 'fs';
|
|
1804
|
+
* import { tmpdir } from 'node:os';
|
|
1805
|
+
* import { mkdtemp } from 'node:fs';
|
|
1671
1806
|
*
|
|
1672
1807
|
* // The parent directory for the new temporary directory
|
|
1673
1808
|
* const tmpDir = tmpdir();
|
|
@@ -1682,7 +1817,7 @@ declare module 'fs' {
|
|
|
1682
1817
|
* });
|
|
1683
1818
|
*
|
|
1684
1819
|
* // This method is *CORRECT*:
|
|
1685
|
-
* import { sep } from 'path';
|
|
1820
|
+
* import { sep } from 'node:path';
|
|
1686
1821
|
* mkdtemp(`${tmpDir}${sep}`, (err, directory) => {
|
|
1687
1822
|
* if (err) throw err;
|
|
1688
1823
|
* console.log(directory);
|
|
@@ -1781,6 +1916,7 @@ declare module 'fs' {
|
|
|
1781
1916
|
| {
|
|
1782
1917
|
encoding: BufferEncoding | null;
|
|
1783
1918
|
withFileTypes?: false | undefined;
|
|
1919
|
+
recursive?: boolean | undefined;
|
|
1784
1920
|
}
|
|
1785
1921
|
| BufferEncoding
|
|
1786
1922
|
| undefined
|
|
@@ -1798,6 +1934,7 @@ declare module 'fs' {
|
|
|
1798
1934
|
| {
|
|
1799
1935
|
encoding: 'buffer';
|
|
1800
1936
|
withFileTypes?: false | undefined;
|
|
1937
|
+
recursive?: boolean | undefined;
|
|
1801
1938
|
}
|
|
1802
1939
|
| 'buffer',
|
|
1803
1940
|
callback: (err: NodeJS.ErrnoException | null, files: Buffer[]) => void
|
|
@@ -1812,6 +1949,7 @@ declare module 'fs' {
|
|
|
1812
1949
|
options:
|
|
1813
1950
|
| (ObjectEncodingOptions & {
|
|
1814
1951
|
withFileTypes?: false | undefined;
|
|
1952
|
+
recursive?: boolean | undefined;
|
|
1815
1953
|
})
|
|
1816
1954
|
| BufferEncoding
|
|
1817
1955
|
| undefined
|
|
@@ -1832,6 +1970,7 @@ declare module 'fs' {
|
|
|
1832
1970
|
path: PathLike,
|
|
1833
1971
|
options: ObjectEncodingOptions & {
|
|
1834
1972
|
withFileTypes: true;
|
|
1973
|
+
recursive?: boolean | undefined;
|
|
1835
1974
|
},
|
|
1836
1975
|
callback: (err: NodeJS.ErrnoException | null, files: Dirent[]) => void
|
|
1837
1976
|
): void;
|
|
@@ -1847,6 +1986,7 @@ declare module 'fs' {
|
|
|
1847
1986
|
| {
|
|
1848
1987
|
encoding: BufferEncoding | null;
|
|
1849
1988
|
withFileTypes?: false | undefined;
|
|
1989
|
+
recursive?: boolean | undefined;
|
|
1850
1990
|
}
|
|
1851
1991
|
| BufferEncoding
|
|
1852
1992
|
| null
|
|
@@ -1863,6 +2003,7 @@ declare module 'fs' {
|
|
|
1863
2003
|
| {
|
|
1864
2004
|
encoding: 'buffer';
|
|
1865
2005
|
withFileTypes?: false | undefined;
|
|
2006
|
+
recursive?: boolean | undefined;
|
|
1866
2007
|
}
|
|
1867
2008
|
): Promise<Buffer[]>;
|
|
1868
2009
|
/**
|
|
@@ -1875,6 +2016,7 @@ declare module 'fs' {
|
|
|
1875
2016
|
options?:
|
|
1876
2017
|
| (ObjectEncodingOptions & {
|
|
1877
2018
|
withFileTypes?: false | undefined;
|
|
2019
|
+
recursive?: boolean | undefined;
|
|
1878
2020
|
})
|
|
1879
2021
|
| BufferEncoding
|
|
1880
2022
|
| null
|
|
@@ -1888,6 +2030,7 @@ declare module 'fs' {
|
|
|
1888
2030
|
path: PathLike,
|
|
1889
2031
|
options: ObjectEncodingOptions & {
|
|
1890
2032
|
withFileTypes: true;
|
|
2033
|
+
recursive?: boolean | undefined;
|
|
1891
2034
|
}
|
|
1892
2035
|
): Promise<Dirent[]>;
|
|
1893
2036
|
}
|
|
@@ -1910,6 +2053,7 @@ declare module 'fs' {
|
|
|
1910
2053
|
| {
|
|
1911
2054
|
encoding: BufferEncoding | null;
|
|
1912
2055
|
withFileTypes?: false | undefined;
|
|
2056
|
+
recursive?: boolean | undefined;
|
|
1913
2057
|
}
|
|
1914
2058
|
| BufferEncoding
|
|
1915
2059
|
| null
|
|
@@ -1925,6 +2069,7 @@ declare module 'fs' {
|
|
|
1925
2069
|
| {
|
|
1926
2070
|
encoding: 'buffer';
|
|
1927
2071
|
withFileTypes?: false | undefined;
|
|
2072
|
+
recursive?: boolean | undefined;
|
|
1928
2073
|
}
|
|
1929
2074
|
| 'buffer'
|
|
1930
2075
|
): Buffer[];
|
|
@@ -1938,6 +2083,7 @@ declare module 'fs' {
|
|
|
1938
2083
|
options?:
|
|
1939
2084
|
| (ObjectEncodingOptions & {
|
|
1940
2085
|
withFileTypes?: false | undefined;
|
|
2086
|
+
recursive?: boolean | undefined;
|
|
1941
2087
|
})
|
|
1942
2088
|
| BufferEncoding
|
|
1943
2089
|
| null
|
|
@@ -1951,6 +2097,7 @@ declare module 'fs' {
|
|
|
1951
2097
|
path: PathLike,
|
|
1952
2098
|
options: ObjectEncodingOptions & {
|
|
1953
2099
|
withFileTypes: true;
|
|
2100
|
+
recursive?: boolean | undefined;
|
|
1954
2101
|
}
|
|
1955
2102
|
): Dirent[];
|
|
1956
2103
|
/**
|
|
@@ -2010,7 +2157,6 @@ declare module 'fs' {
|
|
|
2010
2157
|
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
2011
2158
|
*/
|
|
2012
2159
|
export function open(path: PathLike, callback: (err: NodeJS.ErrnoException | null, fd: number) => void): void;
|
|
2013
|
-
|
|
2014
2160
|
export namespace open {
|
|
2015
2161
|
/**
|
|
2016
2162
|
* Asynchronous open(2) - open and possibly create a file.
|
|
@@ -2035,7 +2181,7 @@ declare module 'fs' {
|
|
|
2035
2181
|
* The `atime` and `mtime` arguments follow these rules:
|
|
2036
2182
|
*
|
|
2037
2183
|
* * 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
|
|
2184
|
+
* * If the value can not be converted to a number, or is `NaN`, `Infinity`, or`-Infinity`, an `Error` will be thrown.
|
|
2039
2185
|
* @since v0.4.2
|
|
2040
2186
|
*/
|
|
2041
2187
|
export function utimes(path: PathLike, atime: TimeLike, mtime: TimeLike, callback: NoParamCallback): void;
|
|
@@ -2121,6 +2267,9 @@ declare module 'fs' {
|
|
|
2121
2267
|
* The kernel ignores the position argument and always appends the data to
|
|
2122
2268
|
* the end of the file.
|
|
2123
2269
|
* @since v0.0.2
|
|
2270
|
+
* @param [offset=0]
|
|
2271
|
+
* @param [length=buffer.byteLength - offset]
|
|
2272
|
+
* @param [position='null']
|
|
2124
2273
|
*/
|
|
2125
2274
|
export function write<TBuffer extends NodeJS.ArrayBufferView>(
|
|
2126
2275
|
fd: number,
|
|
@@ -2225,6 +2374,9 @@ declare module 'fs' {
|
|
|
2225
2374
|
* For detailed information, see the documentation of the asynchronous version of
|
|
2226
2375
|
* this API: {@link write}.
|
|
2227
2376
|
* @since v0.1.21
|
|
2377
|
+
* @param [offset=0]
|
|
2378
|
+
* @param [length=buffer.byteLength - offset]
|
|
2379
|
+
* @param [position='null']
|
|
2228
2380
|
* @return The number of bytes written.
|
|
2229
2381
|
*/
|
|
2230
2382
|
export function writeSync(fd: number, buffer: NodeJS.ArrayBufferView, offset?: number | null, length?: number | null, position?: number | null): number;
|
|
@@ -2330,6 +2482,7 @@ declare module 'fs' {
|
|
|
2330
2482
|
* For detailed information, see the documentation of the asynchronous version of
|
|
2331
2483
|
* this API: {@link read}.
|
|
2332
2484
|
* @since v0.1.21
|
|
2485
|
+
* @param [position='null']
|
|
2333
2486
|
*/
|
|
2334
2487
|
export function readSync(fd: number, buffer: NodeJS.ArrayBufferView, offset: number, length: number, position: ReadPosition | null): number;
|
|
2335
2488
|
/**
|
|
@@ -2341,7 +2494,7 @@ declare module 'fs' {
|
|
|
2341
2494
|
* Asynchronously reads the entire contents of a file.
|
|
2342
2495
|
*
|
|
2343
2496
|
* ```js
|
|
2344
|
-
* import { readFile } from 'fs';
|
|
2497
|
+
* import { readFile } from 'node:fs';
|
|
2345
2498
|
*
|
|
2346
2499
|
* readFile('/etc/passwd', (err, data) => {
|
|
2347
2500
|
* if (err) throw err;
|
|
@@ -2357,7 +2510,7 @@ declare module 'fs' {
|
|
|
2357
2510
|
* If `options` is a string, then it specifies the encoding:
|
|
2358
2511
|
*
|
|
2359
2512
|
* ```js
|
|
2360
|
-
* import { readFile } from 'fs';
|
|
2513
|
+
* import { readFile } from 'node:fs';
|
|
2361
2514
|
*
|
|
2362
2515
|
* readFile('/etc/passwd', 'utf8', callback);
|
|
2363
2516
|
* ```
|
|
@@ -2367,7 +2520,7 @@ declare module 'fs' {
|
|
|
2367
2520
|
* will be returned.
|
|
2368
2521
|
*
|
|
2369
2522
|
* ```js
|
|
2370
|
-
* import { readFile } from 'fs';
|
|
2523
|
+
* import { readFile } from 'node:fs';
|
|
2371
2524
|
*
|
|
2372
2525
|
* // macOS, Linux, and Windows
|
|
2373
2526
|
* readFile('<directory>', (err, data) => {
|
|
@@ -2384,7 +2537,7 @@ declare module 'fs' {
|
|
|
2384
2537
|
* request is aborted the callback is called with an `AbortError`:
|
|
2385
2538
|
*
|
|
2386
2539
|
* ```js
|
|
2387
|
-
* import { readFile } from 'fs';
|
|
2540
|
+
* import { readFile } from 'node:fs';
|
|
2388
2541
|
*
|
|
2389
2542
|
* const controller = new AbortController();
|
|
2390
2543
|
* const signal = controller.signal;
|
|
@@ -2517,7 +2670,7 @@ declare module 'fs' {
|
|
|
2517
2670
|
* Similar to {@link readFile}, when the path is a directory, the behavior of`fs.readFileSync()` is platform-specific.
|
|
2518
2671
|
*
|
|
2519
2672
|
* ```js
|
|
2520
|
-
* import { readFileSync } from 'fs';
|
|
2673
|
+
* import { readFileSync } from 'node:fs';
|
|
2521
2674
|
*
|
|
2522
2675
|
* // macOS, Linux, and Windows
|
|
2523
2676
|
* readFileSync('<directory>');
|
|
@@ -2588,8 +2741,8 @@ declare module 'fs' {
|
|
|
2588
2741
|
* The `mode` option only affects the newly created file. See {@link open} for more details.
|
|
2589
2742
|
*
|
|
2590
2743
|
* ```js
|
|
2591
|
-
* import { writeFile } from 'fs';
|
|
2592
|
-
* import { Buffer } from 'buffer';
|
|
2744
|
+
* import { writeFile } from 'node:fs';
|
|
2745
|
+
* import { Buffer } from 'node:buffer';
|
|
2593
2746
|
*
|
|
2594
2747
|
* const data = new Uint8Array(Buffer.from('Hello Node.js'));
|
|
2595
2748
|
* writeFile('message.txt', data, (err) => {
|
|
@@ -2601,7 +2754,7 @@ declare module 'fs' {
|
|
|
2601
2754
|
* If `options` is a string, then it specifies the encoding:
|
|
2602
2755
|
*
|
|
2603
2756
|
* ```js
|
|
2604
|
-
* import { writeFile } from 'fs';
|
|
2757
|
+
* import { writeFile } from 'node:fs';
|
|
2605
2758
|
*
|
|
2606
2759
|
* writeFile('message.txt', 'Hello Node.js', 'utf8', callback);
|
|
2607
2760
|
* ```
|
|
@@ -2619,8 +2772,8 @@ declare module 'fs' {
|
|
|
2619
2772
|
* to be written.
|
|
2620
2773
|
*
|
|
2621
2774
|
* ```js
|
|
2622
|
-
* import { writeFile } from 'fs';
|
|
2623
|
-
* import { Buffer } from 'buffer';
|
|
2775
|
+
* import { writeFile } from 'node:fs';
|
|
2776
|
+
* import { Buffer } from 'node:buffer';
|
|
2624
2777
|
*
|
|
2625
2778
|
* const controller = new AbortController();
|
|
2626
2779
|
* const { signal } = controller;
|
|
@@ -2678,7 +2831,7 @@ declare module 'fs' {
|
|
|
2678
2831
|
* The `mode` option only affects the newly created file. See {@link open} for more details.
|
|
2679
2832
|
*
|
|
2680
2833
|
* ```js
|
|
2681
|
-
* import { appendFile } from 'fs';
|
|
2834
|
+
* import { appendFile } from 'node:fs';
|
|
2682
2835
|
*
|
|
2683
2836
|
* appendFile('message.txt', 'data to append', (err) => {
|
|
2684
2837
|
* if (err) throw err;
|
|
@@ -2689,7 +2842,7 @@ declare module 'fs' {
|
|
|
2689
2842
|
* If `options` is a string, then it specifies the encoding:
|
|
2690
2843
|
*
|
|
2691
2844
|
* ```js
|
|
2692
|
-
* import { appendFile } from 'fs';
|
|
2845
|
+
* import { appendFile } from 'node:fs';
|
|
2693
2846
|
*
|
|
2694
2847
|
* appendFile('message.txt', 'data to append', 'utf8', callback);
|
|
2695
2848
|
* ```
|
|
@@ -2699,7 +2852,7 @@ declare module 'fs' {
|
|
|
2699
2852
|
* not be closed automatically.
|
|
2700
2853
|
*
|
|
2701
2854
|
* ```js
|
|
2702
|
-
* import { open, close, appendFile } from 'fs';
|
|
2855
|
+
* import { open, close, appendFile } from 'node:fs';
|
|
2703
2856
|
*
|
|
2704
2857
|
* function closeFd(fd) {
|
|
2705
2858
|
* close(fd, (err) => {
|
|
@@ -2754,7 +2907,7 @@ declare module 'fs' {
|
|
|
2754
2907
|
* The `mode` option only affects the newly created file. See {@link open} for more details.
|
|
2755
2908
|
*
|
|
2756
2909
|
* ```js
|
|
2757
|
-
* import { appendFileSync } from 'fs';
|
|
2910
|
+
* import { appendFileSync } from 'node:fs';
|
|
2758
2911
|
*
|
|
2759
2912
|
* try {
|
|
2760
2913
|
* appendFileSync('message.txt', 'data to append');
|
|
@@ -2767,7 +2920,7 @@ declare module 'fs' {
|
|
|
2767
2920
|
* If `options` is a string, then it specifies the encoding:
|
|
2768
2921
|
*
|
|
2769
2922
|
* ```js
|
|
2770
|
-
* import { appendFileSync } from 'fs';
|
|
2923
|
+
* import { appendFileSync } from 'node:fs';
|
|
2771
2924
|
*
|
|
2772
2925
|
* appendFileSync('message.txt', 'data to append', 'utf8');
|
|
2773
2926
|
* ```
|
|
@@ -2777,7 +2930,7 @@ declare module 'fs' {
|
|
|
2777
2930
|
* not be closed automatically.
|
|
2778
2931
|
*
|
|
2779
2932
|
* ```js
|
|
2780
|
-
* import { openSync, closeSync, appendFileSync } from 'fs';
|
|
2933
|
+
* import { openSync, closeSync, appendFileSync } from 'node:fs';
|
|
2781
2934
|
*
|
|
2782
2935
|
* let fd;
|
|
2783
2936
|
*
|
|
@@ -2859,7 +3012,7 @@ declare module 'fs' {
|
|
|
2859
3012
|
* stat object:
|
|
2860
3013
|
*
|
|
2861
3014
|
* ```js
|
|
2862
|
-
* import { watchFile } from 'fs';
|
|
3015
|
+
* import { watchFile } from 'node:fs';
|
|
2863
3016
|
*
|
|
2864
3017
|
* watchFile('message.text', (curr, prev) => {
|
|
2865
3018
|
* console.log(`the current mtime is: ${curr.mtime}`);
|
|
@@ -2899,7 +3052,7 @@ declare module 'fs' {
|
|
|
2899
3052
|
bigint?: false | undefined;
|
|
2900
3053
|
})
|
|
2901
3054
|
| undefined,
|
|
2902
|
-
listener:
|
|
3055
|
+
listener: StatsListener
|
|
2903
3056
|
): StatWatcher;
|
|
2904
3057
|
export function watchFile(
|
|
2905
3058
|
filename: PathLike,
|
|
@@ -2908,13 +3061,13 @@ declare module 'fs' {
|
|
|
2908
3061
|
bigint: true;
|
|
2909
3062
|
})
|
|
2910
3063
|
| undefined,
|
|
2911
|
-
listener:
|
|
3064
|
+
listener: BigIntStatsListener
|
|
2912
3065
|
): StatWatcher;
|
|
2913
3066
|
/**
|
|
2914
3067
|
* Watch for changes on `filename`. The callback `listener` will be called each time the file is accessed.
|
|
2915
3068
|
* @param filename A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
|
|
2916
3069
|
*/
|
|
2917
|
-
export function watchFile(filename: PathLike, listener:
|
|
3070
|
+
export function watchFile(filename: PathLike, listener: StatsListener): StatWatcher;
|
|
2918
3071
|
/**
|
|
2919
3072
|
* Stop watching for changes on `filename`. If `listener` is specified, only that
|
|
2920
3073
|
* particular listener is removed. Otherwise, _all_ listeners are removed,
|
|
@@ -2927,14 +3080,17 @@ declare module 'fs' {
|
|
|
2927
3080
|
* @since v0.1.31
|
|
2928
3081
|
* @param listener Optional, a listener previously attached using `fs.watchFile()`
|
|
2929
3082
|
*/
|
|
2930
|
-
export function unwatchFile(filename: PathLike, listener?:
|
|
3083
|
+
export function unwatchFile(filename: PathLike, listener?: StatsListener): void;
|
|
3084
|
+
export function unwatchFile(filename: PathLike, listener?: BigIntStatsListener): void;
|
|
2931
3085
|
export interface WatchOptions extends Abortable {
|
|
2932
3086
|
encoding?: BufferEncoding | 'buffer' | undefined;
|
|
2933
3087
|
persistent?: boolean | undefined;
|
|
2934
3088
|
recursive?: boolean | undefined;
|
|
2935
3089
|
}
|
|
2936
3090
|
export type WatchEventType = 'rename' | 'change';
|
|
2937
|
-
export type WatchListener<T> = (event: WatchEventType, filename: T) => void;
|
|
3091
|
+
export type WatchListener<T> = (event: WatchEventType, filename: T | null) => void;
|
|
3092
|
+
export type StatsListener = (curr: Stats, prev: Stats) => void;
|
|
3093
|
+
export type BigIntStatsListener = (curr: BigIntStats, prev: BigIntStats) => void;
|
|
2938
3094
|
/**
|
|
2939
3095
|
* Watch for changes on `filename`, where `filename` is either a file or a
|
|
2940
3096
|
* directory.
|
|
@@ -2992,7 +3148,7 @@ declare module 'fs' {
|
|
|
2992
3148
|
* Then call the `callback` argument with either true or false:
|
|
2993
3149
|
*
|
|
2994
3150
|
* ```js
|
|
2995
|
-
* import { exists } from 'fs';
|
|
3151
|
+
* import { exists } from 'node:fs';
|
|
2996
3152
|
*
|
|
2997
3153
|
* exists('/etc/passwd', (e) => {
|
|
2998
3154
|
* console.log(e ? 'it exists' : 'no passwd!');
|
|
@@ -3004,7 +3160,7 @@ declare module 'fs' {
|
|
|
3004
3160
|
* has only one boolean parameter. This is one reason `fs.access()` is recommended
|
|
3005
3161
|
* instead of `fs.exists()`.
|
|
3006
3162
|
*
|
|
3007
|
-
* Using `fs.exists()` to check for the existence of a file before calling`fs.open()`, `fs.readFile()
|
|
3163
|
+
* 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
3164
|
* so introduces a race condition, since other processes may change the file's
|
|
3009
3165
|
* state between the two calls. Instead, user code should open/read/write the
|
|
3010
3166
|
* file directly and handle the error raised if the file does not exist.
|
|
@@ -3012,7 +3168,7 @@ declare module 'fs' {
|
|
|
3012
3168
|
* **write (NOT RECOMMENDED)**
|
|
3013
3169
|
*
|
|
3014
3170
|
* ```js
|
|
3015
|
-
* import { exists, open, close } from 'fs';
|
|
3171
|
+
* import { exists, open, close } from 'node:fs';
|
|
3016
3172
|
*
|
|
3017
3173
|
* exists('myfile', (e) => {
|
|
3018
3174
|
* if (e) {
|
|
@@ -3036,7 +3192,7 @@ declare module 'fs' {
|
|
|
3036
3192
|
* **write (RECOMMENDED)**
|
|
3037
3193
|
*
|
|
3038
3194
|
* ```js
|
|
3039
|
-
* import { open, close } from 'fs';
|
|
3195
|
+
* import { open, close } from 'node:fs';
|
|
3040
3196
|
* open('myfile', 'wx', (err, fd) => {
|
|
3041
3197
|
* if (err) {
|
|
3042
3198
|
* if (err.code === 'EEXIST') {
|
|
@@ -3060,7 +3216,7 @@ declare module 'fs' {
|
|
|
3060
3216
|
* **read (NOT RECOMMENDED)**
|
|
3061
3217
|
*
|
|
3062
3218
|
* ```js
|
|
3063
|
-
* import { open, close, exists } from 'fs';
|
|
3219
|
+
* import { open, close, exists } from 'node:fs';
|
|
3064
3220
|
*
|
|
3065
3221
|
* exists('myfile', (e) => {
|
|
3066
3222
|
* if (e) {
|
|
@@ -3084,7 +3240,7 @@ declare module 'fs' {
|
|
|
3084
3240
|
* **read (RECOMMENDED)**
|
|
3085
3241
|
*
|
|
3086
3242
|
* ```js
|
|
3087
|
-
* import { open, close } from 'fs';
|
|
3243
|
+
* import { open, close } from 'node:fs';
|
|
3088
3244
|
*
|
|
3089
3245
|
* open('myfile', 'r', (err, fd) => {
|
|
3090
3246
|
* if (err) {
|
|
@@ -3110,7 +3266,7 @@ declare module 'fs' {
|
|
|
3110
3266
|
* file; the "recommended" examples are better because they use the file directly
|
|
3111
3267
|
* and handle the error, if any.
|
|
3112
3268
|
*
|
|
3113
|
-
* In general, check for the existence of a file only if the file won
|
|
3269
|
+
* In general, check for the existence of a file only if the file won't be
|
|
3114
3270
|
* used directly, for example when its existence is a signal from another
|
|
3115
3271
|
* process.
|
|
3116
3272
|
* @since v0.0.2
|
|
@@ -3135,7 +3291,7 @@ declare module 'fs' {
|
|
|
3135
3291
|
* Node.js callbacks. `fs.existsSync()` does not use a callback.
|
|
3136
3292
|
*
|
|
3137
3293
|
* ```js
|
|
3138
|
-
* import { existsSync } from 'fs';
|
|
3294
|
+
* import { existsSync } from 'node:fs';
|
|
3139
3295
|
*
|
|
3140
3296
|
* if (existsSync('/etc/passwd'))
|
|
3141
3297
|
* console.log('The path exists.');
|
|
@@ -3269,7 +3425,7 @@ declare module 'fs' {
|
|
|
3269
3425
|
* argument will be an `Error` object. The following examples check if`package.json` exists, and if it is readable or writable.
|
|
3270
3426
|
*
|
|
3271
3427
|
* ```js
|
|
3272
|
-
* import { access, constants } from 'fs';
|
|
3428
|
+
* import { access, constants } from 'node:fs';
|
|
3273
3429
|
*
|
|
3274
3430
|
* const file = 'package.json';
|
|
3275
3431
|
*
|
|
@@ -3294,7 +3450,7 @@ declare module 'fs' {
|
|
|
3294
3450
|
* });
|
|
3295
3451
|
* ```
|
|
3296
3452
|
*
|
|
3297
|
-
* Do not use `fs.access()` to check for the accessibility of a file before calling`fs.open()`, `fs.readFile()
|
|
3453
|
+
* Do not use `fs.access()` to check for the accessibility of a file before calling`fs.open()`, `fs.readFile()`, or `fs.writeFile()`. Doing
|
|
3298
3454
|
* so introduces a race condition, since other processes may change the file's
|
|
3299
3455
|
* state between the two calls. Instead, user code should open/read/write the
|
|
3300
3456
|
* file directly and handle the error raised if the file is not accessible.
|
|
@@ -3302,7 +3458,7 @@ declare module 'fs' {
|
|
|
3302
3458
|
* **write (NOT RECOMMENDED)**
|
|
3303
3459
|
*
|
|
3304
3460
|
* ```js
|
|
3305
|
-
* import { access, open, close } from 'fs';
|
|
3461
|
+
* import { access, open, close } from 'node:fs';
|
|
3306
3462
|
*
|
|
3307
3463
|
* access('myfile', (err) => {
|
|
3308
3464
|
* if (!err) {
|
|
@@ -3327,7 +3483,7 @@ declare module 'fs' {
|
|
|
3327
3483
|
* **write (RECOMMENDED)**
|
|
3328
3484
|
*
|
|
3329
3485
|
* ```js
|
|
3330
|
-
* import { open, close } from 'fs';
|
|
3486
|
+
* import { open, close } from 'node:fs';
|
|
3331
3487
|
*
|
|
3332
3488
|
* open('myfile', 'wx', (err, fd) => {
|
|
3333
3489
|
* if (err) {
|
|
@@ -3352,7 +3508,7 @@ declare module 'fs' {
|
|
|
3352
3508
|
* **read (NOT RECOMMENDED)**
|
|
3353
3509
|
*
|
|
3354
3510
|
* ```js
|
|
3355
|
-
* import { access, open, close } from 'fs';
|
|
3511
|
+
* import { access, open, close } from 'node:fs';
|
|
3356
3512
|
* access('myfile', (err) => {
|
|
3357
3513
|
* if (err) {
|
|
3358
3514
|
* if (err.code === 'ENOENT') {
|
|
@@ -3380,7 +3536,7 @@ declare module 'fs' {
|
|
|
3380
3536
|
* **read (RECOMMENDED)**
|
|
3381
3537
|
*
|
|
3382
3538
|
* ```js
|
|
3383
|
-
* import { open, close } from 'fs';
|
|
3539
|
+
* import { open, close } from 'node:fs';
|
|
3384
3540
|
*
|
|
3385
3541
|
* open('myfile', 'r', (err, fd) => {
|
|
3386
3542
|
* if (err) {
|
|
@@ -3442,7 +3598,7 @@ declare module 'fs' {
|
|
|
3442
3598
|
* the method will return `undefined`.
|
|
3443
3599
|
*
|
|
3444
3600
|
* ```js
|
|
3445
|
-
* import { accessSync, constants } from 'fs';
|
|
3601
|
+
* import { accessSync, constants } from 'node:fs';
|
|
3446
3602
|
*
|
|
3447
3603
|
* try {
|
|
3448
3604
|
* accessSync('etc/passwd', constants.R_OK | constants.W_OK);
|
|
@@ -3472,8 +3628,8 @@ declare module 'fs' {
|
|
|
3472
3628
|
end?: number | undefined;
|
|
3473
3629
|
}
|
|
3474
3630
|
/**
|
|
3475
|
-
* Unlike the 16
|
|
3476
|
-
* returned by this method has a default `highWaterMark` of 64
|
|
3631
|
+
* Unlike the 16 KiB default `highWaterMark` for a `stream.Readable`, the stream
|
|
3632
|
+
* returned by this method has a default `highWaterMark` of 64 KiB.
|
|
3477
3633
|
*
|
|
3478
3634
|
* `options` can include `start` and `end` values to read a range of bytes from
|
|
3479
3635
|
* the file instead of the entire file. Both `start` and `end` are inclusive and
|
|
@@ -3499,7 +3655,7 @@ declare module 'fs' {
|
|
|
3499
3655
|
* also required.
|
|
3500
3656
|
*
|
|
3501
3657
|
* ```js
|
|
3502
|
-
* import { createReadStream } from 'fs';
|
|
3658
|
+
* import { createReadStream } from 'node:fs';
|
|
3503
3659
|
*
|
|
3504
3660
|
* // Create a stream from some character device.
|
|
3505
3661
|
* const stream = createReadStream('/dev/input/event0');
|
|
@@ -3527,7 +3683,7 @@ declare module 'fs' {
|
|
|
3527
3683
|
* An example to read the last 10 bytes of a file which is 100 bytes long:
|
|
3528
3684
|
*
|
|
3529
3685
|
* ```js
|
|
3530
|
-
* import { createReadStream } from 'fs';
|
|
3686
|
+
* import { createReadStream } from 'node:fs';
|
|
3531
3687
|
*
|
|
3532
3688
|
* createReadStream('sample.txt', { start: 90, end: 99 });
|
|
3533
3689
|
* ```
|
|
@@ -3551,7 +3707,7 @@ declare module 'fs' {
|
|
|
3551
3707
|
* By default, the stream will emit a `'close'` event after it has been
|
|
3552
3708
|
* destroyed. Set the `emitClose` option to `false` to change this behavior.
|
|
3553
3709
|
*
|
|
3554
|
-
* By providing the `fs` option it is possible to override the corresponding `fs`implementations for `open`, `write`, `writev
|
|
3710
|
+
* 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
3711
|
* performance as some optimizations (`_writev()`)
|
|
3556
3712
|
* 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
3713
|
* for `open` is also required. If `autoClose` is `true`, an override for `close`is also required.
|
|
@@ -3606,7 +3762,7 @@ declare module 'fs' {
|
|
|
3606
3762
|
* copy-on-write, then the operation will fail.
|
|
3607
3763
|
*
|
|
3608
3764
|
* ```js
|
|
3609
|
-
* import { copyFile, constants } from 'fs';
|
|
3765
|
+
* import { copyFile, constants } from 'node:fs';
|
|
3610
3766
|
*
|
|
3611
3767
|
* function callback(err) {
|
|
3612
3768
|
* if (err) throw err;
|
|
@@ -3649,7 +3805,7 @@ declare module 'fs' {
|
|
|
3649
3805
|
* copy-on-write, then the operation will fail.
|
|
3650
3806
|
*
|
|
3651
3807
|
* ```js
|
|
3652
|
-
* import { copyFileSync, constants } from 'fs';
|
|
3808
|
+
* import { copyFileSync, constants } from 'node:fs';
|
|
3653
3809
|
*
|
|
3654
3810
|
* // destination.txt will be created or overwritten by default.
|
|
3655
3811
|
* copyFileSync('source.txt', 'destination.txt');
|
|
@@ -3682,6 +3838,7 @@ declare module 'fs' {
|
|
|
3682
3838
|
* The kernel ignores the position argument and always appends the data to
|
|
3683
3839
|
* the end of the file.
|
|
3684
3840
|
* @since v12.9.0
|
|
3841
|
+
* @param [position='null']
|
|
3685
3842
|
*/
|
|
3686
3843
|
export function writev(fd: number, buffers: ReadonlyArray<NodeJS.ArrayBufferView>, cb: (err: NodeJS.ErrnoException | null, bytesWritten: number, buffers: NodeJS.ArrayBufferView[]) => void): void;
|
|
3687
3844
|
export function writev(
|
|
@@ -3701,6 +3858,7 @@ declare module 'fs' {
|
|
|
3701
3858
|
* For detailed information, see the documentation of the asynchronous version of
|
|
3702
3859
|
* this API: {@link writev}.
|
|
3703
3860
|
* @since v12.9.0
|
|
3861
|
+
* @param [position='null']
|
|
3704
3862
|
* @return The number of bytes written.
|
|
3705
3863
|
*/
|
|
3706
3864
|
export function writevSync(fd: number, buffers: ReadonlyArray<NodeJS.ArrayBufferView>, position?: number): number;
|
|
@@ -3717,6 +3875,7 @@ declare module 'fs' {
|
|
|
3717
3875
|
* If this method is invoked as its `util.promisify()` ed version, it returns
|
|
3718
3876
|
* a promise for an `Object` with `bytesRead` and `buffers` properties.
|
|
3719
3877
|
* @since v13.13.0, v12.17.0
|
|
3878
|
+
* @param [position='null']
|
|
3720
3879
|
*/
|
|
3721
3880
|
export function readv(fd: number, buffers: ReadonlyArray<NodeJS.ArrayBufferView>, cb: (err: NodeJS.ErrnoException | null, bytesRead: number, buffers: NodeJS.ArrayBufferView[]) => void): void;
|
|
3722
3881
|
export function readv(
|
|
@@ -3736,10 +3895,14 @@ declare module 'fs' {
|
|
|
3736
3895
|
* For detailed information, see the documentation of the asynchronous version of
|
|
3737
3896
|
* this API: {@link readv}.
|
|
3738
3897
|
* @since v13.13.0, v12.17.0
|
|
3898
|
+
* @param [position='null']
|
|
3739
3899
|
* @return The number of bytes read.
|
|
3740
3900
|
*/
|
|
3741
3901
|
export function readvSync(fd: number, buffers: ReadonlyArray<NodeJS.ArrayBufferView>, position?: number): number;
|
|
3742
3902
|
export interface OpenDirOptions {
|
|
3903
|
+
/**
|
|
3904
|
+
* @default 'utf8'
|
|
3905
|
+
*/
|
|
3743
3906
|
encoding?: BufferEncoding | undefined;
|
|
3744
3907
|
/**
|
|
3745
3908
|
* Number of directory entries that are buffered
|
|
@@ -3748,6 +3911,10 @@ declare module 'fs' {
|
|
|
3748
3911
|
* @default 32
|
|
3749
3912
|
*/
|
|
3750
3913
|
bufferSize?: number | undefined;
|
|
3914
|
+
/**
|
|
3915
|
+
* @default false
|
|
3916
|
+
*/
|
|
3917
|
+
recursive?: boolean;
|
|
3751
3918
|
}
|
|
3752
3919
|
/**
|
|
3753
3920
|
* Synchronously open a directory. See [`opendir(3)`](http://man7.org/linux/man-pages/man3/opendir.3.html).
|
|
@@ -3810,6 +3977,10 @@ declare module 'fs' {
|
|
|
3810
3977
|
* @default true
|
|
3811
3978
|
*/
|
|
3812
3979
|
force?: boolean;
|
|
3980
|
+
/**
|
|
3981
|
+
* Modifiers for copy operation. See `mode` flag of {@link copyFileSync()}
|
|
3982
|
+
*/
|
|
3983
|
+
mode?: number;
|
|
3813
3984
|
/**
|
|
3814
3985
|
* When `true` timestamps from `src` will
|
|
3815
3986
|
* be preserved.
|