@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/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.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
|
|
@@ -191,7 +191,7 @@ declare module 'fs' {
|
|
|
191
191
|
* Created by {@link opendir}, {@link opendirSync}, or `fsPromises.opendir()`.
|
|
192
192
|
*
|
|
193
193
|
* ```js
|
|
194
|
-
* import { opendir } from 'fs/promises';
|
|
194
|
+
* import { opendir } from 'node:fs/promises';
|
|
195
195
|
*
|
|
196
196
|
* try {
|
|
197
197
|
* const dir = await opendir('./');
|
|
@@ -494,7 +494,7 @@ declare module 'fs' {
|
|
|
494
494
|
* See also: [`rename(2)`](http://man7.org/linux/man-pages/man2/rename.2.html).
|
|
495
495
|
*
|
|
496
496
|
* ```js
|
|
497
|
-
* import { rename } from 'fs';
|
|
497
|
+
* import { rename } from 'node:fs';
|
|
498
498
|
*
|
|
499
499
|
* rename('oldFile.txt', 'newFile.txt', (err) => {
|
|
500
500
|
* if (err) throw err;
|
|
@@ -527,7 +527,7 @@ declare module 'fs' {
|
|
|
527
527
|
* first argument. In this case, `fs.ftruncate()` is called.
|
|
528
528
|
*
|
|
529
529
|
* ```js
|
|
530
|
-
* import { truncate } from 'fs';
|
|
530
|
+
* import { truncate } from 'node:fs';
|
|
531
531
|
* // Assuming that 'path/file.txt' is a regular file.
|
|
532
532
|
* truncate('path/file.txt', (err) => {
|
|
533
533
|
* if (err) throw err;
|
|
@@ -579,7 +579,7 @@ declare module 'fs' {
|
|
|
579
579
|
* file:
|
|
580
580
|
*
|
|
581
581
|
* ```js
|
|
582
|
-
* import { open, close, ftruncate } from 'fs';
|
|
582
|
+
* import { open, close, ftruncate } from 'node:fs';
|
|
583
583
|
*
|
|
584
584
|
* function closeFd(fd) {
|
|
585
585
|
* close(fd, (err) => {
|
|
@@ -736,7 +736,7 @@ declare module 'fs' {
|
|
|
736
736
|
* See the POSIX [`chmod(2)`](http://man7.org/linux/man-pages/man2/chmod.2.html) documentation for more detail.
|
|
737
737
|
*
|
|
738
738
|
* ```js
|
|
739
|
-
* import { chmod } from 'fs';
|
|
739
|
+
* import { chmod } from 'node:fs';
|
|
740
740
|
*
|
|
741
741
|
* chmod('my_file.txt', 0o775, (err) => {
|
|
742
742
|
* if (err) throw err;
|
|
@@ -818,7 +818,7 @@ declare module 'fs' {
|
|
|
818
818
|
*
|
|
819
819
|
* In case of an error, the `err.code` will be one of `Common System Errors`.
|
|
820
820
|
*
|
|
821
|
-
* Using `fs.stat()` to check for the existence of a file before calling`fs.open()`, `fs.readFile()
|
|
821
|
+
* Using `fs.stat()` to check for the existence of a file before calling`fs.open()`, `fs.readFile()`, or `fs.writeFile()` is not recommended.
|
|
822
822
|
* Instead, user code should open/read/write the file directly and handle the
|
|
823
823
|
* error raised if the file is not available.
|
|
824
824
|
*
|
|
@@ -835,7 +835,7 @@ declare module 'fs' {
|
|
|
835
835
|
* The next program will check for the stats of the given paths:
|
|
836
836
|
*
|
|
837
837
|
* ```js
|
|
838
|
-
* import { stat } from 'fs';
|
|
838
|
+
* import { stat } from 'node:fs';
|
|
839
839
|
*
|
|
840
840
|
* const pathsToCheck = ['./txtDir', './txtDir/file.txt'];
|
|
841
841
|
*
|
|
@@ -1114,14 +1114,14 @@ declare module 'fs' {
|
|
|
1114
1114
|
*
|
|
1115
1115
|
* The `type` argument is only available on Windows and ignored on other platforms.
|
|
1116
1116
|
* 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
|
|
1117
|
+
* not a string, Node.js will autodetect `target` type and use `'file'` or `'dir'`.
|
|
1118
|
+
* If the `target` does not exist, `'file'` will be used. Windows junction points
|
|
1119
1119
|
* require the destination path to be absolute. When using `'junction'`, the`target` argument will automatically be normalized to absolute path.
|
|
1120
1120
|
*
|
|
1121
|
-
* Relative targets are relative to the link
|
|
1121
|
+
* Relative targets are relative to the link's parent directory.
|
|
1122
1122
|
*
|
|
1123
1123
|
* ```js
|
|
1124
|
-
* import { symlink } from 'fs';
|
|
1124
|
+
* import { symlink } from 'node:fs';
|
|
1125
1125
|
*
|
|
1126
1126
|
* symlink('./mew', './mewtwo', callback);
|
|
1127
1127
|
* ```
|
|
@@ -1136,6 +1136,7 @@ declare module 'fs' {
|
|
|
1136
1136
|
* └── mewtwo -> ./mew
|
|
1137
1137
|
* ```
|
|
1138
1138
|
* @since v0.1.31
|
|
1139
|
+
* @param [type='null']
|
|
1139
1140
|
*/
|
|
1140
1141
|
export function symlink(target: PathLike, path: PathLike, type: symlink.Type | undefined | null, callback: NoParamCallback): void;
|
|
1141
1142
|
/**
|
|
@@ -1161,6 +1162,7 @@ declare module 'fs' {
|
|
|
1161
1162
|
* For detailed information, see the documentation of the asynchronous version of
|
|
1162
1163
|
* this API: {@link symlink}.
|
|
1163
1164
|
* @since v0.1.31
|
|
1165
|
+
* @param [type='null']
|
|
1164
1166
|
*/
|
|
1165
1167
|
export function symlinkSync(target: PathLike, path: PathLike, type?: symlink.Type | null): void;
|
|
1166
1168
|
/**
|
|
@@ -1238,7 +1240,7 @@ declare module 'fs' {
|
|
|
1238
1240
|
*/
|
|
1239
1241
|
export function readlinkSync(path: PathLike, options?: EncodingOption): string | Buffer;
|
|
1240
1242
|
/**
|
|
1241
|
-
* Asynchronously computes the canonical pathname by resolving `.`,
|
|
1243
|
+
* Asynchronously computes the canonical pathname by resolving `.`, `..`, and
|
|
1242
1244
|
* symbolic links.
|
|
1243
1245
|
*
|
|
1244
1246
|
* A canonical pathname is not necessarily unique. Hard links and bind mounts can
|
|
@@ -1352,7 +1354,7 @@ declare module 'fs' {
|
|
|
1352
1354
|
* possible exception are given to the completion callback.
|
|
1353
1355
|
*
|
|
1354
1356
|
* ```js
|
|
1355
|
-
* import { unlink } from 'fs';
|
|
1357
|
+
* import { unlink } from 'node:fs';
|
|
1356
1358
|
* // Assuming that 'path/file.txt' is a regular file.
|
|
1357
1359
|
* unlink('path/file.txt', (err) => {
|
|
1358
1360
|
* if (err) throw err;
|
|
@@ -1507,7 +1509,7 @@ declare module 'fs' {
|
|
|
1507
1509
|
* when `recursive` is false.
|
|
1508
1510
|
*
|
|
1509
1511
|
* ```js
|
|
1510
|
-
* import { mkdir } from 'fs';
|
|
1512
|
+
* import { mkdir } from 'node:fs';
|
|
1511
1513
|
*
|
|
1512
1514
|
* // Creates /tmp/a/apple, regardless of whether `/tmp` and /tmp/a exist.
|
|
1513
1515
|
* mkdir('/tmp/a/apple', { recursive: true }, (err) => {
|
|
@@ -1519,7 +1521,7 @@ declare module 'fs' {
|
|
|
1519
1521
|
* result in an error:
|
|
1520
1522
|
*
|
|
1521
1523
|
* ```js
|
|
1522
|
-
* import { mkdir } from 'fs';
|
|
1524
|
+
* import { mkdir } from 'node:fs';
|
|
1523
1525
|
*
|
|
1524
1526
|
* mkdir('/', { recursive: true }, (err) => {
|
|
1525
1527
|
* // => [Error: EPERM: operation not permitted, mkdir 'C:\']
|
|
@@ -1651,9 +1653,11 @@ declare module 'fs' {
|
|
|
1651
1653
|
* object with an `encoding` property specifying the character encoding to use.
|
|
1652
1654
|
*
|
|
1653
1655
|
* ```js
|
|
1654
|
-
* import { mkdtemp } from 'fs';
|
|
1656
|
+
* import { mkdtemp } from 'node:fs';
|
|
1657
|
+
* import { join } from 'node:path';
|
|
1658
|
+
* import { tmpdir } from 'node:os';
|
|
1655
1659
|
*
|
|
1656
|
-
* mkdtemp(
|
|
1660
|
+
* mkdtemp(join(tmpdir(), 'foo-'), (err, directory) => {
|
|
1657
1661
|
* if (err) throw err;
|
|
1658
1662
|
* console.log(directory);
|
|
1659
1663
|
* // Prints: /tmp/foo-itXde2 or C:\Users\...\AppData\Local\Temp\foo-itXde2
|
|
@@ -1663,11 +1667,11 @@ declare module 'fs' {
|
|
|
1663
1667
|
* The `fs.mkdtemp()` method will append the six randomly selected characters
|
|
1664
1668
|
* directly to the `prefix` string. For instance, given a directory `/tmp`, if the
|
|
1665
1669
|
* intention is to create a temporary directory _within_`/tmp`, the `prefix`must end with a trailing platform-specific path separator
|
|
1666
|
-
* (`require('path').sep`).
|
|
1670
|
+
* (`require('node:path').sep`).
|
|
1667
1671
|
*
|
|
1668
1672
|
* ```js
|
|
1669
|
-
* import { tmpdir } from 'os';
|
|
1670
|
-
* import { mkdtemp } from 'fs';
|
|
1673
|
+
* import { tmpdir } from 'node:os';
|
|
1674
|
+
* import { mkdtemp } from 'node:fs';
|
|
1671
1675
|
*
|
|
1672
1676
|
* // The parent directory for the new temporary directory
|
|
1673
1677
|
* const tmpDir = tmpdir();
|
|
@@ -1682,7 +1686,7 @@ declare module 'fs' {
|
|
|
1682
1686
|
* });
|
|
1683
1687
|
*
|
|
1684
1688
|
* // This method is *CORRECT*:
|
|
1685
|
-
* import { sep } from 'path';
|
|
1689
|
+
* import { sep } from 'node:path';
|
|
1686
1690
|
* mkdtemp(`${tmpDir}${sep}`, (err, directory) => {
|
|
1687
1691
|
* if (err) throw err;
|
|
1688
1692
|
* console.log(directory);
|
|
@@ -2010,7 +2014,6 @@ declare module 'fs' {
|
|
|
2010
2014
|
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
2011
2015
|
*/
|
|
2012
2016
|
export function open(path: PathLike, callback: (err: NodeJS.ErrnoException | null, fd: number) => void): void;
|
|
2013
|
-
|
|
2014
2017
|
export namespace open {
|
|
2015
2018
|
/**
|
|
2016
2019
|
* Asynchronous open(2) - open and possibly create a file.
|
|
@@ -2035,7 +2038,7 @@ declare module 'fs' {
|
|
|
2035
2038
|
* The `atime` and `mtime` arguments follow these rules:
|
|
2036
2039
|
*
|
|
2037
2040
|
* * 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
|
|
2041
|
+
* * If the value can not be converted to a number, or is `NaN`, `Infinity`, or`-Infinity`, an `Error` will be thrown.
|
|
2039
2042
|
* @since v0.4.2
|
|
2040
2043
|
*/
|
|
2041
2044
|
export function utimes(path: PathLike, atime: TimeLike, mtime: TimeLike, callback: NoParamCallback): void;
|
|
@@ -2121,6 +2124,9 @@ declare module 'fs' {
|
|
|
2121
2124
|
* The kernel ignores the position argument and always appends the data to
|
|
2122
2125
|
* the end of the file.
|
|
2123
2126
|
* @since v0.0.2
|
|
2127
|
+
* @param [offset=0]
|
|
2128
|
+
* @param [length=buffer.byteLength - offset]
|
|
2129
|
+
* @param [position='null']
|
|
2124
2130
|
*/
|
|
2125
2131
|
export function write<TBuffer extends NodeJS.ArrayBufferView>(
|
|
2126
2132
|
fd: number,
|
|
@@ -2225,6 +2231,9 @@ declare module 'fs' {
|
|
|
2225
2231
|
* For detailed information, see the documentation of the asynchronous version of
|
|
2226
2232
|
* this API: {@link write}.
|
|
2227
2233
|
* @since v0.1.21
|
|
2234
|
+
* @param [offset=0]
|
|
2235
|
+
* @param [length=buffer.byteLength - offset]
|
|
2236
|
+
* @param [position='null']
|
|
2228
2237
|
* @return The number of bytes written.
|
|
2229
2238
|
*/
|
|
2230
2239
|
export function writeSync(fd: number, buffer: NodeJS.ArrayBufferView, offset?: number | null, length?: number | null, position?: number | null): number;
|
|
@@ -2330,6 +2339,7 @@ declare module 'fs' {
|
|
|
2330
2339
|
* For detailed information, see the documentation of the asynchronous version of
|
|
2331
2340
|
* this API: {@link read}.
|
|
2332
2341
|
* @since v0.1.21
|
|
2342
|
+
* @param [position='null']
|
|
2333
2343
|
*/
|
|
2334
2344
|
export function readSync(fd: number, buffer: NodeJS.ArrayBufferView, offset: number, length: number, position: ReadPosition | null): number;
|
|
2335
2345
|
/**
|
|
@@ -2341,7 +2351,7 @@ declare module 'fs' {
|
|
|
2341
2351
|
* Asynchronously reads the entire contents of a file.
|
|
2342
2352
|
*
|
|
2343
2353
|
* ```js
|
|
2344
|
-
* import { readFile } from 'fs';
|
|
2354
|
+
* import { readFile } from 'node:fs';
|
|
2345
2355
|
*
|
|
2346
2356
|
* readFile('/etc/passwd', (err, data) => {
|
|
2347
2357
|
* if (err) throw err;
|
|
@@ -2357,7 +2367,7 @@ declare module 'fs' {
|
|
|
2357
2367
|
* If `options` is a string, then it specifies the encoding:
|
|
2358
2368
|
*
|
|
2359
2369
|
* ```js
|
|
2360
|
-
* import { readFile } from 'fs';
|
|
2370
|
+
* import { readFile } from 'node:fs';
|
|
2361
2371
|
*
|
|
2362
2372
|
* readFile('/etc/passwd', 'utf8', callback);
|
|
2363
2373
|
* ```
|
|
@@ -2367,7 +2377,7 @@ declare module 'fs' {
|
|
|
2367
2377
|
* will be returned.
|
|
2368
2378
|
*
|
|
2369
2379
|
* ```js
|
|
2370
|
-
* import { readFile } from 'fs';
|
|
2380
|
+
* import { readFile } from 'node:fs';
|
|
2371
2381
|
*
|
|
2372
2382
|
* // macOS, Linux, and Windows
|
|
2373
2383
|
* readFile('<directory>', (err, data) => {
|
|
@@ -2384,7 +2394,7 @@ declare module 'fs' {
|
|
|
2384
2394
|
* request is aborted the callback is called with an `AbortError`:
|
|
2385
2395
|
*
|
|
2386
2396
|
* ```js
|
|
2387
|
-
* import { readFile } from 'fs';
|
|
2397
|
+
* import { readFile } from 'node:fs';
|
|
2388
2398
|
*
|
|
2389
2399
|
* const controller = new AbortController();
|
|
2390
2400
|
* const signal = controller.signal;
|
|
@@ -2517,7 +2527,7 @@ declare module 'fs' {
|
|
|
2517
2527
|
* Similar to {@link readFile}, when the path is a directory, the behavior of`fs.readFileSync()` is platform-specific.
|
|
2518
2528
|
*
|
|
2519
2529
|
* ```js
|
|
2520
|
-
* import { readFileSync } from 'fs';
|
|
2530
|
+
* import { readFileSync } from 'node:fs';
|
|
2521
2531
|
*
|
|
2522
2532
|
* // macOS, Linux, and Windows
|
|
2523
2533
|
* readFileSync('<directory>');
|
|
@@ -2588,8 +2598,8 @@ declare module 'fs' {
|
|
|
2588
2598
|
* The `mode` option only affects the newly created file. See {@link open} for more details.
|
|
2589
2599
|
*
|
|
2590
2600
|
* ```js
|
|
2591
|
-
* import { writeFile } from 'fs';
|
|
2592
|
-
* import { Buffer } from 'buffer';
|
|
2601
|
+
* import { writeFile } from 'node:fs';
|
|
2602
|
+
* import { Buffer } from 'node:buffer';
|
|
2593
2603
|
*
|
|
2594
2604
|
* const data = new Uint8Array(Buffer.from('Hello Node.js'));
|
|
2595
2605
|
* writeFile('message.txt', data, (err) => {
|
|
@@ -2601,7 +2611,7 @@ declare module 'fs' {
|
|
|
2601
2611
|
* If `options` is a string, then it specifies the encoding:
|
|
2602
2612
|
*
|
|
2603
2613
|
* ```js
|
|
2604
|
-
* import { writeFile } from 'fs';
|
|
2614
|
+
* import { writeFile } from 'node:fs';
|
|
2605
2615
|
*
|
|
2606
2616
|
* writeFile('message.txt', 'Hello Node.js', 'utf8', callback);
|
|
2607
2617
|
* ```
|
|
@@ -2619,8 +2629,8 @@ declare module 'fs' {
|
|
|
2619
2629
|
* to be written.
|
|
2620
2630
|
*
|
|
2621
2631
|
* ```js
|
|
2622
|
-
* import { writeFile } from 'fs';
|
|
2623
|
-
* import { Buffer } from 'buffer';
|
|
2632
|
+
* import { writeFile } from 'node:fs';
|
|
2633
|
+
* import { Buffer } from 'node:buffer';
|
|
2624
2634
|
*
|
|
2625
2635
|
* const controller = new AbortController();
|
|
2626
2636
|
* const { signal } = controller;
|
|
@@ -2678,7 +2688,7 @@ declare module 'fs' {
|
|
|
2678
2688
|
* The `mode` option only affects the newly created file. See {@link open} for more details.
|
|
2679
2689
|
*
|
|
2680
2690
|
* ```js
|
|
2681
|
-
* import { appendFile } from 'fs';
|
|
2691
|
+
* import { appendFile } from 'node:fs';
|
|
2682
2692
|
*
|
|
2683
2693
|
* appendFile('message.txt', 'data to append', (err) => {
|
|
2684
2694
|
* if (err) throw err;
|
|
@@ -2689,7 +2699,7 @@ declare module 'fs' {
|
|
|
2689
2699
|
* If `options` is a string, then it specifies the encoding:
|
|
2690
2700
|
*
|
|
2691
2701
|
* ```js
|
|
2692
|
-
* import { appendFile } from 'fs';
|
|
2702
|
+
* import { appendFile } from 'node:fs';
|
|
2693
2703
|
*
|
|
2694
2704
|
* appendFile('message.txt', 'data to append', 'utf8', callback);
|
|
2695
2705
|
* ```
|
|
@@ -2699,7 +2709,7 @@ declare module 'fs' {
|
|
|
2699
2709
|
* not be closed automatically.
|
|
2700
2710
|
*
|
|
2701
2711
|
* ```js
|
|
2702
|
-
* import { open, close, appendFile } from 'fs';
|
|
2712
|
+
* import { open, close, appendFile } from 'node:fs';
|
|
2703
2713
|
*
|
|
2704
2714
|
* function closeFd(fd) {
|
|
2705
2715
|
* close(fd, (err) => {
|
|
@@ -2754,7 +2764,7 @@ declare module 'fs' {
|
|
|
2754
2764
|
* The `mode` option only affects the newly created file. See {@link open} for more details.
|
|
2755
2765
|
*
|
|
2756
2766
|
* ```js
|
|
2757
|
-
* import { appendFileSync } from 'fs';
|
|
2767
|
+
* import { appendFileSync } from 'node:fs';
|
|
2758
2768
|
*
|
|
2759
2769
|
* try {
|
|
2760
2770
|
* appendFileSync('message.txt', 'data to append');
|
|
@@ -2767,7 +2777,7 @@ declare module 'fs' {
|
|
|
2767
2777
|
* If `options` is a string, then it specifies the encoding:
|
|
2768
2778
|
*
|
|
2769
2779
|
* ```js
|
|
2770
|
-
* import { appendFileSync } from 'fs';
|
|
2780
|
+
* import { appendFileSync } from 'node:fs';
|
|
2771
2781
|
*
|
|
2772
2782
|
* appendFileSync('message.txt', 'data to append', 'utf8');
|
|
2773
2783
|
* ```
|
|
@@ -2777,7 +2787,7 @@ declare module 'fs' {
|
|
|
2777
2787
|
* not be closed automatically.
|
|
2778
2788
|
*
|
|
2779
2789
|
* ```js
|
|
2780
|
-
* import { openSync, closeSync, appendFileSync } from 'fs';
|
|
2790
|
+
* import { openSync, closeSync, appendFileSync } from 'node:fs';
|
|
2781
2791
|
*
|
|
2782
2792
|
* let fd;
|
|
2783
2793
|
*
|
|
@@ -2859,7 +2869,7 @@ declare module 'fs' {
|
|
|
2859
2869
|
* stat object:
|
|
2860
2870
|
*
|
|
2861
2871
|
* ```js
|
|
2862
|
-
* import { watchFile } from 'fs';
|
|
2872
|
+
* import { watchFile } from 'node:fs';
|
|
2863
2873
|
*
|
|
2864
2874
|
* watchFile('message.text', (curr, prev) => {
|
|
2865
2875
|
* console.log(`the current mtime is: ${curr.mtime}`);
|
|
@@ -2992,7 +3002,7 @@ declare module 'fs' {
|
|
|
2992
3002
|
* Then call the `callback` argument with either true or false:
|
|
2993
3003
|
*
|
|
2994
3004
|
* ```js
|
|
2995
|
-
* import { exists } from 'fs';
|
|
3005
|
+
* import { exists } from 'node:fs';
|
|
2996
3006
|
*
|
|
2997
3007
|
* exists('/etc/passwd', (e) => {
|
|
2998
3008
|
* console.log(e ? 'it exists' : 'no passwd!');
|
|
@@ -3004,7 +3014,7 @@ declare module 'fs' {
|
|
|
3004
3014
|
* has only one boolean parameter. This is one reason `fs.access()` is recommended
|
|
3005
3015
|
* instead of `fs.exists()`.
|
|
3006
3016
|
*
|
|
3007
|
-
* Using `fs.exists()` to check for the existence of a file before calling`fs.open()`, `fs.readFile()
|
|
3017
|
+
* 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
3018
|
* so introduces a race condition, since other processes may change the file's
|
|
3009
3019
|
* state between the two calls. Instead, user code should open/read/write the
|
|
3010
3020
|
* file directly and handle the error raised if the file does not exist.
|
|
@@ -3012,7 +3022,7 @@ declare module 'fs' {
|
|
|
3012
3022
|
* **write (NOT RECOMMENDED)**
|
|
3013
3023
|
*
|
|
3014
3024
|
* ```js
|
|
3015
|
-
* import { exists, open, close } from 'fs';
|
|
3025
|
+
* import { exists, open, close } from 'node:fs';
|
|
3016
3026
|
*
|
|
3017
3027
|
* exists('myfile', (e) => {
|
|
3018
3028
|
* if (e) {
|
|
@@ -3036,7 +3046,7 @@ declare module 'fs' {
|
|
|
3036
3046
|
* **write (RECOMMENDED)**
|
|
3037
3047
|
*
|
|
3038
3048
|
* ```js
|
|
3039
|
-
* import { open, close } from 'fs';
|
|
3049
|
+
* import { open, close } from 'node:fs';
|
|
3040
3050
|
* open('myfile', 'wx', (err, fd) => {
|
|
3041
3051
|
* if (err) {
|
|
3042
3052
|
* if (err.code === 'EEXIST') {
|
|
@@ -3060,7 +3070,7 @@ declare module 'fs' {
|
|
|
3060
3070
|
* **read (NOT RECOMMENDED)**
|
|
3061
3071
|
*
|
|
3062
3072
|
* ```js
|
|
3063
|
-
* import { open, close, exists } from 'fs';
|
|
3073
|
+
* import { open, close, exists } from 'node:fs';
|
|
3064
3074
|
*
|
|
3065
3075
|
* exists('myfile', (e) => {
|
|
3066
3076
|
* if (e) {
|
|
@@ -3084,7 +3094,7 @@ declare module 'fs' {
|
|
|
3084
3094
|
* **read (RECOMMENDED)**
|
|
3085
3095
|
*
|
|
3086
3096
|
* ```js
|
|
3087
|
-
* import { open, close } from 'fs';
|
|
3097
|
+
* import { open, close } from 'node:fs';
|
|
3088
3098
|
*
|
|
3089
3099
|
* open('myfile', 'r', (err, fd) => {
|
|
3090
3100
|
* if (err) {
|
|
@@ -3110,7 +3120,7 @@ declare module 'fs' {
|
|
|
3110
3120
|
* file; the "recommended" examples are better because they use the file directly
|
|
3111
3121
|
* and handle the error, if any.
|
|
3112
3122
|
*
|
|
3113
|
-
* In general, check for the existence of a file only if the file won
|
|
3123
|
+
* In general, check for the existence of a file only if the file won't be
|
|
3114
3124
|
* used directly, for example when its existence is a signal from another
|
|
3115
3125
|
* process.
|
|
3116
3126
|
* @since v0.0.2
|
|
@@ -3135,7 +3145,7 @@ declare module 'fs' {
|
|
|
3135
3145
|
* Node.js callbacks. `fs.existsSync()` does not use a callback.
|
|
3136
3146
|
*
|
|
3137
3147
|
* ```js
|
|
3138
|
-
* import { existsSync } from 'fs';
|
|
3148
|
+
* import { existsSync } from 'node:fs';
|
|
3139
3149
|
*
|
|
3140
3150
|
* if (existsSync('/etc/passwd'))
|
|
3141
3151
|
* console.log('The path exists.');
|
|
@@ -3269,7 +3279,7 @@ declare module 'fs' {
|
|
|
3269
3279
|
* argument will be an `Error` object. The following examples check if`package.json` exists, and if it is readable or writable.
|
|
3270
3280
|
*
|
|
3271
3281
|
* ```js
|
|
3272
|
-
* import { access, constants } from 'fs';
|
|
3282
|
+
* import { access, constants } from 'node:fs';
|
|
3273
3283
|
*
|
|
3274
3284
|
* const file = 'package.json';
|
|
3275
3285
|
*
|
|
@@ -3294,7 +3304,7 @@ declare module 'fs' {
|
|
|
3294
3304
|
* });
|
|
3295
3305
|
* ```
|
|
3296
3306
|
*
|
|
3297
|
-
* Do not use `fs.access()` to check for the accessibility of a file before calling`fs.open()`, `fs.readFile()
|
|
3307
|
+
* Do not use `fs.access()` to check for the accessibility of a file before calling`fs.open()`, `fs.readFile()`, or `fs.writeFile()`. Doing
|
|
3298
3308
|
* so introduces a race condition, since other processes may change the file's
|
|
3299
3309
|
* state between the two calls. Instead, user code should open/read/write the
|
|
3300
3310
|
* file directly and handle the error raised if the file is not accessible.
|
|
@@ -3302,7 +3312,7 @@ declare module 'fs' {
|
|
|
3302
3312
|
* **write (NOT RECOMMENDED)**
|
|
3303
3313
|
*
|
|
3304
3314
|
* ```js
|
|
3305
|
-
* import { access, open, close } from 'fs';
|
|
3315
|
+
* import { access, open, close } from 'node:fs';
|
|
3306
3316
|
*
|
|
3307
3317
|
* access('myfile', (err) => {
|
|
3308
3318
|
* if (!err) {
|
|
@@ -3327,7 +3337,7 @@ declare module 'fs' {
|
|
|
3327
3337
|
* **write (RECOMMENDED)**
|
|
3328
3338
|
*
|
|
3329
3339
|
* ```js
|
|
3330
|
-
* import { open, close } from 'fs';
|
|
3340
|
+
* import { open, close } from 'node:fs';
|
|
3331
3341
|
*
|
|
3332
3342
|
* open('myfile', 'wx', (err, fd) => {
|
|
3333
3343
|
* if (err) {
|
|
@@ -3352,7 +3362,7 @@ declare module 'fs' {
|
|
|
3352
3362
|
* **read (NOT RECOMMENDED)**
|
|
3353
3363
|
*
|
|
3354
3364
|
* ```js
|
|
3355
|
-
* import { access, open, close } from 'fs';
|
|
3365
|
+
* import { access, open, close } from 'node:fs';
|
|
3356
3366
|
* access('myfile', (err) => {
|
|
3357
3367
|
* if (err) {
|
|
3358
3368
|
* if (err.code === 'ENOENT') {
|
|
@@ -3380,7 +3390,7 @@ declare module 'fs' {
|
|
|
3380
3390
|
* **read (RECOMMENDED)**
|
|
3381
3391
|
*
|
|
3382
3392
|
* ```js
|
|
3383
|
-
* import { open, close } from 'fs';
|
|
3393
|
+
* import { open, close } from 'node:fs';
|
|
3384
3394
|
*
|
|
3385
3395
|
* open('myfile', 'r', (err, fd) => {
|
|
3386
3396
|
* if (err) {
|
|
@@ -3442,7 +3452,7 @@ declare module 'fs' {
|
|
|
3442
3452
|
* the method will return `undefined`.
|
|
3443
3453
|
*
|
|
3444
3454
|
* ```js
|
|
3445
|
-
* import { accessSync, constants } from 'fs';
|
|
3455
|
+
* import { accessSync, constants } from 'node:fs';
|
|
3446
3456
|
*
|
|
3447
3457
|
* try {
|
|
3448
3458
|
* accessSync('etc/passwd', constants.R_OK | constants.W_OK);
|
|
@@ -3472,8 +3482,8 @@ declare module 'fs' {
|
|
|
3472
3482
|
end?: number | undefined;
|
|
3473
3483
|
}
|
|
3474
3484
|
/**
|
|
3475
|
-
* Unlike the 16
|
|
3476
|
-
* returned by this method has a default `highWaterMark` of 64
|
|
3485
|
+
* Unlike the 16 KiB default `highWaterMark` for a `stream.Readable`, the stream
|
|
3486
|
+
* returned by this method has a default `highWaterMark` of 64 KiB.
|
|
3477
3487
|
*
|
|
3478
3488
|
* `options` can include `start` and `end` values to read a range of bytes from
|
|
3479
3489
|
* the file instead of the entire file. Both `start` and `end` are inclusive and
|
|
@@ -3499,7 +3509,7 @@ declare module 'fs' {
|
|
|
3499
3509
|
* also required.
|
|
3500
3510
|
*
|
|
3501
3511
|
* ```js
|
|
3502
|
-
* import { createReadStream } from 'fs';
|
|
3512
|
+
* import { createReadStream } from 'node:fs';
|
|
3503
3513
|
*
|
|
3504
3514
|
* // Create a stream from some character device.
|
|
3505
3515
|
* const stream = createReadStream('/dev/input/event0');
|
|
@@ -3527,7 +3537,7 @@ declare module 'fs' {
|
|
|
3527
3537
|
* An example to read the last 10 bytes of a file which is 100 bytes long:
|
|
3528
3538
|
*
|
|
3529
3539
|
* ```js
|
|
3530
|
-
* import { createReadStream } from 'fs';
|
|
3540
|
+
* import { createReadStream } from 'node:fs';
|
|
3531
3541
|
*
|
|
3532
3542
|
* createReadStream('sample.txt', { start: 90, end: 99 });
|
|
3533
3543
|
* ```
|
|
@@ -3551,7 +3561,7 @@ declare module 'fs' {
|
|
|
3551
3561
|
* By default, the stream will emit a `'close'` event after it has been
|
|
3552
3562
|
* destroyed. Set the `emitClose` option to `false` to change this behavior.
|
|
3553
3563
|
*
|
|
3554
|
-
* By providing the `fs` option it is possible to override the corresponding `fs`implementations for `open`, `write`, `writev
|
|
3564
|
+
* 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
3565
|
* performance as some optimizations (`_writev()`)
|
|
3556
3566
|
* 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
3567
|
* for `open` is also required. If `autoClose` is `true`, an override for `close`is also required.
|
|
@@ -3606,7 +3616,7 @@ declare module 'fs' {
|
|
|
3606
3616
|
* copy-on-write, then the operation will fail.
|
|
3607
3617
|
*
|
|
3608
3618
|
* ```js
|
|
3609
|
-
* import { copyFile, constants } from 'fs';
|
|
3619
|
+
* import { copyFile, constants } from 'node:fs';
|
|
3610
3620
|
*
|
|
3611
3621
|
* function callback(err) {
|
|
3612
3622
|
* if (err) throw err;
|
|
@@ -3649,7 +3659,7 @@ declare module 'fs' {
|
|
|
3649
3659
|
* copy-on-write, then the operation will fail.
|
|
3650
3660
|
*
|
|
3651
3661
|
* ```js
|
|
3652
|
-
* import { copyFileSync, constants } from 'fs';
|
|
3662
|
+
* import { copyFileSync, constants } from 'node:fs';
|
|
3653
3663
|
*
|
|
3654
3664
|
* // destination.txt will be created or overwritten by default.
|
|
3655
3665
|
* copyFileSync('source.txt', 'destination.txt');
|
|
@@ -3682,6 +3692,7 @@ declare module 'fs' {
|
|
|
3682
3692
|
* The kernel ignores the position argument and always appends the data to
|
|
3683
3693
|
* the end of the file.
|
|
3684
3694
|
* @since v12.9.0
|
|
3695
|
+
* @param [position='null']
|
|
3685
3696
|
*/
|
|
3686
3697
|
export function writev(fd: number, buffers: ReadonlyArray<NodeJS.ArrayBufferView>, cb: (err: NodeJS.ErrnoException | null, bytesWritten: number, buffers: NodeJS.ArrayBufferView[]) => void): void;
|
|
3687
3698
|
export function writev(
|
|
@@ -3701,6 +3712,7 @@ declare module 'fs' {
|
|
|
3701
3712
|
* For detailed information, see the documentation of the asynchronous version of
|
|
3702
3713
|
* this API: {@link writev}.
|
|
3703
3714
|
* @since v12.9.0
|
|
3715
|
+
* @param [position='null']
|
|
3704
3716
|
* @return The number of bytes written.
|
|
3705
3717
|
*/
|
|
3706
3718
|
export function writevSync(fd: number, buffers: ReadonlyArray<NodeJS.ArrayBufferView>, position?: number): number;
|
|
@@ -3717,6 +3729,7 @@ declare module 'fs' {
|
|
|
3717
3729
|
* If this method is invoked as its `util.promisify()` ed version, it returns
|
|
3718
3730
|
* a promise for an `Object` with `bytesRead` and `buffers` properties.
|
|
3719
3731
|
* @since v13.13.0, v12.17.0
|
|
3732
|
+
* @param [position='null']
|
|
3720
3733
|
*/
|
|
3721
3734
|
export function readv(fd: number, buffers: ReadonlyArray<NodeJS.ArrayBufferView>, cb: (err: NodeJS.ErrnoException | null, bytesRead: number, buffers: NodeJS.ArrayBufferView[]) => void): void;
|
|
3722
3735
|
export function readv(
|
|
@@ -3736,6 +3749,7 @@ declare module 'fs' {
|
|
|
3736
3749
|
* For detailed information, see the documentation of the asynchronous version of
|
|
3737
3750
|
* this API: {@link readv}.
|
|
3738
3751
|
* @since v13.13.0, v12.17.0
|
|
3752
|
+
* @param [position='null']
|
|
3739
3753
|
* @return The number of bytes read.
|
|
3740
3754
|
*/
|
|
3741
3755
|
export function readvSync(fd: number, buffers: ReadonlyArray<NodeJS.ArrayBufferView>, position?: number): number;
|