@types/node 18.16.3 → 20.0.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/README.md +1 -1
- node/assert.d.ts +68 -73
- node/async_hooks.d.ts +62 -42
- node/buffer.d.ts +123 -95
- node/child_process.d.ts +50 -54
- node/cluster.d.ts +12 -12
- node/console.d.ts +5 -5
- node/crypto.d.ts +209 -220
- node/dgram.d.ts +15 -15
- node/diagnostics_channel.d.ts +25 -26
- node/dns/promises.d.ts +6 -6
- node/dns.d.ts +16 -16
- node/domain.d.ts +3 -3
- node/events.d.ts +60 -60
- node/fs/promises.d.ts +74 -48
- node/fs.d.ts +91 -81
- node/http.d.ts +147 -144
- node/http2.d.ts +42 -46
- node/https.d.ts +52 -153
- node/index.d.ts +1 -1
- node/inspector.d.ts +10 -3
- node/module.d.ts +5 -4
- node/net.d.ts +21 -18
- node/os.d.ts +22 -18
- node/package.json +2 -2
- node/path.d.ts +4 -4
- node/perf_hooks.d.ts +28 -15
- node/process.d.ts +43 -46
- node/punycode.d.ts +1 -1
- node/querystring.d.ts +5 -5
- node/readline/promises.d.ts +6 -4
- node/readline.d.ts +15 -15
- node/repl.d.ts +9 -9
- node/stream/consumers.d.ts +1 -1
- node/stream.d.ts +74 -136
- node/string_decoder.d.ts +6 -6
- node/test.d.ts +0 -76
- node/timers/promises.d.ts +3 -3
- node/timers.d.ts +2 -2
- node/tls.d.ts +22 -15
- node/trace_events.d.ts +20 -9
- node/ts4.8/assert.d.ts +68 -73
- node/ts4.8/async_hooks.d.ts +59 -31
- node/ts4.8/buffer.d.ts +123 -95
- node/ts4.8/child_process.d.ts +50 -54
- node/ts4.8/cluster.d.ts +12 -12
- node/ts4.8/console.d.ts +5 -5
- node/ts4.8/crypto.d.ts +209 -220
- node/ts4.8/dgram.d.ts +15 -15
- node/ts4.8/diagnostics_channel.d.ts +25 -26
- node/ts4.8/dns/promises.d.ts +6 -6
- node/ts4.8/dns.d.ts +16 -16
- node/ts4.8/domain.d.ts +3 -3
- node/ts4.8/events.d.ts +60 -60
- node/ts4.8/fs/promises.d.ts +72 -45
- node/ts4.8/fs.d.ts +81 -67
- node/ts4.8/http.d.ts +133 -126
- node/ts4.8/http2.d.ts +42 -46
- node/ts4.8/https.d.ts +52 -153
- node/ts4.8/inspector.d.ts +10 -3
- node/ts4.8/module.d.ts +5 -4
- node/ts4.8/net.d.ts +21 -18
- node/ts4.8/os.d.ts +22 -18
- node/ts4.8/path.d.ts +4 -4
- node/ts4.8/perf_hooks.d.ts +28 -15
- node/ts4.8/process.d.ts +43 -46
- node/ts4.8/punycode.d.ts +1 -1
- node/ts4.8/querystring.d.ts +5 -5
- node/ts4.8/readline/promises.d.ts +6 -4
- node/ts4.8/readline.d.ts +15 -15
- node/ts4.8/repl.d.ts +9 -9
- node/ts4.8/stream/consumers.d.ts +1 -1
- node/ts4.8/stream.d.ts +77 -139
- node/ts4.8/string_decoder.d.ts +6 -6
- node/ts4.8/test.d.ts +0 -75
- node/ts4.8/timers/promises.d.ts +3 -3
- node/ts4.8/timers.d.ts +2 -2
- node/ts4.8/tls.d.ts +22 -15
- node/ts4.8/trace_events.d.ts +20 -9
- node/ts4.8/tty.d.ts +4 -5
- node/ts4.8/url.d.ts +26 -36
- node/ts4.8/util.d.ts +143 -116
- node/ts4.8/v8.d.ts +107 -16
- node/ts4.8/vm.d.ts +292 -42
- node/ts4.8/wasi.d.ts +8 -14
- node/ts4.8/worker_threads.d.ts +32 -34
- node/ts4.8/zlib.d.ts +11 -11
- node/tty.d.ts +4 -5
- node/url.d.ts +26 -36
- node/util.d.ts +146 -111
- node/v8.d.ts +110 -16
- node/vm.d.ts +292 -42
- node/wasi.d.ts +8 -14
- node/worker_threads.d.ts +32 -34
- node/zlib.d.ts +11 -11
node/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.0.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,7 @@ 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
|
-
* Using `fs.stat()` to check for the existence of a file before calling`fs.open()`, `fs.readFile()
|
|
851
|
+
* Using `fs.stat()` to check for the existence of a file before calling`fs.open()`, `fs.readFile()`, or `fs.writeFile()` is not recommended.
|
|
858
852
|
* Instead, user code should open/read/write the file directly and handle the
|
|
859
853
|
* error raised if the file is not available.
|
|
860
854
|
*
|
|
@@ -871,7 +865,7 @@ declare module 'fs' {
|
|
|
871
865
|
* The next program will check for the stats of the given paths:
|
|
872
866
|
*
|
|
873
867
|
* ```js
|
|
874
|
-
* import { stat } from 'fs';
|
|
868
|
+
* import { stat } from 'node:fs';
|
|
875
869
|
*
|
|
876
870
|
* const pathsToCheck = ['./txtDir', './txtDir/file.txt'];
|
|
877
871
|
*
|
|
@@ -1118,10 +1112,12 @@ declare module 'fs' {
|
|
|
1118
1112
|
function __promisify__(path: PathLike, options?: StatOptions): Promise<Stats | BigIntStats>;
|
|
1119
1113
|
}
|
|
1120
1114
|
/**
|
|
1121
|
-
* Asynchronous statfs(2). Returns information about the mounted file system which
|
|
1122
|
-
*
|
|
1115
|
+
* Asynchronous [`statfs(2)`](http://man7.org/linux/man-pages/man2/statfs.2.html). Returns information about the mounted file system which
|
|
1116
|
+
* contains `path`. The callback gets two arguments `(err, stats)` where `stats`is an `fs.StatFs` object.
|
|
1117
|
+
*
|
|
1118
|
+
* In case of an error, the `err.code` will be one of `Common System Errors`.
|
|
1119
|
+
* @since v19.6.0, v18.15.0
|
|
1123
1120
|
* @param path A path to an existing file or directory on the file system to be queried.
|
|
1124
|
-
* @param callback
|
|
1125
1121
|
*/
|
|
1126
1122
|
export function statfs(path: PathLike, callback: (err: NodeJS.ErrnoException | null, stats: StatsFs) => void): void;
|
|
1127
1123
|
export function statfs(
|
|
@@ -1160,12 +1156,13 @@ declare module 'fs' {
|
|
|
1160
1156
|
): Promise<BigIntStatsFs>;
|
|
1161
1157
|
function __promisify__(path: PathLike, options?: StatFsOptions): Promise<StatsFs | BigIntStatsFs>;
|
|
1162
1158
|
}
|
|
1163
|
-
|
|
1164
1159
|
/**
|
|
1165
|
-
* Synchronous statfs(2). Returns information about the mounted file system which
|
|
1166
|
-
*
|
|
1160
|
+
* Synchronous [`statfs(2)`](http://man7.org/linux/man-pages/man2/statfs.2.html). Returns information about the mounted file system which
|
|
1161
|
+
* contains `path`.
|
|
1162
|
+
*
|
|
1163
|
+
* In case of an error, the `err.code` will be one of `Common System Errors`.
|
|
1164
|
+
* @since v19.6.0, v18.15.0
|
|
1167
1165
|
* @param path A path to an existing file or directory on the file system to be queried.
|
|
1168
|
-
* @param callback
|
|
1169
1166
|
*/
|
|
1170
1167
|
export function statfsSync(
|
|
1171
1168
|
path: PathLike,
|
|
@@ -1179,7 +1176,6 @@ declare module 'fs' {
|
|
|
1179
1176
|
bigint: true;
|
|
1180
1177
|
}
|
|
1181
1178
|
): BigIntStatsFs;
|
|
1182
|
-
|
|
1183
1179
|
export function statfsSync(path: PathLike, options?: StatFsOptions): StatsFs | BigIntStatsFs;
|
|
1184
1180
|
/**
|
|
1185
1181
|
* Synchronous lstat(2) - Get file status. Does not dereference symbolic links.
|
|
@@ -1214,14 +1210,14 @@ declare module 'fs' {
|
|
|
1214
1210
|
*
|
|
1215
1211
|
* The `type` argument is only available on Windows and ignored on other platforms.
|
|
1216
1212
|
* 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
|
|
1213
|
+
* not a string, Node.js will autodetect `target` type and use `'file'` or `'dir'`.
|
|
1214
|
+
* If the `target` does not exist, `'file'` will be used. Windows junction points
|
|
1219
1215
|
* require the destination path to be absolute. When using `'junction'`, the`target` argument will automatically be normalized to absolute path.
|
|
1220
1216
|
*
|
|
1221
|
-
* Relative targets are relative to the link
|
|
1217
|
+
* Relative targets are relative to the link's parent directory.
|
|
1222
1218
|
*
|
|
1223
1219
|
* ```js
|
|
1224
|
-
* import { symlink } from 'fs';
|
|
1220
|
+
* import { symlink } from 'node:fs';
|
|
1225
1221
|
*
|
|
1226
1222
|
* symlink('./mew', './mewtwo', callback);
|
|
1227
1223
|
* ```
|
|
@@ -1236,6 +1232,7 @@ declare module 'fs' {
|
|
|
1236
1232
|
* └── mewtwo -> ./mew
|
|
1237
1233
|
* ```
|
|
1238
1234
|
* @since v0.1.31
|
|
1235
|
+
* @param [type='null']
|
|
1239
1236
|
*/
|
|
1240
1237
|
export function symlink(target: PathLike, path: PathLike, type: symlink.Type | undefined | null, callback: NoParamCallback): void;
|
|
1241
1238
|
/**
|
|
@@ -1261,6 +1258,7 @@ declare module 'fs' {
|
|
|
1261
1258
|
* For detailed information, see the documentation of the asynchronous version of
|
|
1262
1259
|
* this API: {@link symlink}.
|
|
1263
1260
|
* @since v0.1.31
|
|
1261
|
+
* @param [type='null']
|
|
1264
1262
|
*/
|
|
1265
1263
|
export function symlinkSync(target: PathLike, path: PathLike, type?: symlink.Type | null): void;
|
|
1266
1264
|
/**
|
|
@@ -1338,7 +1336,7 @@ declare module 'fs' {
|
|
|
1338
1336
|
*/
|
|
1339
1337
|
export function readlinkSync(path: PathLike, options?: EncodingOption): string | Buffer;
|
|
1340
1338
|
/**
|
|
1341
|
-
* Asynchronously computes the canonical pathname by resolving `.`,
|
|
1339
|
+
* Asynchronously computes the canonical pathname by resolving `.`, `..`, and
|
|
1342
1340
|
* symbolic links.
|
|
1343
1341
|
*
|
|
1344
1342
|
* A canonical pathname is not necessarily unique. Hard links and bind mounts can
|
|
@@ -1452,7 +1450,7 @@ declare module 'fs' {
|
|
|
1452
1450
|
* possible exception are given to the completion callback.
|
|
1453
1451
|
*
|
|
1454
1452
|
* ```js
|
|
1455
|
-
* import { unlink } from 'fs';
|
|
1453
|
+
* import { unlink } from 'node:fs';
|
|
1456
1454
|
* // Assuming that 'path/file.txt' is a regular file.
|
|
1457
1455
|
* unlink('path/file.txt', (err) => {
|
|
1458
1456
|
* if (err) throw err;
|
|
@@ -1607,7 +1605,7 @@ declare module 'fs' {
|
|
|
1607
1605
|
* when `recursive` is false.
|
|
1608
1606
|
*
|
|
1609
1607
|
* ```js
|
|
1610
|
-
* import { mkdir } from 'fs';
|
|
1608
|
+
* import { mkdir } from 'node:fs';
|
|
1611
1609
|
*
|
|
1612
1610
|
* // Creates /tmp/a/apple, regardless of whether `/tmp` and /tmp/a exist.
|
|
1613
1611
|
* mkdir('/tmp/a/apple', { recursive: true }, (err) => {
|
|
@@ -1619,7 +1617,7 @@ declare module 'fs' {
|
|
|
1619
1617
|
* result in an error:
|
|
1620
1618
|
*
|
|
1621
1619
|
* ```js
|
|
1622
|
-
* import { mkdir } from 'fs';
|
|
1620
|
+
* import { mkdir } from 'node:fs';
|
|
1623
1621
|
*
|
|
1624
1622
|
* mkdir('/', { recursive: true }, (err) => {
|
|
1625
1623
|
* // => [Error: EPERM: operation not permitted, mkdir 'C:\']
|
|
@@ -1751,9 +1749,11 @@ declare module 'fs' {
|
|
|
1751
1749
|
* object with an `encoding` property specifying the character encoding to use.
|
|
1752
1750
|
*
|
|
1753
1751
|
* ```js
|
|
1754
|
-
* import { mkdtemp } from 'fs';
|
|
1752
|
+
* import { mkdtemp } from 'node:fs';
|
|
1753
|
+
* import { join } from 'node:path';
|
|
1754
|
+
* import { tmpdir } from 'node:os';
|
|
1755
1755
|
*
|
|
1756
|
-
* mkdtemp(
|
|
1756
|
+
* mkdtemp(join(tmpdir(), 'foo-'), (err, directory) => {
|
|
1757
1757
|
* if (err) throw err;
|
|
1758
1758
|
* console.log(directory);
|
|
1759
1759
|
* // Prints: /tmp/foo-itXde2 or C:\Users\...\AppData\Local\Temp\foo-itXde2
|
|
@@ -1763,11 +1763,11 @@ declare module 'fs' {
|
|
|
1763
1763
|
* The `fs.mkdtemp()` method will append the six randomly selected characters
|
|
1764
1764
|
* directly to the `prefix` string. For instance, given a directory `/tmp`, if the
|
|
1765
1765
|
* intention is to create a temporary directory _within_`/tmp`, the `prefix`must end with a trailing platform-specific path separator
|
|
1766
|
-
* (`require('path').sep`).
|
|
1766
|
+
* (`require('node:path').sep`).
|
|
1767
1767
|
*
|
|
1768
1768
|
* ```js
|
|
1769
|
-
* import { tmpdir } from 'os';
|
|
1770
|
-
* import { mkdtemp } from 'fs';
|
|
1769
|
+
* import { tmpdir } from 'node:os';
|
|
1770
|
+
* import { mkdtemp } from 'node:fs';
|
|
1771
1771
|
*
|
|
1772
1772
|
* // The parent directory for the new temporary directory
|
|
1773
1773
|
* const tmpDir = tmpdir();
|
|
@@ -1782,7 +1782,7 @@ declare module 'fs' {
|
|
|
1782
1782
|
* });
|
|
1783
1783
|
*
|
|
1784
1784
|
* // This method is *CORRECT*:
|
|
1785
|
-
* import { sep } from 'path';
|
|
1785
|
+
* import { sep } from 'node:path';
|
|
1786
1786
|
* mkdtemp(`${tmpDir}${sep}`, (err, directory) => {
|
|
1787
1787
|
* if (err) throw err;
|
|
1788
1788
|
* console.log(directory);
|
|
@@ -2110,7 +2110,6 @@ declare module 'fs' {
|
|
|
2110
2110
|
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
2111
2111
|
*/
|
|
2112
2112
|
export function open(path: PathLike, callback: (err: NodeJS.ErrnoException | null, fd: number) => void): void;
|
|
2113
|
-
|
|
2114
2113
|
export namespace open {
|
|
2115
2114
|
/**
|
|
2116
2115
|
* Asynchronous open(2) - open and possibly create a file.
|
|
@@ -2135,7 +2134,7 @@ declare module 'fs' {
|
|
|
2135
2134
|
* The `atime` and `mtime` arguments follow these rules:
|
|
2136
2135
|
*
|
|
2137
2136
|
* * 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
|
|
2137
|
+
* * If the value can not be converted to a number, or is `NaN`, `Infinity`, or`-Infinity`, an `Error` will be thrown.
|
|
2139
2138
|
* @since v0.4.2
|
|
2140
2139
|
*/
|
|
2141
2140
|
export function utimes(path: PathLike, atime: TimeLike, mtime: TimeLike, callback: NoParamCallback): void;
|
|
@@ -2221,6 +2220,9 @@ declare module 'fs' {
|
|
|
2221
2220
|
* The kernel ignores the position argument and always appends the data to
|
|
2222
2221
|
* the end of the file.
|
|
2223
2222
|
* @since v0.0.2
|
|
2223
|
+
* @param [offset=0]
|
|
2224
|
+
* @param [length=buffer.byteLength - offset]
|
|
2225
|
+
* @param [position='null']
|
|
2224
2226
|
*/
|
|
2225
2227
|
export function write<TBuffer extends NodeJS.ArrayBufferView>(
|
|
2226
2228
|
fd: number,
|
|
@@ -2325,6 +2327,9 @@ declare module 'fs' {
|
|
|
2325
2327
|
* For detailed information, see the documentation of the asynchronous version of
|
|
2326
2328
|
* this API: {@link write}.
|
|
2327
2329
|
* @since v0.1.21
|
|
2330
|
+
* @param [offset=0]
|
|
2331
|
+
* @param [length=buffer.byteLength - offset]
|
|
2332
|
+
* @param [position='null']
|
|
2328
2333
|
* @return The number of bytes written.
|
|
2329
2334
|
*/
|
|
2330
2335
|
export function writeSync(fd: number, buffer: NodeJS.ArrayBufferView, offset?: number | null, length?: number | null, position?: number | null): number;
|
|
@@ -2430,6 +2435,7 @@ declare module 'fs' {
|
|
|
2430
2435
|
* For detailed information, see the documentation of the asynchronous version of
|
|
2431
2436
|
* this API: {@link read}.
|
|
2432
2437
|
* @since v0.1.21
|
|
2438
|
+
* @param [position='null']
|
|
2433
2439
|
*/
|
|
2434
2440
|
export function readSync(fd: number, buffer: NodeJS.ArrayBufferView, offset: number, length: number, position: ReadPosition | null): number;
|
|
2435
2441
|
/**
|
|
@@ -2441,7 +2447,7 @@ declare module 'fs' {
|
|
|
2441
2447
|
* Asynchronously reads the entire contents of a file.
|
|
2442
2448
|
*
|
|
2443
2449
|
* ```js
|
|
2444
|
-
* import { readFile } from 'fs';
|
|
2450
|
+
* import { readFile } from 'node:fs';
|
|
2445
2451
|
*
|
|
2446
2452
|
* readFile('/etc/passwd', (err, data) => {
|
|
2447
2453
|
* if (err) throw err;
|
|
@@ -2457,7 +2463,7 @@ declare module 'fs' {
|
|
|
2457
2463
|
* If `options` is a string, then it specifies the encoding:
|
|
2458
2464
|
*
|
|
2459
2465
|
* ```js
|
|
2460
|
-
* import { readFile } from 'fs';
|
|
2466
|
+
* import { readFile } from 'node:fs';
|
|
2461
2467
|
*
|
|
2462
2468
|
* readFile('/etc/passwd', 'utf8', callback);
|
|
2463
2469
|
* ```
|
|
@@ -2467,7 +2473,7 @@ declare module 'fs' {
|
|
|
2467
2473
|
* will be returned.
|
|
2468
2474
|
*
|
|
2469
2475
|
* ```js
|
|
2470
|
-
* import { readFile } from 'fs';
|
|
2476
|
+
* import { readFile } from 'node:fs';
|
|
2471
2477
|
*
|
|
2472
2478
|
* // macOS, Linux, and Windows
|
|
2473
2479
|
* readFile('<directory>', (err, data) => {
|
|
@@ -2484,7 +2490,7 @@ declare module 'fs' {
|
|
|
2484
2490
|
* request is aborted the callback is called with an `AbortError`:
|
|
2485
2491
|
*
|
|
2486
2492
|
* ```js
|
|
2487
|
-
* import { readFile } from 'fs';
|
|
2493
|
+
* import { readFile } from 'node:fs';
|
|
2488
2494
|
*
|
|
2489
2495
|
* const controller = new AbortController();
|
|
2490
2496
|
* const signal = controller.signal;
|
|
@@ -2617,7 +2623,7 @@ declare module 'fs' {
|
|
|
2617
2623
|
* Similar to {@link readFile}, when the path is a directory, the behavior of`fs.readFileSync()` is platform-specific.
|
|
2618
2624
|
*
|
|
2619
2625
|
* ```js
|
|
2620
|
-
* import { readFileSync } from 'fs';
|
|
2626
|
+
* import { readFileSync } from 'node:fs';
|
|
2621
2627
|
*
|
|
2622
2628
|
* // macOS, Linux, and Windows
|
|
2623
2629
|
* readFileSync('<directory>');
|
|
@@ -2688,8 +2694,8 @@ declare module 'fs' {
|
|
|
2688
2694
|
* The `mode` option only affects the newly created file. See {@link open} for more details.
|
|
2689
2695
|
*
|
|
2690
2696
|
* ```js
|
|
2691
|
-
* import { writeFile } from 'fs';
|
|
2692
|
-
* import { Buffer } from 'buffer';
|
|
2697
|
+
* import { writeFile } from 'node:fs';
|
|
2698
|
+
* import { Buffer } from 'node:buffer';
|
|
2693
2699
|
*
|
|
2694
2700
|
* const data = new Uint8Array(Buffer.from('Hello Node.js'));
|
|
2695
2701
|
* writeFile('message.txt', data, (err) => {
|
|
@@ -2701,7 +2707,7 @@ declare module 'fs' {
|
|
|
2701
2707
|
* If `options` is a string, then it specifies the encoding:
|
|
2702
2708
|
*
|
|
2703
2709
|
* ```js
|
|
2704
|
-
* import { writeFile } from 'fs';
|
|
2710
|
+
* import { writeFile } from 'node:fs';
|
|
2705
2711
|
*
|
|
2706
2712
|
* writeFile('message.txt', 'Hello Node.js', 'utf8', callback);
|
|
2707
2713
|
* ```
|
|
@@ -2719,8 +2725,8 @@ declare module 'fs' {
|
|
|
2719
2725
|
* to be written.
|
|
2720
2726
|
*
|
|
2721
2727
|
* ```js
|
|
2722
|
-
* import { writeFile } from 'fs';
|
|
2723
|
-
* import { Buffer } from 'buffer';
|
|
2728
|
+
* import { writeFile } from 'node:fs';
|
|
2729
|
+
* import { Buffer } from 'node:buffer';
|
|
2724
2730
|
*
|
|
2725
2731
|
* const controller = new AbortController();
|
|
2726
2732
|
* const { signal } = controller;
|
|
@@ -2778,7 +2784,7 @@ declare module 'fs' {
|
|
|
2778
2784
|
* The `mode` option only affects the newly created file. See {@link open} for more details.
|
|
2779
2785
|
*
|
|
2780
2786
|
* ```js
|
|
2781
|
-
* import { appendFile } from 'fs';
|
|
2787
|
+
* import { appendFile } from 'node:fs';
|
|
2782
2788
|
*
|
|
2783
2789
|
* appendFile('message.txt', 'data to append', (err) => {
|
|
2784
2790
|
* if (err) throw err;
|
|
@@ -2789,7 +2795,7 @@ declare module 'fs' {
|
|
|
2789
2795
|
* If `options` is a string, then it specifies the encoding:
|
|
2790
2796
|
*
|
|
2791
2797
|
* ```js
|
|
2792
|
-
* import { appendFile } from 'fs';
|
|
2798
|
+
* import { appendFile } from 'node:fs';
|
|
2793
2799
|
*
|
|
2794
2800
|
* appendFile('message.txt', 'data to append', 'utf8', callback);
|
|
2795
2801
|
* ```
|
|
@@ -2799,7 +2805,7 @@ declare module 'fs' {
|
|
|
2799
2805
|
* not be closed automatically.
|
|
2800
2806
|
*
|
|
2801
2807
|
* ```js
|
|
2802
|
-
* import { open, close, appendFile } from 'fs';
|
|
2808
|
+
* import { open, close, appendFile } from 'node:fs';
|
|
2803
2809
|
*
|
|
2804
2810
|
* function closeFd(fd) {
|
|
2805
2811
|
* close(fd, (err) => {
|
|
@@ -2854,7 +2860,7 @@ declare module 'fs' {
|
|
|
2854
2860
|
* The `mode` option only affects the newly created file. See {@link open} for more details.
|
|
2855
2861
|
*
|
|
2856
2862
|
* ```js
|
|
2857
|
-
* import { appendFileSync } from 'fs';
|
|
2863
|
+
* import { appendFileSync } from 'node:fs';
|
|
2858
2864
|
*
|
|
2859
2865
|
* try {
|
|
2860
2866
|
* appendFileSync('message.txt', 'data to append');
|
|
@@ -2867,7 +2873,7 @@ declare module 'fs' {
|
|
|
2867
2873
|
* If `options` is a string, then it specifies the encoding:
|
|
2868
2874
|
*
|
|
2869
2875
|
* ```js
|
|
2870
|
-
* import { appendFileSync } from 'fs';
|
|
2876
|
+
* import { appendFileSync } from 'node:fs';
|
|
2871
2877
|
*
|
|
2872
2878
|
* appendFileSync('message.txt', 'data to append', 'utf8');
|
|
2873
2879
|
* ```
|
|
@@ -2877,7 +2883,7 @@ declare module 'fs' {
|
|
|
2877
2883
|
* not be closed automatically.
|
|
2878
2884
|
*
|
|
2879
2885
|
* ```js
|
|
2880
|
-
* import { openSync, closeSync, appendFileSync } from 'fs';
|
|
2886
|
+
* import { openSync, closeSync, appendFileSync } from 'node:fs';
|
|
2881
2887
|
*
|
|
2882
2888
|
* let fd;
|
|
2883
2889
|
*
|
|
@@ -2959,7 +2965,7 @@ declare module 'fs' {
|
|
|
2959
2965
|
* stat object:
|
|
2960
2966
|
*
|
|
2961
2967
|
* ```js
|
|
2962
|
-
* import { watchFile } from 'fs';
|
|
2968
|
+
* import { watchFile } from 'node:fs';
|
|
2963
2969
|
*
|
|
2964
2970
|
* watchFile('message.text', (curr, prev) => {
|
|
2965
2971
|
* console.log(`the current mtime is: ${curr.mtime}`);
|
|
@@ -3092,7 +3098,7 @@ declare module 'fs' {
|
|
|
3092
3098
|
* Then call the `callback` argument with either true or false:
|
|
3093
3099
|
*
|
|
3094
3100
|
* ```js
|
|
3095
|
-
* import { exists } from 'fs';
|
|
3101
|
+
* import { exists } from 'node:fs';
|
|
3096
3102
|
*
|
|
3097
3103
|
* exists('/etc/passwd', (e) => {
|
|
3098
3104
|
* console.log(e ? 'it exists' : 'no passwd!');
|
|
@@ -3104,7 +3110,7 @@ declare module 'fs' {
|
|
|
3104
3110
|
* has only one boolean parameter. This is one reason `fs.access()` is recommended
|
|
3105
3111
|
* instead of `fs.exists()`.
|
|
3106
3112
|
*
|
|
3107
|
-
* Using `fs.exists()` to check for the existence of a file before calling`fs.open()`, `fs.readFile()
|
|
3113
|
+
* 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
3114
|
* so introduces a race condition, since other processes may change the file's
|
|
3109
3115
|
* state between the two calls. Instead, user code should open/read/write the
|
|
3110
3116
|
* file directly and handle the error raised if the file does not exist.
|
|
@@ -3112,7 +3118,7 @@ declare module 'fs' {
|
|
|
3112
3118
|
* **write (NOT RECOMMENDED)**
|
|
3113
3119
|
*
|
|
3114
3120
|
* ```js
|
|
3115
|
-
* import { exists, open, close } from 'fs';
|
|
3121
|
+
* import { exists, open, close } from 'node:fs';
|
|
3116
3122
|
*
|
|
3117
3123
|
* exists('myfile', (e) => {
|
|
3118
3124
|
* if (e) {
|
|
@@ -3136,7 +3142,7 @@ declare module 'fs' {
|
|
|
3136
3142
|
* **write (RECOMMENDED)**
|
|
3137
3143
|
*
|
|
3138
3144
|
* ```js
|
|
3139
|
-
* import { open, close } from 'fs';
|
|
3145
|
+
* import { open, close } from 'node:fs';
|
|
3140
3146
|
* open('myfile', 'wx', (err, fd) => {
|
|
3141
3147
|
* if (err) {
|
|
3142
3148
|
* if (err.code === 'EEXIST') {
|
|
@@ -3160,7 +3166,7 @@ declare module 'fs' {
|
|
|
3160
3166
|
* **read (NOT RECOMMENDED)**
|
|
3161
3167
|
*
|
|
3162
3168
|
* ```js
|
|
3163
|
-
* import { open, close, exists } from 'fs';
|
|
3169
|
+
* import { open, close, exists } from 'node:fs';
|
|
3164
3170
|
*
|
|
3165
3171
|
* exists('myfile', (e) => {
|
|
3166
3172
|
* if (e) {
|
|
@@ -3184,7 +3190,7 @@ declare module 'fs' {
|
|
|
3184
3190
|
* **read (RECOMMENDED)**
|
|
3185
3191
|
*
|
|
3186
3192
|
* ```js
|
|
3187
|
-
* import { open, close } from 'fs';
|
|
3193
|
+
* import { open, close } from 'node:fs';
|
|
3188
3194
|
*
|
|
3189
3195
|
* open('myfile', 'r', (err, fd) => {
|
|
3190
3196
|
* if (err) {
|
|
@@ -3210,7 +3216,7 @@ declare module 'fs' {
|
|
|
3210
3216
|
* file; the "recommended" examples are better because they use the file directly
|
|
3211
3217
|
* and handle the error, if any.
|
|
3212
3218
|
*
|
|
3213
|
-
* In general, check for the existence of a file only if the file won
|
|
3219
|
+
* In general, check for the existence of a file only if the file won't be
|
|
3214
3220
|
* used directly, for example when its existence is a signal from another
|
|
3215
3221
|
* process.
|
|
3216
3222
|
* @since v0.0.2
|
|
@@ -3235,7 +3241,7 @@ declare module 'fs' {
|
|
|
3235
3241
|
* Node.js callbacks. `fs.existsSync()` does not use a callback.
|
|
3236
3242
|
*
|
|
3237
3243
|
* ```js
|
|
3238
|
-
* import { existsSync } from 'fs';
|
|
3244
|
+
* import { existsSync } from 'node:fs';
|
|
3239
3245
|
*
|
|
3240
3246
|
* if (existsSync('/etc/passwd'))
|
|
3241
3247
|
* console.log('The path exists.');
|
|
@@ -3369,7 +3375,7 @@ declare module 'fs' {
|
|
|
3369
3375
|
* argument will be an `Error` object. The following examples check if`package.json` exists, and if it is readable or writable.
|
|
3370
3376
|
*
|
|
3371
3377
|
* ```js
|
|
3372
|
-
* import { access, constants } from 'fs';
|
|
3378
|
+
* import { access, constants } from 'node:fs';
|
|
3373
3379
|
*
|
|
3374
3380
|
* const file = 'package.json';
|
|
3375
3381
|
*
|
|
@@ -3394,7 +3400,7 @@ declare module 'fs' {
|
|
|
3394
3400
|
* });
|
|
3395
3401
|
* ```
|
|
3396
3402
|
*
|
|
3397
|
-
* Do not use `fs.access()` to check for the accessibility of a file before calling`fs.open()`, `fs.readFile()
|
|
3403
|
+
* Do not use `fs.access()` to check for the accessibility of a file before calling`fs.open()`, `fs.readFile()`, or `fs.writeFile()`. Doing
|
|
3398
3404
|
* so introduces a race condition, since other processes may change the file's
|
|
3399
3405
|
* state between the two calls. Instead, user code should open/read/write the
|
|
3400
3406
|
* file directly and handle the error raised if the file is not accessible.
|
|
@@ -3402,7 +3408,7 @@ declare module 'fs' {
|
|
|
3402
3408
|
* **write (NOT RECOMMENDED)**
|
|
3403
3409
|
*
|
|
3404
3410
|
* ```js
|
|
3405
|
-
* import { access, open, close } from 'fs';
|
|
3411
|
+
* import { access, open, close } from 'node:fs';
|
|
3406
3412
|
*
|
|
3407
3413
|
* access('myfile', (err) => {
|
|
3408
3414
|
* if (!err) {
|
|
@@ -3427,7 +3433,7 @@ declare module 'fs' {
|
|
|
3427
3433
|
* **write (RECOMMENDED)**
|
|
3428
3434
|
*
|
|
3429
3435
|
* ```js
|
|
3430
|
-
* import { open, close } from 'fs';
|
|
3436
|
+
* import { open, close } from 'node:fs';
|
|
3431
3437
|
*
|
|
3432
3438
|
* open('myfile', 'wx', (err, fd) => {
|
|
3433
3439
|
* if (err) {
|
|
@@ -3452,7 +3458,7 @@ declare module 'fs' {
|
|
|
3452
3458
|
* **read (NOT RECOMMENDED)**
|
|
3453
3459
|
*
|
|
3454
3460
|
* ```js
|
|
3455
|
-
* import { access, open, close } from 'fs';
|
|
3461
|
+
* import { access, open, close } from 'node:fs';
|
|
3456
3462
|
* access('myfile', (err) => {
|
|
3457
3463
|
* if (err) {
|
|
3458
3464
|
* if (err.code === 'ENOENT') {
|
|
@@ -3480,7 +3486,7 @@ declare module 'fs' {
|
|
|
3480
3486
|
* **read (RECOMMENDED)**
|
|
3481
3487
|
*
|
|
3482
3488
|
* ```js
|
|
3483
|
-
* import { open, close } from 'fs';
|
|
3489
|
+
* import { open, close } from 'node:fs';
|
|
3484
3490
|
*
|
|
3485
3491
|
* open('myfile', 'r', (err, fd) => {
|
|
3486
3492
|
* if (err) {
|
|
@@ -3542,7 +3548,7 @@ declare module 'fs' {
|
|
|
3542
3548
|
* the method will return `undefined`.
|
|
3543
3549
|
*
|
|
3544
3550
|
* ```js
|
|
3545
|
-
* import { accessSync, constants } from 'fs';
|
|
3551
|
+
* import { accessSync, constants } from 'node:fs';
|
|
3546
3552
|
*
|
|
3547
3553
|
* try {
|
|
3548
3554
|
* accessSync('etc/passwd', constants.R_OK | constants.W_OK);
|
|
@@ -3572,8 +3578,8 @@ declare module 'fs' {
|
|
|
3572
3578
|
end?: number | undefined;
|
|
3573
3579
|
}
|
|
3574
3580
|
/**
|
|
3575
|
-
* Unlike the 16
|
|
3576
|
-
* returned by this method has a default `highWaterMark` of 64
|
|
3581
|
+
* Unlike the 16 KiB default `highWaterMark` for a `stream.Readable`, the stream
|
|
3582
|
+
* returned by this method has a default `highWaterMark` of 64 KiB.
|
|
3577
3583
|
*
|
|
3578
3584
|
* `options` can include `start` and `end` values to read a range of bytes from
|
|
3579
3585
|
* the file instead of the entire file. Both `start` and `end` are inclusive and
|
|
@@ -3599,7 +3605,7 @@ declare module 'fs' {
|
|
|
3599
3605
|
* also required.
|
|
3600
3606
|
*
|
|
3601
3607
|
* ```js
|
|
3602
|
-
* import { createReadStream } from 'fs';
|
|
3608
|
+
* import { createReadStream } from 'node:fs';
|
|
3603
3609
|
*
|
|
3604
3610
|
* // Create a stream from some character device.
|
|
3605
3611
|
* const stream = createReadStream('/dev/input/event0');
|
|
@@ -3627,7 +3633,7 @@ declare module 'fs' {
|
|
|
3627
3633
|
* An example to read the last 10 bytes of a file which is 100 bytes long:
|
|
3628
3634
|
*
|
|
3629
3635
|
* ```js
|
|
3630
|
-
* import { createReadStream } from 'fs';
|
|
3636
|
+
* import { createReadStream } from 'node:fs';
|
|
3631
3637
|
*
|
|
3632
3638
|
* createReadStream('sample.txt', { start: 90, end: 99 });
|
|
3633
3639
|
* ```
|
|
@@ -3651,7 +3657,7 @@ declare module 'fs' {
|
|
|
3651
3657
|
* By default, the stream will emit a `'close'` event after it has been
|
|
3652
3658
|
* destroyed. Set the `emitClose` option to `false` to change this behavior.
|
|
3653
3659
|
*
|
|
3654
|
-
* By providing the `fs` option it is possible to override the corresponding `fs`implementations for `open`, `write`, `writev
|
|
3660
|
+
* 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
3661
|
* performance as some optimizations (`_writev()`)
|
|
3656
3662
|
* 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
3663
|
* for `open` is also required. If `autoClose` is `true`, an override for `close`is also required.
|
|
@@ -3706,7 +3712,7 @@ declare module 'fs' {
|
|
|
3706
3712
|
* copy-on-write, then the operation will fail.
|
|
3707
3713
|
*
|
|
3708
3714
|
* ```js
|
|
3709
|
-
* import { copyFile, constants } from 'fs';
|
|
3715
|
+
* import { copyFile, constants } from 'node:fs';
|
|
3710
3716
|
*
|
|
3711
3717
|
* function callback(err) {
|
|
3712
3718
|
* if (err) throw err;
|
|
@@ -3749,7 +3755,7 @@ declare module 'fs' {
|
|
|
3749
3755
|
* copy-on-write, then the operation will fail.
|
|
3750
3756
|
*
|
|
3751
3757
|
* ```js
|
|
3752
|
-
* import { copyFileSync, constants } from 'fs';
|
|
3758
|
+
* import { copyFileSync, constants } from 'node:fs';
|
|
3753
3759
|
*
|
|
3754
3760
|
* // destination.txt will be created or overwritten by default.
|
|
3755
3761
|
* copyFileSync('source.txt', 'destination.txt');
|
|
@@ -3782,6 +3788,7 @@ declare module 'fs' {
|
|
|
3782
3788
|
* The kernel ignores the position argument and always appends the data to
|
|
3783
3789
|
* the end of the file.
|
|
3784
3790
|
* @since v12.9.0
|
|
3791
|
+
* @param [position='null']
|
|
3785
3792
|
*/
|
|
3786
3793
|
export function writev(fd: number, buffers: ReadonlyArray<NodeJS.ArrayBufferView>, cb: (err: NodeJS.ErrnoException | null, bytesWritten: number, buffers: NodeJS.ArrayBufferView[]) => void): void;
|
|
3787
3794
|
export function writev(
|
|
@@ -3801,6 +3808,7 @@ declare module 'fs' {
|
|
|
3801
3808
|
* For detailed information, see the documentation of the asynchronous version of
|
|
3802
3809
|
* this API: {@link writev}.
|
|
3803
3810
|
* @since v12.9.0
|
|
3811
|
+
* @param [position='null']
|
|
3804
3812
|
* @return The number of bytes written.
|
|
3805
3813
|
*/
|
|
3806
3814
|
export function writevSync(fd: number, buffers: ReadonlyArray<NodeJS.ArrayBufferView>, position?: number): number;
|
|
@@ -3817,6 +3825,7 @@ declare module 'fs' {
|
|
|
3817
3825
|
* If this method is invoked as its `util.promisify()` ed version, it returns
|
|
3818
3826
|
* a promise for an `Object` with `bytesRead` and `buffers` properties.
|
|
3819
3827
|
* @since v13.13.0, v12.17.0
|
|
3828
|
+
* @param [position='null']
|
|
3820
3829
|
*/
|
|
3821
3830
|
export function readv(fd: number, buffers: ReadonlyArray<NodeJS.ArrayBufferView>, cb: (err: NodeJS.ErrnoException | null, bytesRead: number, buffers: NodeJS.ArrayBufferView[]) => void): void;
|
|
3822
3831
|
export function readv(
|
|
@@ -3836,6 +3845,7 @@ declare module 'fs' {
|
|
|
3836
3845
|
* For detailed information, see the documentation of the asynchronous version of
|
|
3837
3846
|
* this API: {@link readv}.
|
|
3838
3847
|
* @since v13.13.0, v12.17.0
|
|
3848
|
+
* @param [position='null']
|
|
3839
3849
|
* @return The number of bytes read.
|
|
3840
3850
|
*/
|
|
3841
3851
|
export function readvSync(fd: number, buffers: ReadonlyArray<NodeJS.ArrayBufferView>, position?: number): number;
|