@types/node 18.16.5 → 20.1.0
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 v18.16/README.md → node/README.md +2 -2
- node v18.16/ts4.8/assert.d.ts → node/assert.d.ts +71 -75
- node v18.16/async_hooks.d.ts → node/async_hooks.d.ts +62 -42
- node v18.16/buffer.d.ts → node/buffer.d.ts +127 -99
- node v18.16/child_process.d.ts → node/child_process.d.ts +50 -54
- node v18.16/ts4.8/cluster.d.ts → node/cluster.d.ts +12 -12
- node v18.16/ts4.8/console.d.ts → node/console.d.ts +5 -5
- node v18.16/crypto.d.ts → node/crypto.d.ts +209 -220
- node v18.16/ts4.8/dgram.d.ts → node/dgram.d.ts +15 -15
- node v18.16/diagnostics_channel.d.ts → node/diagnostics_channel.d.ts +25 -26
- node v18.16/dns/promises.d.ts → node/dns/promises.d.ts +6 -6
- node v18.16/ts4.8/dns.d.ts → node/dns.d.ts +24 -16
- node v18.16/domain.d.ts → node/domain.d.ts +4 -4
- node v18.16/events.d.ts → node/events.d.ts +60 -60
- node v18.16/fs/promises.d.ts → node/fs/promises.d.ts +78 -48
- node v18.16/fs.d.ts → node/fs.d.ts +117 -81
- node v18.16/http.d.ts → node/http.d.ts +155 -145
- node v18.16/ts4.8/http2.d.ts → node/http2.d.ts +42 -46
- node v18.16/https.d.ts → node/https.d.ts +52 -153
- node v18.16/index.d.ts → node/index.d.ts +1 -1
- node v18.16/ts4.8/inspector.d.ts → node/inspector.d.ts +10 -3
- node v18.16/ts4.8/module.d.ts → node/module.d.ts +5 -4
- node v18.16/ts4.8/net.d.ts → node/net.d.ts +24 -21
- node v18.16/ts4.8/os.d.ts → node/os.d.ts +22 -18
- node v18.16/package.json → node/package.json +2 -2
- node v18.16/ts4.8/path.d.ts → node/path.d.ts +4 -4
- node v18.16/perf_hooks.d.ts → node/perf_hooks.d.ts +28 -15
- node v18.16/process.d.ts → node/process.d.ts +43 -46
- node v18.16/ts4.8/punycode.d.ts → node/punycode.d.ts +1 -1
- node v18.16/ts4.8/querystring.d.ts → node/querystring.d.ts +5 -5
- node v18.16/readline/promises.d.ts → node/readline/promises.d.ts +6 -4
- node v18.16/readline.d.ts → node/readline.d.ts +15 -15
- node v18.16/repl.d.ts → node/repl.d.ts +9 -9
- node v18.16/stream/consumers.d.ts → node/stream/consumers.d.ts +1 -1
- node v18.16/stream.d.ts → node/stream.d.ts +88 -136
- node v18.16/ts4.8/string_decoder.d.ts → node/string_decoder.d.ts +6 -6
- node v18.16/ts4.8/test.d.ts → node/test.d.ts +423 -186
- node v18.16/timers/promises.d.ts → node/timers/promises.d.ts +3 -3
- node v18.16/timers.d.ts → node/timers.d.ts +2 -2
- node v18.16/ts4.8/tls.d.ts → node/tls.d.ts +24 -16
- node v18.16/ts4.8/trace_events.d.ts → node/trace_events.d.ts +20 -9
- node v18.16/assert.d.ts → node/ts4.8/assert.d.ts +71 -75
- node v18.16/ts4.8/async_hooks.d.ts → node/ts4.8/async_hooks.d.ts +62 -42
- node v18.16/ts4.8/buffer.d.ts → node/ts4.8/buffer.d.ts +127 -99
- node v18.16/ts4.8/child_process.d.ts → node/ts4.8/child_process.d.ts +50 -54
- node v18.16/cluster.d.ts → node/ts4.8/cluster.d.ts +12 -12
- node v18.16/console.d.ts → node/ts4.8/console.d.ts +5 -5
- node v18.16/ts4.8/crypto.d.ts → node/ts4.8/crypto.d.ts +209 -220
- node v18.16/dgram.d.ts → node/ts4.8/dgram.d.ts +15 -15
- node v18.16/ts4.8/diagnostics_channel.d.ts → node/ts4.8/diagnostics_channel.d.ts +25 -26
- node v18.16/ts4.8/dns/promises.d.ts → node/ts4.8/dns/promises.d.ts +6 -6
- node v18.16/dns.d.ts → node/ts4.8/dns.d.ts +24 -16
- node v18.16/ts4.8/domain.d.ts → node/ts4.8/domain.d.ts +4 -4
- node v18.16/ts4.8/events.d.ts → node/ts4.8/events.d.ts +60 -60
- node v18.16/ts4.8/fs/promises.d.ts → node/ts4.8/fs/promises.d.ts +96 -45
- node v18.16/ts4.8/fs.d.ts → node/ts4.8/fs.d.ts +203 -67
- node v18.16/ts4.8/globals.d.ts → node/ts4.8/globals.d.ts +29 -28
- node v18.16/ts4.8/http.d.ts → node/ts4.8/http.d.ts +198 -126
- node v18.16/http2.d.ts → node/ts4.8/http2.d.ts +42 -46
- node v18.16/ts4.8/https.d.ts → node/ts4.8/https.d.ts +52 -153
- node v18.16/inspector.d.ts → node/ts4.8/inspector.d.ts +10 -3
- node v18.16/module.d.ts → node/ts4.8/module.d.ts +5 -4
- node v18.16/net.d.ts → node/ts4.8/net.d.ts +21 -18
- node v18.16/os.d.ts → node/ts4.8/os.d.ts +22 -18
- node v18.16/path.d.ts → node/ts4.8/path.d.ts +4 -4
- node v18.16/ts4.8/perf_hooks.d.ts → node/ts4.8/perf_hooks.d.ts +28 -15
- node v18.16/ts4.8/process.d.ts → node/ts4.8/process.d.ts +43 -46
- node v18.16/punycode.d.ts → node/ts4.8/punycode.d.ts +1 -1
- node v18.16/querystring.d.ts → node/ts4.8/querystring.d.ts +5 -5
- node v18.16/ts4.8/readline/promises.d.ts → node/ts4.8/readline/promises.d.ts +6 -4
- node v18.16/ts4.8/readline.d.ts → node/ts4.8/readline.d.ts +15 -15
- node v18.16/ts4.8/repl.d.ts → node/ts4.8/repl.d.ts +9 -9
- node v18.16/ts4.8/stream/consumers.d.ts → node/ts4.8/stream/consumers.d.ts +1 -1
- node v18.16/ts4.8/stream.d.ts → node/ts4.8/stream.d.ts +91 -139
- node v18.16/string_decoder.d.ts → node/ts4.8/string_decoder.d.ts +6 -6
- node v18.16/test.d.ts → node/ts4.8/test.d.ts +423 -186
- node v18.16/ts4.8/timers/promises.d.ts → node/ts4.8/timers/promises.d.ts +3 -3
- node v18.16/ts4.8/timers.d.ts → node/ts4.8/timers.d.ts +9 -2
- node v18.16/tls.d.ts → node/ts4.8/tls.d.ts +24 -16
- node v18.16/trace_events.d.ts → node/ts4.8/trace_events.d.ts +20 -9
- node v18.16/tty.d.ts → node/ts4.8/tty.d.ts +4 -5
- node v18.16/ts4.8/url.d.ts → node/ts4.8/url.d.ts +26 -36
- node v18.16/ts4.8/util.d.ts → node/ts4.8/util.d.ts +143 -116
- node v18.16/ts4.8/v8.d.ts → node/ts4.8/v8.d.ts +110 -16
- node v18.16/vm.d.ts → node/ts4.8/vm.d.ts +292 -42
- node v18.16/wasi.d.ts → node/ts4.8/wasi.d.ts +13 -19
- node v18.16/ts4.8/worker_threads.d.ts → node/ts4.8/worker_threads.d.ts +32 -34
- node v18.16/zlib.d.ts → node/ts4.8/zlib.d.ts +11 -11
- node v18.16/ts4.8/tty.d.ts → node/tty.d.ts +4 -5
- node v18.16/url.d.ts → node/url.d.ts +26 -36
- node v18.16/util.d.ts → node/util.d.ts +146 -111
- node v18.16/v8.d.ts → node/v8.d.ts +110 -16
- node v18.16/ts4.8/vm.d.ts → node/vm.d.ts +292 -42
- node v18.16/ts4.8/wasi.d.ts → node/wasi.d.ts +13 -19
- node v18.16/worker_threads.d.ts → node/worker_threads.d.ts +32 -34
- node v18.16/ts4.8/zlib.d.ts → node/zlib.d.ts +11 -11
- {node v18.16 → node}/LICENSE +0 -0
- {node v18.16 → node}/assert/strict.d.ts +0 -0
- {node v18.16 → node}/constants.d.ts +0 -0
- {node v18.16 → node}/dom-events.d.ts +0 -0
- {node v18.16 → node}/globals.d.ts +0 -0
- {node v18.16 → node}/globals.global.d.ts +0 -0
- {node v18.16 → node}/stream/promises.d.ts +0 -0
- {node v18.16 → node}/stream/web.d.ts +0 -0
- {node v18.16 → node}/ts4.8/assert/strict.d.ts +0 -0
- {node v18.16 → node}/ts4.8/constants.d.ts +0 -0
- {node v18.16 → node}/ts4.8/dom-events.d.ts +0 -0
- {node v18.16 → node}/ts4.8/globals.global.d.ts +0 -0
- {node v18.16 → node}/ts4.8/index.d.ts +0 -0
- {node v18.16 → node}/ts4.8/stream/promises.d.ts +0 -0
- {node v18.16 → node}/ts4.8/stream/web.d.ts +0 -0
|
@@ -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.1.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,7 +131,6 @@ declare module 'fs' {
|
|
|
131
131
|
* @since v0.1.21
|
|
132
132
|
*/
|
|
133
133
|
export class Stats {}
|
|
134
|
-
|
|
135
134
|
export interface StatsFsBase<T> {
|
|
136
135
|
/** Type of file system. */
|
|
137
136
|
type: T;
|
|
@@ -148,9 +147,7 @@ declare module 'fs' {
|
|
|
148
147
|
/** Free file nodes in file system. */
|
|
149
148
|
ffree: T;
|
|
150
149
|
}
|
|
151
|
-
|
|
152
150
|
export interface StatsFs extends StatsFsBase<number> {}
|
|
153
|
-
|
|
154
151
|
/**
|
|
155
152
|
* Provides information about a mounted file system
|
|
156
153
|
*
|
|
@@ -160,13 +157,10 @@ declare module 'fs' {
|
|
|
160
157
|
* @since v18.15.0
|
|
161
158
|
*/
|
|
162
159
|
export class StatsFs {}
|
|
163
|
-
|
|
164
160
|
export interface BigIntStatsFs extends StatsFsBase<bigint> {}
|
|
165
|
-
|
|
166
161
|
export interface StatFsOptions {
|
|
167
162
|
bigint?: boolean | undefined;
|
|
168
163
|
}
|
|
169
|
-
|
|
170
164
|
/**
|
|
171
165
|
* A representation of a directory entry, which can be a file or a subdirectory
|
|
172
166
|
* within the directory, as returned by reading from an `fs.Dir`. The
|
|
@@ -227,7 +221,7 @@ declare module 'fs' {
|
|
|
227
221
|
* Created by {@link opendir}, {@link opendirSync}, or `fsPromises.opendir()`.
|
|
228
222
|
*
|
|
229
223
|
* ```js
|
|
230
|
-
* import { opendir } from 'fs/promises';
|
|
224
|
+
* import { opendir } from 'node:fs/promises';
|
|
231
225
|
*
|
|
232
226
|
* try {
|
|
233
227
|
* const dir = await opendir('./');
|
|
@@ -530,7 +524,7 @@ declare module 'fs' {
|
|
|
530
524
|
* See also: [`rename(2)`](http://man7.org/linux/man-pages/man2/rename.2.html).
|
|
531
525
|
*
|
|
532
526
|
* ```js
|
|
533
|
-
* import { rename } from 'fs';
|
|
527
|
+
* import { rename } from 'node:fs';
|
|
534
528
|
*
|
|
535
529
|
* rename('oldFile.txt', 'newFile.txt', (err) => {
|
|
536
530
|
* if (err) throw err;
|
|
@@ -563,7 +557,7 @@ declare module 'fs' {
|
|
|
563
557
|
* first argument. In this case, `fs.ftruncate()` is called.
|
|
564
558
|
*
|
|
565
559
|
* ```js
|
|
566
|
-
* import { truncate } from 'fs';
|
|
560
|
+
* import { truncate } from 'node:fs';
|
|
567
561
|
* // Assuming that 'path/file.txt' is a regular file.
|
|
568
562
|
* truncate('path/file.txt', (err) => {
|
|
569
563
|
* if (err) throw err;
|
|
@@ -615,7 +609,7 @@ declare module 'fs' {
|
|
|
615
609
|
* file:
|
|
616
610
|
*
|
|
617
611
|
* ```js
|
|
618
|
-
* import { open, close, ftruncate } from 'fs';
|
|
612
|
+
* import { open, close, ftruncate } from 'node:fs';
|
|
619
613
|
*
|
|
620
614
|
* function closeFd(fd) {
|
|
621
615
|
* close(fd, (err) => {
|
|
@@ -772,7 +766,7 @@ declare module 'fs' {
|
|
|
772
766
|
* See the POSIX [`chmod(2)`](http://man7.org/linux/man-pages/man2/chmod.2.html) documentation for more detail.
|
|
773
767
|
*
|
|
774
768
|
* ```js
|
|
775
|
-
* import { chmod } from 'fs';
|
|
769
|
+
* import { chmod } from 'node:fs';
|
|
776
770
|
*
|
|
777
771
|
* chmod('my_file.txt', 0o775, (err) => {
|
|
778
772
|
* if (err) throw err;
|
|
@@ -854,7 +848,10 @@ declare module 'fs' {
|
|
|
854
848
|
*
|
|
855
849
|
* In case of an error, the `err.code` will be one of `Common System Errors`.
|
|
856
850
|
*
|
|
857
|
-
*
|
|
851
|
+
* {@link stat} follows symbolic links. Use {@link lstat} to look at the
|
|
852
|
+
* links themselves.
|
|
853
|
+
*
|
|
854
|
+
* Using `fs.stat()` to check for the existence of a file before calling`fs.open()`, `fs.readFile()`, or `fs.writeFile()` is not recommended.
|
|
858
855
|
* Instead, user code should open/read/write the file directly and handle the
|
|
859
856
|
* error raised if the file is not available.
|
|
860
857
|
*
|
|
@@ -871,7 +868,7 @@ declare module 'fs' {
|
|
|
871
868
|
* The next program will check for the stats of the given paths:
|
|
872
869
|
*
|
|
873
870
|
* ```js
|
|
874
|
-
* import { stat } from 'fs';
|
|
871
|
+
* import { stat } from 'node:fs';
|
|
875
872
|
*
|
|
876
873
|
* const pathsToCheck = ['./txtDir', './txtDir/file.txt'];
|
|
877
874
|
*
|
|
@@ -1118,10 +1115,12 @@ declare module 'fs' {
|
|
|
1118
1115
|
function __promisify__(path: PathLike, options?: StatOptions): Promise<Stats | BigIntStats>;
|
|
1119
1116
|
}
|
|
1120
1117
|
/**
|
|
1121
|
-
* Asynchronous statfs(2). Returns information about the mounted file system which
|
|
1122
|
-
*
|
|
1118
|
+
* Asynchronous [`statfs(2)`](http://man7.org/linux/man-pages/man2/statfs.2.html). Returns information about the mounted file system which
|
|
1119
|
+
* contains `path`. The callback gets two arguments `(err, stats)` where `stats`is an `fs.StatFs` object.
|
|
1120
|
+
*
|
|
1121
|
+
* In case of an error, the `err.code` will be one of `Common System Errors`.
|
|
1122
|
+
* @since v19.6.0, v18.15.0
|
|
1123
1123
|
* @param path A path to an existing file or directory on the file system to be queried.
|
|
1124
|
-
* @param callback
|
|
1125
1124
|
*/
|
|
1126
1125
|
export function statfs(path: PathLike, callback: (err: NodeJS.ErrnoException | null, stats: StatsFs) => void): void;
|
|
1127
1126
|
export function statfs(
|
|
@@ -1160,12 +1159,13 @@ declare module 'fs' {
|
|
|
1160
1159
|
): Promise<BigIntStatsFs>;
|
|
1161
1160
|
function __promisify__(path: PathLike, options?: StatFsOptions): Promise<StatsFs | BigIntStatsFs>;
|
|
1162
1161
|
}
|
|
1163
|
-
|
|
1164
1162
|
/**
|
|
1165
|
-
* Synchronous statfs(2). Returns information about the mounted file system which
|
|
1166
|
-
*
|
|
1163
|
+
* Synchronous [`statfs(2)`](http://man7.org/linux/man-pages/man2/statfs.2.html). Returns information about the mounted file system which
|
|
1164
|
+
* contains `path`.
|
|
1165
|
+
*
|
|
1166
|
+
* In case of an error, the `err.code` will be one of `Common System Errors`.
|
|
1167
|
+
* @since v19.6.0, v18.15.0
|
|
1167
1168
|
* @param path A path to an existing file or directory on the file system to be queried.
|
|
1168
|
-
* @param callback
|
|
1169
1169
|
*/
|
|
1170
1170
|
export function statfsSync(
|
|
1171
1171
|
path: PathLike,
|
|
@@ -1179,7 +1179,6 @@ declare module 'fs' {
|
|
|
1179
1179
|
bigint: true;
|
|
1180
1180
|
}
|
|
1181
1181
|
): BigIntStatsFs;
|
|
1182
|
-
|
|
1183
1182
|
export function statfsSync(path: PathLike, options?: StatFsOptions): StatsFs | BigIntStatsFs;
|
|
1184
1183
|
/**
|
|
1185
1184
|
* Synchronous lstat(2) - Get file status. Does not dereference symbolic links.
|
|
@@ -1214,14 +1213,14 @@ declare module 'fs' {
|
|
|
1214
1213
|
*
|
|
1215
1214
|
* The `type` argument is only available on Windows and ignored on other platforms.
|
|
1216
1215
|
* It can be set to `'dir'`, `'file'`, or `'junction'`. If the `type` argument is
|
|
1217
|
-
* not
|
|
1218
|
-
* the `target` does not exist, `'file'` will be used. Windows junction points
|
|
1216
|
+
* not a string, Node.js will autodetect `target` type and use `'file'` or `'dir'`.
|
|
1217
|
+
* If the `target` does not exist, `'file'` will be used. Windows junction points
|
|
1219
1218
|
* require the destination path to be absolute. When using `'junction'`, the`target` argument will automatically be normalized to absolute path.
|
|
1220
1219
|
*
|
|
1221
|
-
* Relative targets are relative to the link
|
|
1220
|
+
* Relative targets are relative to the link's parent directory.
|
|
1222
1221
|
*
|
|
1223
1222
|
* ```js
|
|
1224
|
-
* import { symlink } from 'fs';
|
|
1223
|
+
* import { symlink } from 'node:fs';
|
|
1225
1224
|
*
|
|
1226
1225
|
* symlink('./mew', './mewtwo', callback);
|
|
1227
1226
|
* ```
|
|
@@ -1236,6 +1235,7 @@ declare module 'fs' {
|
|
|
1236
1235
|
* └── mewtwo -> ./mew
|
|
1237
1236
|
* ```
|
|
1238
1237
|
* @since v0.1.31
|
|
1238
|
+
* @param [type='null']
|
|
1239
1239
|
*/
|
|
1240
1240
|
export function symlink(target: PathLike, path: PathLike, type: symlink.Type | undefined | null, callback: NoParamCallback): void;
|
|
1241
1241
|
/**
|
|
@@ -1261,6 +1261,7 @@ declare module 'fs' {
|
|
|
1261
1261
|
* For detailed information, see the documentation of the asynchronous version of
|
|
1262
1262
|
* this API: {@link symlink}.
|
|
1263
1263
|
* @since v0.1.31
|
|
1264
|
+
* @param [type='null']
|
|
1264
1265
|
*/
|
|
1265
1266
|
export function symlinkSync(target: PathLike, path: PathLike, type?: symlink.Type | null): void;
|
|
1266
1267
|
/**
|
|
@@ -1338,7 +1339,7 @@ declare module 'fs' {
|
|
|
1338
1339
|
*/
|
|
1339
1340
|
export function readlinkSync(path: PathLike, options?: EncodingOption): string | Buffer;
|
|
1340
1341
|
/**
|
|
1341
|
-
* Asynchronously computes the canonical pathname by resolving `.`,
|
|
1342
|
+
* Asynchronously computes the canonical pathname by resolving `.`, `..`, and
|
|
1342
1343
|
* symbolic links.
|
|
1343
1344
|
*
|
|
1344
1345
|
* A canonical pathname is not necessarily unique. Hard links and bind mounts can
|
|
@@ -1452,7 +1453,7 @@ declare module 'fs' {
|
|
|
1452
1453
|
* possible exception are given to the completion callback.
|
|
1453
1454
|
*
|
|
1454
1455
|
* ```js
|
|
1455
|
-
* import { unlink } from 'fs';
|
|
1456
|
+
* import { unlink } from 'node:fs';
|
|
1456
1457
|
* // Assuming that 'path/file.txt' is a regular file.
|
|
1457
1458
|
* unlink('path/file.txt', (err) => {
|
|
1458
1459
|
* if (err) throw err;
|
|
@@ -1607,7 +1608,7 @@ declare module 'fs' {
|
|
|
1607
1608
|
* when `recursive` is false.
|
|
1608
1609
|
*
|
|
1609
1610
|
* ```js
|
|
1610
|
-
* import { mkdir } from 'fs';
|
|
1611
|
+
* import { mkdir } from 'node:fs';
|
|
1611
1612
|
*
|
|
1612
1613
|
* // Creates /tmp/a/apple, regardless of whether `/tmp` and /tmp/a exist.
|
|
1613
1614
|
* mkdir('/tmp/a/apple', { recursive: true }, (err) => {
|
|
@@ -1619,7 +1620,7 @@ declare module 'fs' {
|
|
|
1619
1620
|
* result in an error:
|
|
1620
1621
|
*
|
|
1621
1622
|
* ```js
|
|
1622
|
-
* import { mkdir } from 'fs';
|
|
1623
|
+
* import { mkdir } from 'node:fs';
|
|
1623
1624
|
*
|
|
1624
1625
|
* mkdir('/', { recursive: true }, (err) => {
|
|
1625
1626
|
* // => [Error: EPERM: operation not permitted, mkdir 'C:\']
|
|
@@ -1751,9 +1752,11 @@ declare module 'fs' {
|
|
|
1751
1752
|
* object with an `encoding` property specifying the character encoding to use.
|
|
1752
1753
|
*
|
|
1753
1754
|
* ```js
|
|
1754
|
-
* import { mkdtemp } from 'fs';
|
|
1755
|
+
* import { mkdtemp } from 'node:fs';
|
|
1756
|
+
* import { join } from 'node:path';
|
|
1757
|
+
* import { tmpdir } from 'node:os';
|
|
1755
1758
|
*
|
|
1756
|
-
* mkdtemp(
|
|
1759
|
+
* mkdtemp(join(tmpdir(), 'foo-'), (err, directory) => {
|
|
1757
1760
|
* if (err) throw err;
|
|
1758
1761
|
* console.log(directory);
|
|
1759
1762
|
* // Prints: /tmp/foo-itXde2 or C:\Users\...\AppData\Local\Temp\foo-itXde2
|
|
@@ -1763,11 +1766,11 @@ declare module 'fs' {
|
|
|
1763
1766
|
* The `fs.mkdtemp()` method will append the six randomly selected characters
|
|
1764
1767
|
* directly to the `prefix` string. For instance, given a directory `/tmp`, if the
|
|
1765
1768
|
* intention is to create a temporary directory _within_`/tmp`, the `prefix`must end with a trailing platform-specific path separator
|
|
1766
|
-
* (`require('path').sep`).
|
|
1769
|
+
* (`require('node:path').sep`).
|
|
1767
1770
|
*
|
|
1768
1771
|
* ```js
|
|
1769
|
-
* import { tmpdir } from 'os';
|
|
1770
|
-
* import { mkdtemp } from 'fs';
|
|
1772
|
+
* import { tmpdir } from 'node:os';
|
|
1773
|
+
* import { mkdtemp } from 'node:fs';
|
|
1771
1774
|
*
|
|
1772
1775
|
* // The parent directory for the new temporary directory
|
|
1773
1776
|
* const tmpDir = tmpdir();
|
|
@@ -1782,7 +1785,7 @@ declare module 'fs' {
|
|
|
1782
1785
|
* });
|
|
1783
1786
|
*
|
|
1784
1787
|
* // This method is *CORRECT*:
|
|
1785
|
-
* import { sep } from 'path';
|
|
1788
|
+
* import { sep } from 'node:path';
|
|
1786
1789
|
* mkdtemp(`${tmpDir}${sep}`, (err, directory) => {
|
|
1787
1790
|
* if (err) throw err;
|
|
1788
1791
|
* console.log(directory);
|
|
@@ -1881,6 +1884,7 @@ declare module 'fs' {
|
|
|
1881
1884
|
| {
|
|
1882
1885
|
encoding: BufferEncoding | null;
|
|
1883
1886
|
withFileTypes?: false | undefined;
|
|
1887
|
+
recursive?: boolean | undefined;
|
|
1884
1888
|
}
|
|
1885
1889
|
| BufferEncoding
|
|
1886
1890
|
| undefined
|
|
@@ -1898,6 +1902,7 @@ declare module 'fs' {
|
|
|
1898
1902
|
| {
|
|
1899
1903
|
encoding: 'buffer';
|
|
1900
1904
|
withFileTypes?: false | undefined;
|
|
1905
|
+
recursive?: boolean | undefined;
|
|
1901
1906
|
}
|
|
1902
1907
|
| 'buffer',
|
|
1903
1908
|
callback: (err: NodeJS.ErrnoException | null, files: Buffer[]) => void
|
|
@@ -1912,6 +1917,7 @@ declare module 'fs' {
|
|
|
1912
1917
|
options:
|
|
1913
1918
|
| (ObjectEncodingOptions & {
|
|
1914
1919
|
withFileTypes?: false | undefined;
|
|
1920
|
+
recursive?: boolean | undefined;
|
|
1915
1921
|
})
|
|
1916
1922
|
| BufferEncoding
|
|
1917
1923
|
| undefined
|
|
@@ -1932,6 +1938,7 @@ declare module 'fs' {
|
|
|
1932
1938
|
path: PathLike,
|
|
1933
1939
|
options: ObjectEncodingOptions & {
|
|
1934
1940
|
withFileTypes: true;
|
|
1941
|
+
recursive?: boolean | undefined;
|
|
1935
1942
|
},
|
|
1936
1943
|
callback: (err: NodeJS.ErrnoException | null, files: Dirent[]) => void
|
|
1937
1944
|
): void;
|
|
@@ -1947,6 +1954,7 @@ declare module 'fs' {
|
|
|
1947
1954
|
| {
|
|
1948
1955
|
encoding: BufferEncoding | null;
|
|
1949
1956
|
withFileTypes?: false | undefined;
|
|
1957
|
+
recursive?: boolean | undefined;
|
|
1950
1958
|
}
|
|
1951
1959
|
| BufferEncoding
|
|
1952
1960
|
| null
|
|
@@ -1963,6 +1971,7 @@ declare module 'fs' {
|
|
|
1963
1971
|
| {
|
|
1964
1972
|
encoding: 'buffer';
|
|
1965
1973
|
withFileTypes?: false | undefined;
|
|
1974
|
+
recursive?: boolean | undefined;
|
|
1966
1975
|
}
|
|
1967
1976
|
): Promise<Buffer[]>;
|
|
1968
1977
|
/**
|
|
@@ -1975,6 +1984,7 @@ declare module 'fs' {
|
|
|
1975
1984
|
options?:
|
|
1976
1985
|
| (ObjectEncodingOptions & {
|
|
1977
1986
|
withFileTypes?: false | undefined;
|
|
1987
|
+
recursive?: boolean | undefined;
|
|
1978
1988
|
})
|
|
1979
1989
|
| BufferEncoding
|
|
1980
1990
|
| null
|
|
@@ -1988,6 +1998,7 @@ declare module 'fs' {
|
|
|
1988
1998
|
path: PathLike,
|
|
1989
1999
|
options: ObjectEncodingOptions & {
|
|
1990
2000
|
withFileTypes: true;
|
|
2001
|
+
recursive?: boolean | undefined;
|
|
1991
2002
|
}
|
|
1992
2003
|
): Promise<Dirent[]>;
|
|
1993
2004
|
}
|
|
@@ -2010,6 +2021,7 @@ declare module 'fs' {
|
|
|
2010
2021
|
| {
|
|
2011
2022
|
encoding: BufferEncoding | null;
|
|
2012
2023
|
withFileTypes?: false | undefined;
|
|
2024
|
+
recursive?: boolean | undefined;
|
|
2013
2025
|
}
|
|
2014
2026
|
| BufferEncoding
|
|
2015
2027
|
| null
|
|
@@ -2025,6 +2037,7 @@ declare module 'fs' {
|
|
|
2025
2037
|
| {
|
|
2026
2038
|
encoding: 'buffer';
|
|
2027
2039
|
withFileTypes?: false | undefined;
|
|
2040
|
+
recursive?: boolean | undefined;
|
|
2028
2041
|
}
|
|
2029
2042
|
| 'buffer'
|
|
2030
2043
|
): Buffer[];
|
|
@@ -2038,6 +2051,7 @@ declare module 'fs' {
|
|
|
2038
2051
|
options?:
|
|
2039
2052
|
| (ObjectEncodingOptions & {
|
|
2040
2053
|
withFileTypes?: false | undefined;
|
|
2054
|
+
recursive?: boolean | undefined;
|
|
2041
2055
|
})
|
|
2042
2056
|
| BufferEncoding
|
|
2043
2057
|
| null
|
|
@@ -2051,6 +2065,7 @@ declare module 'fs' {
|
|
|
2051
2065
|
path: PathLike,
|
|
2052
2066
|
options: ObjectEncodingOptions & {
|
|
2053
2067
|
withFileTypes: true;
|
|
2068
|
+
recursive?: boolean | undefined;
|
|
2054
2069
|
}
|
|
2055
2070
|
): Dirent[];
|
|
2056
2071
|
/**
|
|
@@ -2110,7 +2125,6 @@ declare module 'fs' {
|
|
|
2110
2125
|
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
2111
2126
|
*/
|
|
2112
2127
|
export function open(path: PathLike, callback: (err: NodeJS.ErrnoException | null, fd: number) => void): void;
|
|
2113
|
-
|
|
2114
2128
|
export namespace open {
|
|
2115
2129
|
/**
|
|
2116
2130
|
* Asynchronous open(2) - open and possibly create a file.
|
|
@@ -2135,7 +2149,7 @@ declare module 'fs' {
|
|
|
2135
2149
|
* The `atime` and `mtime` arguments follow these rules:
|
|
2136
2150
|
*
|
|
2137
2151
|
* * Values can be either numbers representing Unix epoch time in seconds,`Date`s, or a numeric string like `'123456789.0'`.
|
|
2138
|
-
* * If the value can not be converted to a number, or is `NaN`, `Infinity
|
|
2152
|
+
* * If the value can not be converted to a number, or is `NaN`, `Infinity`, or`-Infinity`, an `Error` will be thrown.
|
|
2139
2153
|
* @since v0.4.2
|
|
2140
2154
|
*/
|
|
2141
2155
|
export function utimes(path: PathLike, atime: TimeLike, mtime: TimeLike, callback: NoParamCallback): void;
|
|
@@ -2221,6 +2235,9 @@ declare module 'fs' {
|
|
|
2221
2235
|
* The kernel ignores the position argument and always appends the data to
|
|
2222
2236
|
* the end of the file.
|
|
2223
2237
|
* @since v0.0.2
|
|
2238
|
+
* @param [offset=0]
|
|
2239
|
+
* @param [length=buffer.byteLength - offset]
|
|
2240
|
+
* @param [position='null']
|
|
2224
2241
|
*/
|
|
2225
2242
|
export function write<TBuffer extends NodeJS.ArrayBufferView>(
|
|
2226
2243
|
fd: number,
|
|
@@ -2325,6 +2342,9 @@ declare module 'fs' {
|
|
|
2325
2342
|
* For detailed information, see the documentation of the asynchronous version of
|
|
2326
2343
|
* this API: {@link write}.
|
|
2327
2344
|
* @since v0.1.21
|
|
2345
|
+
* @param [offset=0]
|
|
2346
|
+
* @param [length=buffer.byteLength - offset]
|
|
2347
|
+
* @param [position='null']
|
|
2328
2348
|
* @return The number of bytes written.
|
|
2329
2349
|
*/
|
|
2330
2350
|
export function writeSync(fd: number, buffer: NodeJS.ArrayBufferView, offset?: number | null, length?: number | null, position?: number | null): number;
|
|
@@ -2430,6 +2450,7 @@ declare module 'fs' {
|
|
|
2430
2450
|
* For detailed information, see the documentation of the asynchronous version of
|
|
2431
2451
|
* this API: {@link read}.
|
|
2432
2452
|
* @since v0.1.21
|
|
2453
|
+
* @param [position='null']
|
|
2433
2454
|
*/
|
|
2434
2455
|
export function readSync(fd: number, buffer: NodeJS.ArrayBufferView, offset: number, length: number, position: ReadPosition | null): number;
|
|
2435
2456
|
/**
|
|
@@ -2441,7 +2462,7 @@ declare module 'fs' {
|
|
|
2441
2462
|
* Asynchronously reads the entire contents of a file.
|
|
2442
2463
|
*
|
|
2443
2464
|
* ```js
|
|
2444
|
-
* import { readFile } from 'fs';
|
|
2465
|
+
* import { readFile } from 'node:fs';
|
|
2445
2466
|
*
|
|
2446
2467
|
* readFile('/etc/passwd', (err, data) => {
|
|
2447
2468
|
* if (err) throw err;
|
|
@@ -2457,7 +2478,7 @@ declare module 'fs' {
|
|
|
2457
2478
|
* If `options` is a string, then it specifies the encoding:
|
|
2458
2479
|
*
|
|
2459
2480
|
* ```js
|
|
2460
|
-
* import { readFile } from 'fs';
|
|
2481
|
+
* import { readFile } from 'node:fs';
|
|
2461
2482
|
*
|
|
2462
2483
|
* readFile('/etc/passwd', 'utf8', callback);
|
|
2463
2484
|
* ```
|
|
@@ -2467,7 +2488,7 @@ declare module 'fs' {
|
|
|
2467
2488
|
* will be returned.
|
|
2468
2489
|
*
|
|
2469
2490
|
* ```js
|
|
2470
|
-
* import { readFile } from 'fs';
|
|
2491
|
+
* import { readFile } from 'node:fs';
|
|
2471
2492
|
*
|
|
2472
2493
|
* // macOS, Linux, and Windows
|
|
2473
2494
|
* readFile('<directory>', (err, data) => {
|
|
@@ -2484,7 +2505,7 @@ declare module 'fs' {
|
|
|
2484
2505
|
* request is aborted the callback is called with an `AbortError`:
|
|
2485
2506
|
*
|
|
2486
2507
|
* ```js
|
|
2487
|
-
* import { readFile } from 'fs';
|
|
2508
|
+
* import { readFile } from 'node:fs';
|
|
2488
2509
|
*
|
|
2489
2510
|
* const controller = new AbortController();
|
|
2490
2511
|
* const signal = controller.signal;
|
|
@@ -2617,7 +2638,7 @@ declare module 'fs' {
|
|
|
2617
2638
|
* Similar to {@link readFile}, when the path is a directory, the behavior of`fs.readFileSync()` is platform-specific.
|
|
2618
2639
|
*
|
|
2619
2640
|
* ```js
|
|
2620
|
-
* import { readFileSync } from 'fs';
|
|
2641
|
+
* import { readFileSync } from 'node:fs';
|
|
2621
2642
|
*
|
|
2622
2643
|
* // macOS, Linux, and Windows
|
|
2623
2644
|
* readFileSync('<directory>');
|
|
@@ -2688,8 +2709,8 @@ declare module 'fs' {
|
|
|
2688
2709
|
* The `mode` option only affects the newly created file. See {@link open} for more details.
|
|
2689
2710
|
*
|
|
2690
2711
|
* ```js
|
|
2691
|
-
* import { writeFile } from 'fs';
|
|
2692
|
-
* import { Buffer } from 'buffer';
|
|
2712
|
+
* import { writeFile } from 'node:fs';
|
|
2713
|
+
* import { Buffer } from 'node:buffer';
|
|
2693
2714
|
*
|
|
2694
2715
|
* const data = new Uint8Array(Buffer.from('Hello Node.js'));
|
|
2695
2716
|
* writeFile('message.txt', data, (err) => {
|
|
@@ -2701,7 +2722,7 @@ declare module 'fs' {
|
|
|
2701
2722
|
* If `options` is a string, then it specifies the encoding:
|
|
2702
2723
|
*
|
|
2703
2724
|
* ```js
|
|
2704
|
-
* import { writeFile } from 'fs';
|
|
2725
|
+
* import { writeFile } from 'node:fs';
|
|
2705
2726
|
*
|
|
2706
2727
|
* writeFile('message.txt', 'Hello Node.js', 'utf8', callback);
|
|
2707
2728
|
* ```
|
|
@@ -2719,8 +2740,8 @@ declare module 'fs' {
|
|
|
2719
2740
|
* to be written.
|
|
2720
2741
|
*
|
|
2721
2742
|
* ```js
|
|
2722
|
-
* import { writeFile } from 'fs';
|
|
2723
|
-
* import { Buffer } from 'buffer';
|
|
2743
|
+
* import { writeFile } from 'node:fs';
|
|
2744
|
+
* import { Buffer } from 'node:buffer';
|
|
2724
2745
|
*
|
|
2725
2746
|
* const controller = new AbortController();
|
|
2726
2747
|
* const { signal } = controller;
|
|
@@ -2778,7 +2799,7 @@ declare module 'fs' {
|
|
|
2778
2799
|
* The `mode` option only affects the newly created file. See {@link open} for more details.
|
|
2779
2800
|
*
|
|
2780
2801
|
* ```js
|
|
2781
|
-
* import { appendFile } from 'fs';
|
|
2802
|
+
* import { appendFile } from 'node:fs';
|
|
2782
2803
|
*
|
|
2783
2804
|
* appendFile('message.txt', 'data to append', (err) => {
|
|
2784
2805
|
* if (err) throw err;
|
|
@@ -2789,7 +2810,7 @@ declare module 'fs' {
|
|
|
2789
2810
|
* If `options` is a string, then it specifies the encoding:
|
|
2790
2811
|
*
|
|
2791
2812
|
* ```js
|
|
2792
|
-
* import { appendFile } from 'fs';
|
|
2813
|
+
* import { appendFile } from 'node:fs';
|
|
2793
2814
|
*
|
|
2794
2815
|
* appendFile('message.txt', 'data to append', 'utf8', callback);
|
|
2795
2816
|
* ```
|
|
@@ -2799,7 +2820,7 @@ declare module 'fs' {
|
|
|
2799
2820
|
* not be closed automatically.
|
|
2800
2821
|
*
|
|
2801
2822
|
* ```js
|
|
2802
|
-
* import { open, close, appendFile } from 'fs';
|
|
2823
|
+
* import { open, close, appendFile } from 'node:fs';
|
|
2803
2824
|
*
|
|
2804
2825
|
* function closeFd(fd) {
|
|
2805
2826
|
* close(fd, (err) => {
|
|
@@ -2854,7 +2875,7 @@ declare module 'fs' {
|
|
|
2854
2875
|
* The `mode` option only affects the newly created file. See {@link open} for more details.
|
|
2855
2876
|
*
|
|
2856
2877
|
* ```js
|
|
2857
|
-
* import { appendFileSync } from 'fs';
|
|
2878
|
+
* import { appendFileSync } from 'node:fs';
|
|
2858
2879
|
*
|
|
2859
2880
|
* try {
|
|
2860
2881
|
* appendFileSync('message.txt', 'data to append');
|
|
@@ -2867,7 +2888,7 @@ declare module 'fs' {
|
|
|
2867
2888
|
* If `options` is a string, then it specifies the encoding:
|
|
2868
2889
|
*
|
|
2869
2890
|
* ```js
|
|
2870
|
-
* import { appendFileSync } from 'fs';
|
|
2891
|
+
* import { appendFileSync } from 'node:fs';
|
|
2871
2892
|
*
|
|
2872
2893
|
* appendFileSync('message.txt', 'data to append', 'utf8');
|
|
2873
2894
|
* ```
|
|
@@ -2877,7 +2898,7 @@ declare module 'fs' {
|
|
|
2877
2898
|
* not be closed automatically.
|
|
2878
2899
|
*
|
|
2879
2900
|
* ```js
|
|
2880
|
-
* import { openSync, closeSync, appendFileSync } from 'fs';
|
|
2901
|
+
* import { openSync, closeSync, appendFileSync } from 'node:fs';
|
|
2881
2902
|
*
|
|
2882
2903
|
* let fd;
|
|
2883
2904
|
*
|
|
@@ -2959,7 +2980,7 @@ declare module 'fs' {
|
|
|
2959
2980
|
* stat object:
|
|
2960
2981
|
*
|
|
2961
2982
|
* ```js
|
|
2962
|
-
* import { watchFile } from 'fs';
|
|
2983
|
+
* import { watchFile } from 'node:fs';
|
|
2963
2984
|
*
|
|
2964
2985
|
* watchFile('message.text', (curr, prev) => {
|
|
2965
2986
|
* console.log(`the current mtime is: ${curr.mtime}`);
|
|
@@ -3092,7 +3113,7 @@ declare module 'fs' {
|
|
|
3092
3113
|
* Then call the `callback` argument with either true or false:
|
|
3093
3114
|
*
|
|
3094
3115
|
* ```js
|
|
3095
|
-
* import { exists } from 'fs';
|
|
3116
|
+
* import { exists } from 'node:fs';
|
|
3096
3117
|
*
|
|
3097
3118
|
* exists('/etc/passwd', (e) => {
|
|
3098
3119
|
* console.log(e ? 'it exists' : 'no passwd!');
|
|
@@ -3104,7 +3125,7 @@ declare module 'fs' {
|
|
|
3104
3125
|
* has only one boolean parameter. This is one reason `fs.access()` is recommended
|
|
3105
3126
|
* instead of `fs.exists()`.
|
|
3106
3127
|
*
|
|
3107
|
-
* Using `fs.exists()` to check for the existence of a file before calling`fs.open()`, `fs.readFile()
|
|
3128
|
+
* Using `fs.exists()` to check for the existence of a file before calling`fs.open()`, `fs.readFile()`, or `fs.writeFile()` is not recommended. Doing
|
|
3108
3129
|
* so introduces a race condition, since other processes may change the file's
|
|
3109
3130
|
* state between the two calls. Instead, user code should open/read/write the
|
|
3110
3131
|
* file directly and handle the error raised if the file does not exist.
|
|
@@ -3112,7 +3133,7 @@ declare module 'fs' {
|
|
|
3112
3133
|
* **write (NOT RECOMMENDED)**
|
|
3113
3134
|
*
|
|
3114
3135
|
* ```js
|
|
3115
|
-
* import { exists, open, close } from 'fs';
|
|
3136
|
+
* import { exists, open, close } from 'node:fs';
|
|
3116
3137
|
*
|
|
3117
3138
|
* exists('myfile', (e) => {
|
|
3118
3139
|
* if (e) {
|
|
@@ -3136,7 +3157,7 @@ declare module 'fs' {
|
|
|
3136
3157
|
* **write (RECOMMENDED)**
|
|
3137
3158
|
*
|
|
3138
3159
|
* ```js
|
|
3139
|
-
* import { open, close } from 'fs';
|
|
3160
|
+
* import { open, close } from 'node:fs';
|
|
3140
3161
|
* open('myfile', 'wx', (err, fd) => {
|
|
3141
3162
|
* if (err) {
|
|
3142
3163
|
* if (err.code === 'EEXIST') {
|
|
@@ -3160,7 +3181,7 @@ declare module 'fs' {
|
|
|
3160
3181
|
* **read (NOT RECOMMENDED)**
|
|
3161
3182
|
*
|
|
3162
3183
|
* ```js
|
|
3163
|
-
* import { open, close, exists } from 'fs';
|
|
3184
|
+
* import { open, close, exists } from 'node:fs';
|
|
3164
3185
|
*
|
|
3165
3186
|
* exists('myfile', (e) => {
|
|
3166
3187
|
* if (e) {
|
|
@@ -3184,7 +3205,7 @@ declare module 'fs' {
|
|
|
3184
3205
|
* **read (RECOMMENDED)**
|
|
3185
3206
|
*
|
|
3186
3207
|
* ```js
|
|
3187
|
-
* import { open, close } from 'fs';
|
|
3208
|
+
* import { open, close } from 'node:fs';
|
|
3188
3209
|
*
|
|
3189
3210
|
* open('myfile', 'r', (err, fd) => {
|
|
3190
3211
|
* if (err) {
|
|
@@ -3210,7 +3231,7 @@ declare module 'fs' {
|
|
|
3210
3231
|
* file; the "recommended" examples are better because they use the file directly
|
|
3211
3232
|
* and handle the error, if any.
|
|
3212
3233
|
*
|
|
3213
|
-
* In general, check for the existence of a file only if the file won
|
|
3234
|
+
* In general, check for the existence of a file only if the file won't be
|
|
3214
3235
|
* used directly, for example when its existence is a signal from another
|
|
3215
3236
|
* process.
|
|
3216
3237
|
* @since v0.0.2
|
|
@@ -3235,7 +3256,7 @@ declare module 'fs' {
|
|
|
3235
3256
|
* Node.js callbacks. `fs.existsSync()` does not use a callback.
|
|
3236
3257
|
*
|
|
3237
3258
|
* ```js
|
|
3238
|
-
* import { existsSync } from 'fs';
|
|
3259
|
+
* import { existsSync } from 'node:fs';
|
|
3239
3260
|
*
|
|
3240
3261
|
* if (existsSync('/etc/passwd'))
|
|
3241
3262
|
* console.log('The path exists.');
|
|
@@ -3369,7 +3390,7 @@ declare module 'fs' {
|
|
|
3369
3390
|
* argument will be an `Error` object. The following examples check if`package.json` exists, and if it is readable or writable.
|
|
3370
3391
|
*
|
|
3371
3392
|
* ```js
|
|
3372
|
-
* import { access, constants } from 'fs';
|
|
3393
|
+
* import { access, constants } from 'node:fs';
|
|
3373
3394
|
*
|
|
3374
3395
|
* const file = 'package.json';
|
|
3375
3396
|
*
|
|
@@ -3394,7 +3415,7 @@ declare module 'fs' {
|
|
|
3394
3415
|
* });
|
|
3395
3416
|
* ```
|
|
3396
3417
|
*
|
|
3397
|
-
* Do not use `fs.access()` to check for the accessibility of a file before calling`fs.open()`, `fs.readFile()
|
|
3418
|
+
* Do not use `fs.access()` to check for the accessibility of a file before calling`fs.open()`, `fs.readFile()`, or `fs.writeFile()`. Doing
|
|
3398
3419
|
* so introduces a race condition, since other processes may change the file's
|
|
3399
3420
|
* state between the two calls. Instead, user code should open/read/write the
|
|
3400
3421
|
* file directly and handle the error raised if the file is not accessible.
|
|
@@ -3402,7 +3423,7 @@ declare module 'fs' {
|
|
|
3402
3423
|
* **write (NOT RECOMMENDED)**
|
|
3403
3424
|
*
|
|
3404
3425
|
* ```js
|
|
3405
|
-
* import { access, open, close } from 'fs';
|
|
3426
|
+
* import { access, open, close } from 'node:fs';
|
|
3406
3427
|
*
|
|
3407
3428
|
* access('myfile', (err) => {
|
|
3408
3429
|
* if (!err) {
|
|
@@ -3427,7 +3448,7 @@ declare module 'fs' {
|
|
|
3427
3448
|
* **write (RECOMMENDED)**
|
|
3428
3449
|
*
|
|
3429
3450
|
* ```js
|
|
3430
|
-
* import { open, close } from 'fs';
|
|
3451
|
+
* import { open, close } from 'node:fs';
|
|
3431
3452
|
*
|
|
3432
3453
|
* open('myfile', 'wx', (err, fd) => {
|
|
3433
3454
|
* if (err) {
|
|
@@ -3452,7 +3473,7 @@ declare module 'fs' {
|
|
|
3452
3473
|
* **read (NOT RECOMMENDED)**
|
|
3453
3474
|
*
|
|
3454
3475
|
* ```js
|
|
3455
|
-
* import { access, open, close } from 'fs';
|
|
3476
|
+
* import { access, open, close } from 'node:fs';
|
|
3456
3477
|
* access('myfile', (err) => {
|
|
3457
3478
|
* if (err) {
|
|
3458
3479
|
* if (err.code === 'ENOENT') {
|
|
@@ -3480,7 +3501,7 @@ declare module 'fs' {
|
|
|
3480
3501
|
* **read (RECOMMENDED)**
|
|
3481
3502
|
*
|
|
3482
3503
|
* ```js
|
|
3483
|
-
* import { open, close } from 'fs';
|
|
3504
|
+
* import { open, close } from 'node:fs';
|
|
3484
3505
|
*
|
|
3485
3506
|
* open('myfile', 'r', (err, fd) => {
|
|
3486
3507
|
* if (err) {
|
|
@@ -3542,7 +3563,7 @@ declare module 'fs' {
|
|
|
3542
3563
|
* the method will return `undefined`.
|
|
3543
3564
|
*
|
|
3544
3565
|
* ```js
|
|
3545
|
-
* import { accessSync, constants } from 'fs';
|
|
3566
|
+
* import { accessSync, constants } from 'node:fs';
|
|
3546
3567
|
*
|
|
3547
3568
|
* try {
|
|
3548
3569
|
* accessSync('etc/passwd', constants.R_OK | constants.W_OK);
|
|
@@ -3572,8 +3593,8 @@ declare module 'fs' {
|
|
|
3572
3593
|
end?: number | undefined;
|
|
3573
3594
|
}
|
|
3574
3595
|
/**
|
|
3575
|
-
* Unlike the 16
|
|
3576
|
-
* returned by this method has a default `highWaterMark` of 64
|
|
3596
|
+
* Unlike the 16 KiB default `highWaterMark` for a `stream.Readable`, the stream
|
|
3597
|
+
* returned by this method has a default `highWaterMark` of 64 KiB.
|
|
3577
3598
|
*
|
|
3578
3599
|
* `options` can include `start` and `end` values to read a range of bytes from
|
|
3579
3600
|
* the file instead of the entire file. Both `start` and `end` are inclusive and
|
|
@@ -3599,7 +3620,7 @@ declare module 'fs' {
|
|
|
3599
3620
|
* also required.
|
|
3600
3621
|
*
|
|
3601
3622
|
* ```js
|
|
3602
|
-
* import { createReadStream } from 'fs';
|
|
3623
|
+
* import { createReadStream } from 'node:fs';
|
|
3603
3624
|
*
|
|
3604
3625
|
* // Create a stream from some character device.
|
|
3605
3626
|
* const stream = createReadStream('/dev/input/event0');
|
|
@@ -3627,7 +3648,7 @@ declare module 'fs' {
|
|
|
3627
3648
|
* An example to read the last 10 bytes of a file which is 100 bytes long:
|
|
3628
3649
|
*
|
|
3629
3650
|
* ```js
|
|
3630
|
-
* import { createReadStream } from 'fs';
|
|
3651
|
+
* import { createReadStream } from 'node:fs';
|
|
3631
3652
|
*
|
|
3632
3653
|
* createReadStream('sample.txt', { start: 90, end: 99 });
|
|
3633
3654
|
* ```
|
|
@@ -3651,7 +3672,7 @@ declare module 'fs' {
|
|
|
3651
3672
|
* By default, the stream will emit a `'close'` event after it has been
|
|
3652
3673
|
* destroyed. Set the `emitClose` option to `false` to change this behavior.
|
|
3653
3674
|
*
|
|
3654
|
-
* By providing the `fs` option it is possible to override the corresponding `fs`implementations for `open`, `write`, `writev
|
|
3675
|
+
* 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
|
|
3655
3676
|
* performance as some optimizations (`_writev()`)
|
|
3656
3677
|
* 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
|
|
3657
3678
|
* for `open` is also required. If `autoClose` is `true`, an override for `close`is also required.
|
|
@@ -3706,7 +3727,7 @@ declare module 'fs' {
|
|
|
3706
3727
|
* copy-on-write, then the operation will fail.
|
|
3707
3728
|
*
|
|
3708
3729
|
* ```js
|
|
3709
|
-
* import { copyFile, constants } from 'fs';
|
|
3730
|
+
* import { copyFile, constants } from 'node:fs';
|
|
3710
3731
|
*
|
|
3711
3732
|
* function callback(err) {
|
|
3712
3733
|
* if (err) throw err;
|
|
@@ -3749,7 +3770,7 @@ declare module 'fs' {
|
|
|
3749
3770
|
* copy-on-write, then the operation will fail.
|
|
3750
3771
|
*
|
|
3751
3772
|
* ```js
|
|
3752
|
-
* import { copyFileSync, constants } from 'fs';
|
|
3773
|
+
* import { copyFileSync, constants } from 'node:fs';
|
|
3753
3774
|
*
|
|
3754
3775
|
* // destination.txt will be created or overwritten by default.
|
|
3755
3776
|
* copyFileSync('source.txt', 'destination.txt');
|
|
@@ -3782,6 +3803,7 @@ declare module 'fs' {
|
|
|
3782
3803
|
* The kernel ignores the position argument and always appends the data to
|
|
3783
3804
|
* the end of the file.
|
|
3784
3805
|
* @since v12.9.0
|
|
3806
|
+
* @param [position='null']
|
|
3785
3807
|
*/
|
|
3786
3808
|
export function writev(fd: number, buffers: ReadonlyArray<NodeJS.ArrayBufferView>, cb: (err: NodeJS.ErrnoException | null, bytesWritten: number, buffers: NodeJS.ArrayBufferView[]) => void): void;
|
|
3787
3809
|
export function writev(
|
|
@@ -3801,6 +3823,7 @@ declare module 'fs' {
|
|
|
3801
3823
|
* For detailed information, see the documentation of the asynchronous version of
|
|
3802
3824
|
* this API: {@link writev}.
|
|
3803
3825
|
* @since v12.9.0
|
|
3826
|
+
* @param [position='null']
|
|
3804
3827
|
* @return The number of bytes written.
|
|
3805
3828
|
*/
|
|
3806
3829
|
export function writevSync(fd: number, buffers: ReadonlyArray<NodeJS.ArrayBufferView>, position?: number): number;
|
|
@@ -3817,6 +3840,7 @@ declare module 'fs' {
|
|
|
3817
3840
|
* If this method is invoked as its `util.promisify()` ed version, it returns
|
|
3818
3841
|
* a promise for an `Object` with `bytesRead` and `buffers` properties.
|
|
3819
3842
|
* @since v13.13.0, v12.17.0
|
|
3843
|
+
* @param [position='null']
|
|
3820
3844
|
*/
|
|
3821
3845
|
export function readv(fd: number, buffers: ReadonlyArray<NodeJS.ArrayBufferView>, cb: (err: NodeJS.ErrnoException | null, bytesRead: number, buffers: NodeJS.ArrayBufferView[]) => void): void;
|
|
3822
3846
|
export function readv(
|
|
@@ -3836,10 +3860,14 @@ declare module 'fs' {
|
|
|
3836
3860
|
* For detailed information, see the documentation of the asynchronous version of
|
|
3837
3861
|
* this API: {@link readv}.
|
|
3838
3862
|
* @since v13.13.0, v12.17.0
|
|
3863
|
+
* @param [position='null']
|
|
3839
3864
|
* @return The number of bytes read.
|
|
3840
3865
|
*/
|
|
3841
3866
|
export function readvSync(fd: number, buffers: ReadonlyArray<NodeJS.ArrayBufferView>, position?: number): number;
|
|
3842
3867
|
export interface OpenDirOptions {
|
|
3868
|
+
/**
|
|
3869
|
+
* @default 'utf8'
|
|
3870
|
+
*/
|
|
3843
3871
|
encoding?: BufferEncoding | undefined;
|
|
3844
3872
|
/**
|
|
3845
3873
|
* Number of directory entries that are buffered
|
|
@@ -3848,6 +3876,10 @@ declare module 'fs' {
|
|
|
3848
3876
|
* @default 32
|
|
3849
3877
|
*/
|
|
3850
3878
|
bufferSize?: number | undefined;
|
|
3879
|
+
/**
|
|
3880
|
+
* @default false
|
|
3881
|
+
*/
|
|
3882
|
+
recursive?: boolean;
|
|
3851
3883
|
}
|
|
3852
3884
|
/**
|
|
3853
3885
|
* Synchronously open a directory. See [`opendir(3)`](http://man7.org/linux/man-pages/man3/opendir.3.html).
|
|
@@ -3910,6 +3942,10 @@ declare module 'fs' {
|
|
|
3910
3942
|
* @default true
|
|
3911
3943
|
*/
|
|
3912
3944
|
force?: boolean;
|
|
3945
|
+
/**
|
|
3946
|
+
* Modifiers for copy operation. See `mode` flag of {@link copyFileSync()}
|
|
3947
|
+
*/
|
|
3948
|
+
mode?: number;
|
|
3913
3949
|
/**
|
|
3914
3950
|
* When `true` timestamps from `src` will
|
|
3915
3951
|
* be preserved.
|