@node-red/editor-client 3.0.2 → 3.1.0-beta.2

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