@rio-cloud/cdk-v2-constructs 8.2.0 → 8.2.1-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (179) hide show
  1. package/.jsii +2 -2
  2. package/node_modules/@types/node/README.md +3 -3
  3. package/node_modules/@types/node/assert/strict.d.ts +105 -2
  4. package/node_modules/@types/node/assert.d.ts +211 -92
  5. package/node_modules/@types/node/async_hooks.d.ts +103 -19
  6. package/node_modules/@types/node/buffer.buffer.d.ts +472 -0
  7. package/node_modules/@types/node/buffer.d.ts +88 -516
  8. package/node_modules/@types/node/child_process.d.ts +167 -231
  9. package/node_modules/@types/node/cluster.d.ts +172 -26
  10. package/node_modules/@types/node/compatibility/iterators.d.ts +21 -0
  11. package/node_modules/@types/node/console.d.ts +66 -28
  12. package/node_modules/@types/node/constants.d.ts +14 -12
  13. package/node_modules/@types/node/crypto.d.ts +1458 -497
  14. package/node_modules/@types/node/dgram.d.ts +44 -30
  15. package/node_modules/@types/node/diagnostics_channel.d.ts +389 -4
  16. package/node_modules/@types/node/dns/promises.d.ts +120 -42
  17. package/node_modules/@types/node/dns.d.ts +209 -95
  18. package/node_modules/@types/node/domain.d.ts +14 -18
  19. package/node_modules/@types/node/events.d.ts +245 -113
  20. package/node_modules/@types/node/fs/promises.d.ts +194 -96
  21. package/node_modules/@types/node/fs.d.ts +695 -270
  22. package/node_modules/@types/node/globals.d.ts +97 -308
  23. package/node_modules/@types/node/globals.typedarray.d.ts +41 -0
  24. package/node_modules/@types/node/http.d.ts +363 -97
  25. package/node_modules/@types/node/http2.d.ts +684 -231
  26. package/node_modules/@types/node/https.d.ts +122 -87
  27. package/node_modules/@types/node/index.d.ts +24 -11
  28. package/node_modules/@types/node/inspector.d.ts +220 -2690
  29. package/node_modules/@types/node/inspector.generated.d.ts +4239 -0
  30. package/node_modules/@types/node/module.d.ts +705 -149
  31. package/node_modules/@types/node/net.d.ts +178 -54
  32. package/node_modules/@types/node/os.d.ts +47 -17
  33. package/node_modules/@types/node/package.json +22 -97
  34. package/node_modules/@types/node/path.d.ts +12 -3
  35. package/node_modules/@types/node/perf_hooks.d.ts +500 -97
  36. package/node_modules/@types/node/process.d.ts +657 -87
  37. package/node_modules/@types/node/punycode.d.ts +5 -5
  38. package/node_modules/@types/node/querystring.d.ts +24 -13
  39. package/node_modules/@types/node/readline/promises.d.ts +25 -14
  40. package/node_modules/@types/node/readline.d.ts +102 -41
  41. package/node_modules/@types/node/repl.d.ts +38 -30
  42. package/node_modules/@types/node/sea.d.ts +162 -0
  43. package/node_modules/@types/node/sqlite.d.ts +1040 -0
  44. package/node_modules/@types/node/stream/consumers.d.ts +33 -7
  45. package/node_modules/@types/node/stream/promises.d.ts +8 -1
  46. package/node_modules/@types/node/stream/web.d.ts +251 -28
  47. package/node_modules/@types/node/stream.d.ts +1060 -1055
  48. package/node_modules/@types/node/string_decoder.d.ts +8 -8
  49. package/node_modules/@types/node/test.d.ts +2133 -1166
  50. package/node_modules/@types/node/timers/promises.d.ts +31 -16
  51. package/node_modules/@types/node/timers.d.ts +159 -114
  52. package/node_modules/@types/node/tls.d.ts +232 -163
  53. package/node_modules/@types/node/trace_events.d.ts +43 -28
  54. package/node_modules/@types/node/ts5.6/buffer.buffer.d.ts +468 -0
  55. package/node_modules/@types/node/ts5.6/compatibility/float16array.d.ts +71 -0
  56. package/node_modules/@types/node/ts5.6/globals.typedarray.d.ts +36 -0
  57. package/node_modules/@types/node/ts5.6/index.d.ts +103 -0
  58. package/node_modules/@types/node/ts5.7/compatibility/float16array.d.ts +72 -0
  59. package/node_modules/@types/node/ts5.7/index.d.ts +103 -0
  60. package/node_modules/@types/node/tty.d.ts +9 -9
  61. package/node_modules/@types/node/url.d.ts +236 -84
  62. package/node_modules/@types/node/util.d.ts +562 -412
  63. package/node_modules/@types/node/v8.d.ts +368 -21
  64. package/node_modules/@types/node/vm.d.ts +443 -149
  65. package/node_modules/@types/node/wasi.d.ts +62 -18
  66. package/node_modules/@types/node/web-globals/abortcontroller.d.ts +34 -0
  67. package/node_modules/@types/node/web-globals/crypto.d.ts +32 -0
  68. package/node_modules/@types/node/web-globals/domexception.d.ts +68 -0
  69. package/node_modules/@types/node/web-globals/events.d.ts +97 -0
  70. package/node_modules/@types/node/web-globals/fetch.d.ts +62 -0
  71. package/node_modules/@types/node/web-globals/navigator.d.ts +25 -0
  72. package/node_modules/@types/node/web-globals/storage.d.ts +24 -0
  73. package/node_modules/@types/node/web-globals/streams.d.ts +22 -0
  74. package/node_modules/@types/node/worker_threads.d.ts +310 -107
  75. package/node_modules/@types/node/zlib.d.ts +301 -73
  76. package/node_modules/undici-types/LICENSE +21 -0
  77. package/node_modules/undici-types/agent.d.ts +13 -12
  78. package/node_modules/undici-types/api.d.ts +26 -26
  79. package/node_modules/undici-types/balanced-pool.d.ts +19 -7
  80. package/node_modules/undici-types/cache-interceptor.d.ts +173 -0
  81. package/node_modules/undici-types/client-stats.d.ts +15 -0
  82. package/node_modules/undici-types/client.d.ts +26 -15
  83. package/node_modules/undici-types/connector.d.ts +2 -2
  84. package/node_modules/undici-types/cookies.d.ts +2 -0
  85. package/node_modules/undici-types/diagnostics-channel.d.ts +19 -12
  86. package/node_modules/undici-types/dispatcher.d.ts +148 -113
  87. package/node_modules/undici-types/env-http-proxy-agent.d.ts +22 -0
  88. package/node_modules/undici-types/errors.d.ts +79 -46
  89. package/node_modules/undici-types/eventsource.d.ts +66 -0
  90. package/node_modules/undici-types/fetch.d.ts +41 -39
  91. package/node_modules/undici-types/formdata.d.ts +8 -8
  92. package/node_modules/undici-types/global-dispatcher.d.ts +4 -4
  93. package/node_modules/undici-types/global-origin.d.ts +5 -5
  94. package/node_modules/undici-types/h2c-client.d.ts +73 -0
  95. package/node_modules/undici-types/handlers.d.ts +11 -5
  96. package/node_modules/undici-types/header.d.ts +157 -1
  97. package/node_modules/undici-types/index.d.ts +68 -43
  98. package/node_modules/undici-types/interceptors.d.ts +71 -3
  99. package/node_modules/undici-types/mock-agent.d.ts +36 -18
  100. package/node_modules/undici-types/mock-call-history.d.ts +111 -0
  101. package/node_modules/undici-types/mock-client.d.ts +6 -4
  102. package/node_modules/undici-types/mock-errors.d.ts +3 -3
  103. package/node_modules/undici-types/mock-interceptor.d.ts +24 -23
  104. package/node_modules/undici-types/mock-pool.d.ts +6 -4
  105. package/node_modules/undici-types/package.json +1 -1
  106. package/node_modules/undici-types/patch.d.ts +0 -42
  107. package/node_modules/undici-types/pool-stats.d.ts +8 -8
  108. package/node_modules/undici-types/pool.d.ts +21 -8
  109. package/node_modules/undici-types/proxy-agent.d.ts +5 -6
  110. package/node_modules/undici-types/readable.d.ts +24 -17
  111. package/node_modules/undici-types/retry-agent.d.ts +8 -0
  112. package/node_modules/undici-types/retry-handler.d.ts +125 -0
  113. package/node_modules/undici-types/round-robin-pool.d.ts +41 -0
  114. package/node_modules/undici-types/snapshot-agent.d.ts +109 -0
  115. package/node_modules/undici-types/util.d.ts +18 -0
  116. package/node_modules/undici-types/utility.d.ts +7 -0
  117. package/node_modules/undici-types/webidl.d.ts +157 -36
  118. package/node_modules/undici-types/websocket.d.ts +67 -12
  119. package/package.json +9 -60
  120. package/version.json +1 -1
  121. package/node_modules/@types/node/dom-events.d.ts +0 -122
  122. package/node_modules/@types/node/globals.global.d.ts +0 -1
  123. package/node_modules/@types/node/ts4.8/assert/strict.d.ts +0 -8
  124. package/node_modules/@types/node/ts4.8/assert.d.ts +0 -996
  125. package/node_modules/@types/node/ts4.8/async_hooks.d.ts +0 -539
  126. package/node_modules/@types/node/ts4.8/buffer.d.ts +0 -2362
  127. package/node_modules/@types/node/ts4.8/child_process.d.ts +0 -1540
  128. package/node_modules/@types/node/ts4.8/cluster.d.ts +0 -432
  129. package/node_modules/@types/node/ts4.8/console.d.ts +0 -415
  130. package/node_modules/@types/node/ts4.8/constants.d.ts +0 -19
  131. package/node_modules/@types/node/ts4.8/crypto.d.ts +0 -4455
  132. package/node_modules/@types/node/ts4.8/dgram.d.ts +0 -586
  133. package/node_modules/@types/node/ts4.8/diagnostics_channel.d.ts +0 -191
  134. package/node_modules/@types/node/ts4.8/dns/promises.d.ts +0 -425
  135. package/node_modules/@types/node/ts4.8/dns.d.ts +0 -809
  136. package/node_modules/@types/node/ts4.8/dom-events.d.ts +0 -122
  137. package/node_modules/@types/node/ts4.8/domain.d.ts +0 -170
  138. package/node_modules/@types/node/ts4.8/events.d.ts +0 -796
  139. package/node_modules/@types/node/ts4.8/fs/promises.d.ts +0 -1232
  140. package/node_modules/@types/node/ts4.8/fs.d.ts +0 -4289
  141. package/node_modules/@types/node/ts4.8/globals.d.ts +0 -381
  142. package/node_modules/@types/node/ts4.8/globals.global.d.ts +0 -1
  143. package/node_modules/@types/node/ts4.8/http.d.ts +0 -1888
  144. package/node_modules/@types/node/ts4.8/http2.d.ts +0 -2382
  145. package/node_modules/@types/node/ts4.8/https.d.ts +0 -550
  146. package/node_modules/@types/node/ts4.8/index.d.ts +0 -88
  147. package/node_modules/@types/node/ts4.8/inspector.d.ts +0 -2747
  148. package/node_modules/@types/node/ts4.8/module.d.ts +0 -287
  149. package/node_modules/@types/node/ts4.8/net.d.ts +0 -949
  150. package/node_modules/@types/node/ts4.8/os.d.ts +0 -477
  151. package/node_modules/@types/node/ts4.8/path.d.ts +0 -191
  152. package/node_modules/@types/node/ts4.8/perf_hooks.d.ts +0 -639
  153. package/node_modules/@types/node/ts4.8/process.d.ts +0 -1532
  154. package/node_modules/@types/node/ts4.8/punycode.d.ts +0 -117
  155. package/node_modules/@types/node/ts4.8/querystring.d.ts +0 -141
  156. package/node_modules/@types/node/ts4.8/readline/promises.d.ts +0 -150
  157. package/node_modules/@types/node/ts4.8/readline.d.ts +0 -539
  158. package/node_modules/@types/node/ts4.8/repl.d.ts +0 -430
  159. package/node_modules/@types/node/ts4.8/stream/consumers.d.ts +0 -12
  160. package/node_modules/@types/node/ts4.8/stream/promises.d.ts +0 -83
  161. package/node_modules/@types/node/ts4.8/stream/web.d.ts +0 -350
  162. package/node_modules/@types/node/ts4.8/stream.d.ts +0 -1701
  163. package/node_modules/@types/node/ts4.8/string_decoder.d.ts +0 -67
  164. package/node_modules/@types/node/ts4.8/test.d.ts +0 -1382
  165. package/node_modules/@types/node/ts4.8/timers/promises.d.ts +0 -93
  166. package/node_modules/@types/node/ts4.8/timers.d.ts +0 -240
  167. package/node_modules/@types/node/ts4.8/tls.d.ts +0 -1210
  168. package/node_modules/@types/node/ts4.8/trace_events.d.ts +0 -182
  169. package/node_modules/@types/node/ts4.8/tty.d.ts +0 -208
  170. package/node_modules/@types/node/ts4.8/url.d.ts +0 -927
  171. package/node_modules/@types/node/ts4.8/util.d.ts +0 -2186
  172. package/node_modules/@types/node/ts4.8/v8.d.ts +0 -635
  173. package/node_modules/@types/node/ts4.8/vm.d.ts +0 -901
  174. package/node_modules/@types/node/ts4.8/wasi.d.ts +0 -158
  175. package/node_modules/@types/node/ts4.8/worker_threads.d.ts +0 -691
  176. package/node_modules/@types/node/ts4.8/zlib.d.ts +0 -517
  177. package/node_modules/argparse/CHANGELOG.md +0 -216
  178. package/node_modules/undici-types/file.d.ts +0 -39
  179. package/node_modules/undici-types/filereader.d.ts +0 -54
@@ -16,9 +16,10 @@
16
16
  *
17
17
  * All file system operations have synchronous, callback, and promise-based
18
18
  * forms, and are accessible using both CommonJS syntax and ES6 Modules (ESM).
19
- * @see [source](https://github.com/nodejs/node/blob/v20.2.0/lib/fs.js)
19
+ * @see [source](https://github.com/nodejs/node/blob/v24.x/lib/fs.js)
20
20
  */
21
21
  declare module "fs" {
22
+ import { NonSharedBuffer } from "node:buffer";
22
23
  import * as stream from "node:stream";
23
24
  import { Abortable, EventEmitter } from "node:events";
24
25
  import { URL } from "node:url";
@@ -77,7 +78,7 @@ declare module "fs" {
77
78
  * their synchronous counterparts are of this type.
78
79
  * If `bigint` in the `options` passed to those methods is true, the numeric values
79
80
  * will be `bigint` instead of `number`, and the object will contain additional
80
- * nanosecond-precision properties suffixed with `Ns`.
81
+ * nanosecond-precision properties suffixed with `Ns`. `Stat` objects are not to be created directly using the `new` keyword.
81
82
  *
82
83
  * ```console
83
84
  * Stats {
@@ -130,7 +131,9 @@ declare module "fs" {
130
131
  * ```
131
132
  * @since v0.1.21
132
133
  */
133
- export class Stats {}
134
+ export class Stats {
135
+ private constructor();
136
+ }
134
137
  export interface StatsFsBase<T> {
135
138
  /** Type of file system. */
136
139
  type: T;
@@ -196,7 +199,7 @@ declare module "fs" {
196
199
  * the `withFileTypes` option set to `true`, the resulting array is filled with `fs.Dirent` objects, rather than strings or `Buffer` s.
197
200
  * @since v10.10.0
198
201
  */
199
- export class Dirent {
202
+ export class Dirent<Name extends string | Buffer = string> {
200
203
  /**
201
204
  * Returns `true` if the `fs.Dirent` object describes a regular file.
202
205
  * @since v10.10.0
@@ -239,12 +242,12 @@ declare module "fs" {
239
242
  * value is determined by the `options.encoding` passed to {@link readdir} or {@link readdirSync}.
240
243
  * @since v10.10.0
241
244
  */
242
- name: string;
245
+ name: Name;
243
246
  /**
244
- * The base path that this `fs.Dirent` object refers to.
245
- * @since v20.1.0
247
+ * The path to the parent directory of the file this `fs.Dirent` object refers to.
248
+ * @since v20.12.0, v18.20.0
246
249
  */
247
- path: string;
250
+ parentPath: string;
248
251
  }
249
252
  /**
250
253
  * A class representing a directory stream.
@@ -276,12 +279,12 @@ declare module "fs" {
276
279
  /**
277
280
  * Asynchronously iterates over the directory via `readdir(3)` until all entries have been read.
278
281
  */
279
- [Symbol.asyncIterator](): AsyncIterableIterator<Dirent>;
282
+ [Symbol.asyncIterator](): NodeJS.AsyncIterator<Dirent>;
280
283
  /**
281
284
  * Asynchronously close the directory's underlying resource handle.
282
285
  * Subsequent reads will result in errors.
283
286
  *
284
- * A promise is returned that will be resolved after the resource has been
287
+ * A promise is returned that will be fulfilled after the resource has been
285
288
  * closed.
286
289
  * @since v12.12.0
287
290
  */
@@ -296,7 +299,7 @@ declare module "fs" {
296
299
  /**
297
300
  * Asynchronously read the next directory entry via [`readdir(3)`](http://man7.org/linux/man-pages/man3/readdir.3.html) as an `fs.Dirent`.
298
301
  *
299
- * A promise is returned that will be resolved with an `fs.Dirent`, or `null`if there are no more directory entries to read.
302
+ * A promise is returned that will be fulfilled with an `fs.Dirent`, or `null` if there are no more directory entries to read.
300
303
  *
301
304
  * Directory entries returned by this function are in no particular order as
302
305
  * provided by the operating system's underlying directory mechanisms.
@@ -320,6 +323,18 @@ declare module "fs" {
320
323
  * @since v12.12.0
321
324
  */
322
325
  readSync(): Dirent | null;
326
+ /**
327
+ * Calls `dir.close()` if the directory handle is open, and returns a promise that
328
+ * fulfills when disposal is complete.
329
+ * @since v24.1.0
330
+ */
331
+ [Symbol.asyncDispose](): Promise<void>;
332
+ /**
333
+ * Calls `dir.closeSync()` if the directory handle is open, and returns
334
+ * `undefined`.
335
+ * @since v24.1.0
336
+ */
337
+ [Symbol.dispose](): void;
323
338
  }
324
339
  /**
325
340
  * Class: fs.StatWatcher
@@ -354,31 +369,57 @@ declare module "fs" {
354
369
  * @since v0.5.8
355
370
  */
356
371
  close(): void;
372
+ /**
373
+ * When called, requests that the Node.js event loop _not_ exit so long as the `fs.FSWatcher` is active. Calling `watcher.ref()` multiple times will have
374
+ * no effect.
375
+ *
376
+ * By default, all `fs.FSWatcher` objects are "ref'ed", making it normally
377
+ * unnecessary to call `watcher.ref()` unless `watcher.unref()` had been
378
+ * called previously.
379
+ * @since v14.3.0, v12.20.0
380
+ */
381
+ ref(): this;
382
+ /**
383
+ * When called, the active `fs.FSWatcher` object will not require the Node.js
384
+ * event loop to remain active. If there is no other activity keeping the
385
+ * event loop running, the process may exit before the `fs.FSWatcher` object's
386
+ * callback is invoked. Calling `watcher.unref()` multiple times will have
387
+ * no effect.
388
+ * @since v14.3.0, v12.20.0
389
+ */
390
+ unref(): this;
357
391
  /**
358
392
  * events.EventEmitter
359
393
  * 1. change
360
- * 2. error
394
+ * 2. close
395
+ * 3. error
361
396
  */
362
397
  addListener(event: string, listener: (...args: any[]) => void): this;
363
- addListener(event: "change", listener: (eventType: string, filename: string | Buffer) => void): this;
364
- addListener(event: "error", listener: (error: Error) => void): this;
398
+ addListener(event: "change", listener: (eventType: string, filename: string | NonSharedBuffer) => void): this;
365
399
  addListener(event: "close", listener: () => void): this;
400
+ addListener(event: "error", listener: (error: Error) => void): this;
366
401
  on(event: string, listener: (...args: any[]) => void): this;
367
- on(event: "change", listener: (eventType: string, filename: string | Buffer) => void): this;
368
- on(event: "error", listener: (error: Error) => void): this;
402
+ on(event: "change", listener: (eventType: string, filename: string | NonSharedBuffer) => void): this;
369
403
  on(event: "close", listener: () => void): this;
404
+ on(event: "error", listener: (error: Error) => void): this;
370
405
  once(event: string, listener: (...args: any[]) => void): this;
371
- once(event: "change", listener: (eventType: string, filename: string | Buffer) => void): this;
372
- once(event: "error", listener: (error: Error) => void): this;
406
+ once(event: "change", listener: (eventType: string, filename: string | NonSharedBuffer) => void): this;
373
407
  once(event: "close", listener: () => void): this;
408
+ once(event: "error", listener: (error: Error) => void): this;
374
409
  prependListener(event: string, listener: (...args: any[]) => void): this;
375
- prependListener(event: "change", listener: (eventType: string, filename: string | Buffer) => void): this;
376
- prependListener(event: "error", listener: (error: Error) => void): this;
410
+ prependListener(
411
+ event: "change",
412
+ listener: (eventType: string, filename: string | NonSharedBuffer) => void,
413
+ ): this;
377
414
  prependListener(event: "close", listener: () => void): this;
415
+ prependListener(event: "error", listener: (error: Error) => void): this;
378
416
  prependOnceListener(event: string, listener: (...args: any[]) => void): this;
379
- prependOnceListener(event: "change", listener: (eventType: string, filename: string | Buffer) => void): this;
380
- prependOnceListener(event: "error", listener: (error: Error) => void): this;
417
+ prependOnceListener(
418
+ event: "change",
419
+ listener: (eventType: string, filename: string | NonSharedBuffer) => void,
420
+ ): this;
381
421
  prependOnceListener(event: "close", listener: () => void): this;
422
+ prependOnceListener(event: "error", listener: (error: Error) => void): this;
382
423
  }
383
424
  /**
384
425
  * Instances of `fs.ReadStream` are created and returned using the {@link createReadStream} function.
@@ -410,57 +451,271 @@ declare module "fs" {
410
451
  * 2. close
411
452
  * 3. ready
412
453
  */
454
+ addListener<K extends keyof ReadStreamEvents>(event: K, listener: ReadStreamEvents[K]): this;
455
+ on<K extends keyof ReadStreamEvents>(event: K, listener: ReadStreamEvents[K]): this;
456
+ once<K extends keyof ReadStreamEvents>(event: K, listener: ReadStreamEvents[K]): this;
457
+ prependListener<K extends keyof ReadStreamEvents>(event: K, listener: ReadStreamEvents[K]): this;
458
+ prependOnceListener<K extends keyof ReadStreamEvents>(event: K, listener: ReadStreamEvents[K]): this;
459
+ }
460
+ export interface Utf8StreamOptions {
461
+ /**
462
+ * Appends writes to dest file instead of truncating it.
463
+ * @default true
464
+ */
465
+ append?: boolean | undefined;
466
+ /**
467
+ * Which type of data you can send to the write
468
+ * function, supported values are `'utf8'` or `'buffer'`.
469
+ * @default 'utf8'
470
+ */
471
+ contentMode?: "utf8" | "buffer" | undefined;
472
+ /**
473
+ * A path to a file to be written to (mode controlled by the
474
+ * append option).
475
+ */
476
+ dest?: string | undefined;
477
+ /**
478
+ * A file descriptor, something that is returned by `fs.open()`
479
+ * or `fs.openSync()`.
480
+ */
481
+ fd?: number | undefined;
482
+ /**
483
+ * An object that has the same API as the `fs` module, useful
484
+ * for mocking, testing, or customizing the behavior of the stream.
485
+ */
486
+ fs?: object | undefined;
487
+ /**
488
+ * Perform a `fs.fsyncSync()` every time a write is
489
+ * completed.
490
+ */
491
+ fsync?: boolean | undefined;
492
+ /**
493
+ * The maximum length of the internal buffer. If a write
494
+ * operation would cause the buffer to exceed `maxLength`, the data written is
495
+ * dropped and a drop event is emitted with the dropped data
496
+ */
497
+ maxLength?: number | undefined;
498
+ /**
499
+ * The maximum number of bytes that can be written;
500
+ * @default 16384
501
+ */
502
+ maxWrite?: number | undefined;
503
+ /**
504
+ * The minimum length of the internal buffer that is
505
+ * required to be full before flushing.
506
+ */
507
+ minLength?: number | undefined;
508
+ /**
509
+ * Ensure directory for `dest` file exists when true.
510
+ * @default false
511
+ */
512
+ mkdir?: boolean | undefined;
513
+ /**
514
+ * Specify the creating file mode (see `fs.open()`).
515
+ */
516
+ mode?: number | string | undefined;
517
+ /**
518
+ * Calls flush every `periodicFlush` milliseconds.
519
+ */
520
+ periodicFlush?: number | undefined;
521
+ /**
522
+ * A function that will be called when `write()`,
523
+ * `writeSync()`, or `flushSync()` encounters an `EAGAIN` or `EBUSY` error.
524
+ * If the return value is `true` the operation will be retried, otherwise it
525
+ * will bubble the error. The `err` is the error that caused this function to
526
+ * be called, `writeBufferLen` is the length of the buffer that was written,
527
+ * and `remainingBufferLen` is the length of the remaining buffer that the
528
+ * stream did not try to write.
529
+ */
530
+ retryEAGAIN?: ((err: Error | null, writeBufferLen: number, remainingBufferLen: number) => boolean) | undefined;
531
+ /**
532
+ * Perform writes synchronously.
533
+ */
534
+ sync?: boolean | undefined;
535
+ }
536
+ /**
537
+ * An optimized UTF-8 stream writer that allows for flushing all the internal
538
+ * buffering on demand. It handles `EAGAIN` errors correctly, allowing for
539
+ * customization, for example, by dropping content if the disk is busy.
540
+ * @since v24.6.0
541
+ * @experimental
542
+ */
543
+ export class Utf8Stream extends EventEmitter {
544
+ constructor(options: Utf8StreamOptions);
545
+ /**
546
+ * Whether the stream is appending to the file or truncating it.
547
+ */
548
+ readonly append: boolean;
549
+ /**
550
+ * The type of data that can be written to the stream. Supported
551
+ * values are `'utf8'` or `'buffer'`.
552
+ * @default 'utf8'
553
+ */
554
+ readonly contentMode: "utf8" | "buffer";
555
+ /**
556
+ * Close the stream immediately, without flushing the internal buffer.
557
+ */
558
+ destroy(): void;
559
+ /**
560
+ * Close the stream gracefully, flushing the internal buffer before closing.
561
+ */
562
+ end(): void;
563
+ /**
564
+ * The file descriptor that is being written to.
565
+ */
566
+ readonly fd: number;
567
+ /**
568
+ * The file that is being written to.
569
+ */
570
+ readonly file: string;
571
+ /**
572
+ * Writes the current buffer to the file if a write was not in progress. Do
573
+ * nothing if `minLength` is zero or if it is already writing.
574
+ */
575
+ flush(callback: (err: Error | null) => void): void;
576
+ /**
577
+ * Flushes the buffered data synchronously. This is a costly operation.
578
+ */
579
+ flushSync(): void;
580
+ /**
581
+ * Whether the stream is performing a `fs.fsyncSync()` after every
582
+ * write operation.
583
+ */
584
+ readonly fsync: boolean;
585
+ /**
586
+ * The maximum length of the internal buffer. If a write
587
+ * operation would cause the buffer to exceed `maxLength`, the data written is
588
+ * dropped and a drop event is emitted with the dropped data.
589
+ */
590
+ readonly maxLength: number;
591
+ /**
592
+ * The minimum length of the internal buffer that is required to be
593
+ * full before flushing.
594
+ */
595
+ readonly minLength: number;
596
+ /**
597
+ * Whether the stream should ensure that the directory for the
598
+ * `dest` file exists. If `true`, it will create the directory if it does not
599
+ * exist.
600
+ * @default false
601
+ */
602
+ readonly mkdir: boolean;
603
+ /**
604
+ * The mode of the file that is being written to.
605
+ */
606
+ readonly mode: number | string;
607
+ /**
608
+ * The number of milliseconds between flushes. If set to `0`, no
609
+ * periodic flushes will be performed.
610
+ */
611
+ readonly periodicFlush: number;
612
+ /**
613
+ * Reopen the file in place, useful for log rotation.
614
+ * @param file A path to a file to be written to (mode
615
+ * controlled by the append option).
616
+ */
617
+ reopen(file: PathLike): void;
618
+ /**
619
+ * Whether the stream is writing synchronously or asynchronously.
620
+ */
621
+ readonly sync: boolean;
622
+ /**
623
+ * When the `options.contentMode` is set to `'utf8'` when the stream is created,
624
+ * the `data` argument must be a string. If the `contentMode` is set to `'buffer'`,
625
+ * the `data` argument must be a `Buffer`.
626
+ * @param data The data to write.
627
+ */
628
+ write(data: string | Buffer): boolean;
629
+ /**
630
+ * Whether the stream is currently writing data to the file.
631
+ */
632
+ readonly writing: boolean;
633
+ /**
634
+ * Calls `utf8Stream.destroy()`.
635
+ */
636
+ [Symbol.dispose](): void;
637
+ /**
638
+ * events.EventEmitter
639
+ * 1. change
640
+ * 2. close
641
+ * 3. error
642
+ */
413
643
  addListener(event: "close", listener: () => void): this;
414
- addListener(event: "data", listener: (chunk: Buffer | string) => void): this;
415
- addListener(event: "end", listener: () => void): this;
416
- addListener(event: "error", listener: (err: Error) => void): this;
417
- addListener(event: "open", listener: (fd: number) => void): this;
418
- addListener(event: "pause", listener: () => void): this;
419
- addListener(event: "readable", listener: () => void): this;
644
+ addListener(event: "drain", listener: () => void): this;
645
+ addListener(event: "drop", listener: (data: string | Buffer) => void): this;
646
+ addListener(event: "error", listener: (error: Error) => void): this;
647
+ addListener(event: "finish", listener: () => void): this;
420
648
  addListener(event: "ready", listener: () => void): this;
421
- addListener(event: "resume", listener: () => void): this;
422
- addListener(event: string | symbol, listener: (...args: any[]) => void): this;
649
+ addListener(event: "write", listener: (n: number) => void): this;
650
+ addListener(event: string, listener: (...args: any[]) => void): this;
423
651
  on(event: "close", listener: () => void): this;
424
- on(event: "data", listener: (chunk: Buffer | string) => void): this;
425
- on(event: "end", listener: () => void): this;
426
- on(event: "error", listener: (err: Error) => void): this;
427
- on(event: "open", listener: (fd: number) => void): this;
428
- on(event: "pause", listener: () => void): this;
429
- on(event: "readable", listener: () => void): this;
652
+ on(event: "drain", listener: () => void): this;
653
+ on(event: "drop", listener: (data: string | Buffer) => void): this;
654
+ on(event: "error", listener: (error: Error) => void): this;
655
+ on(event: "finish", listener: () => void): this;
430
656
  on(event: "ready", listener: () => void): this;
431
- on(event: "resume", listener: () => void): this;
432
- on(event: string | symbol, listener: (...args: any[]) => void): this;
657
+ on(event: "write", listener: (n: number) => void): this;
658
+ on(event: string, listener: (...args: any[]) => void): this;
433
659
  once(event: "close", listener: () => void): this;
434
- once(event: "data", listener: (chunk: Buffer | string) => void): this;
435
- once(event: "end", listener: () => void): this;
436
- once(event: "error", listener: (err: Error) => void): this;
437
- once(event: "open", listener: (fd: number) => void): this;
438
- once(event: "pause", listener: () => void): this;
439
- once(event: "readable", listener: () => void): this;
660
+ once(event: "drain", listener: () => void): this;
661
+ once(event: "drop", listener: (data: string | Buffer) => void): this;
662
+ once(event: "error", listener: (error: Error) => void): this;
663
+ once(event: "finish", listener: () => void): this;
440
664
  once(event: "ready", listener: () => void): this;
441
- once(event: "resume", listener: () => void): this;
442
- once(event: string | symbol, listener: (...args: any[]) => void): this;
665
+ once(event: "write", listener: (n: number) => void): this;
666
+ once(event: string, listener: (...args: any[]) => void): this;
443
667
  prependListener(event: "close", listener: () => void): this;
444
- prependListener(event: "data", listener: (chunk: Buffer | string) => void): this;
445
- prependListener(event: "end", listener: () => void): this;
446
- prependListener(event: "error", listener: (err: Error) => void): this;
447
- prependListener(event: "open", listener: (fd: number) => void): this;
448
- prependListener(event: "pause", listener: () => void): this;
449
- prependListener(event: "readable", listener: () => void): this;
668
+ prependListener(event: "drain", listener: () => void): this;
669
+ prependListener(event: "drop", listener: (data: string | Buffer) => void): this;
670
+ prependListener(event: "error", listener: (error: Error) => void): this;
671
+ prependListener(event: "finish", listener: () => void): this;
450
672
  prependListener(event: "ready", listener: () => void): this;
451
- prependListener(event: "resume", listener: () => void): this;
452
- prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
673
+ prependListener(event: "write", listener: (n: number) => void): this;
674
+ prependListener(event: string, listener: (...args: any[]) => void): this;
453
675
  prependOnceListener(event: "close", listener: () => void): this;
454
- prependOnceListener(event: "data", listener: (chunk: Buffer | string) => void): this;
455
- prependOnceListener(event: "end", listener: () => void): this;
456
- prependOnceListener(event: "error", listener: (err: Error) => void): this;
457
- prependOnceListener(event: "open", listener: (fd: number) => void): this;
458
- prependOnceListener(event: "pause", listener: () => void): this;
459
- prependOnceListener(event: "readable", listener: () => void): this;
676
+ prependOnceListener(event: "drain", listener: () => void): this;
677
+ prependOnceListener(event: "drop", listener: (data: string | Buffer) => void): this;
678
+ prependOnceListener(event: "error", listener: (error: Error) => void): this;
679
+ prependOnceListener(event: "finish", listener: () => void): this;
460
680
  prependOnceListener(event: "ready", listener: () => void): this;
461
- prependOnceListener(event: "resume", listener: () => void): this;
462
- prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
681
+ prependOnceListener(event: "write", listener: (n: number) => void): this;
682
+ prependOnceListener(event: string, listener: (...args: any[]) => void): this;
463
683
  }
684
+
685
+ /**
686
+ * The Keys are events of the ReadStream and the values are the functions that are called when the event is emitted.
687
+ */
688
+ type ReadStreamEvents = {
689
+ close: () => void;
690
+ data: (chunk: Buffer | string) => void;
691
+ end: () => void;
692
+ error: (err: Error) => void;
693
+ open: (fd: number) => void;
694
+ pause: () => void;
695
+ readable: () => void;
696
+ ready: () => void;
697
+ resume: () => void;
698
+ } & CustomEvents;
699
+
700
+ /**
701
+ * string & {} allows to allow any kind of strings for the event
702
+ * but still allows to have auto completion for the normal events.
703
+ */
704
+ type CustomEvents = { [Key in string & {} | symbol]: (...args: any[]) => void };
705
+
706
+ /**
707
+ * The Keys are events of the WriteStream and the values are the functions that are called when the event is emitted.
708
+ */
709
+ type WriteStreamEvents = {
710
+ close: () => void;
711
+ drain: () => void;
712
+ error: (err: Error) => void;
713
+ finish: () => void;
714
+ open: (fd: number) => void;
715
+ pipe: (src: stream.Readable) => void;
716
+ ready: () => void;
717
+ unpipe: (src: stream.Readable) => void;
718
+ } & CustomEvents;
464
719
  /**
465
720
  * * Extends `stream.Writable`
466
721
  *
@@ -499,51 +754,11 @@ declare module "fs" {
499
754
  * 2. close
500
755
  * 3. ready
501
756
  */
502
- addListener(event: "close", listener: () => void): this;
503
- addListener(event: "drain", listener: () => void): this;
504
- addListener(event: "error", listener: (err: Error) => void): this;
505
- addListener(event: "finish", listener: () => void): this;
506
- addListener(event: "open", listener: (fd: number) => void): this;
507
- addListener(event: "pipe", listener: (src: stream.Readable) => void): this;
508
- addListener(event: "ready", listener: () => void): this;
509
- addListener(event: "unpipe", listener: (src: stream.Readable) => void): this;
510
- addListener(event: string | symbol, listener: (...args: any[]) => void): this;
511
- on(event: "close", listener: () => void): this;
512
- on(event: "drain", listener: () => void): this;
513
- on(event: "error", listener: (err: Error) => void): this;
514
- on(event: "finish", listener: () => void): this;
515
- on(event: "open", listener: (fd: number) => void): this;
516
- on(event: "pipe", listener: (src: stream.Readable) => void): this;
517
- on(event: "ready", listener: () => void): this;
518
- on(event: "unpipe", listener: (src: stream.Readable) => void): this;
519
- on(event: string | symbol, listener: (...args: any[]) => void): this;
520
- once(event: "close", listener: () => void): this;
521
- once(event: "drain", listener: () => void): this;
522
- once(event: "error", listener: (err: Error) => void): this;
523
- once(event: "finish", listener: () => void): this;
524
- once(event: "open", listener: (fd: number) => void): this;
525
- once(event: "pipe", listener: (src: stream.Readable) => void): this;
526
- once(event: "ready", listener: () => void): this;
527
- once(event: "unpipe", listener: (src: stream.Readable) => void): this;
528
- once(event: string | symbol, listener: (...args: any[]) => void): this;
529
- prependListener(event: "close", listener: () => void): this;
530
- prependListener(event: "drain", listener: () => void): this;
531
- prependListener(event: "error", listener: (err: Error) => void): this;
532
- prependListener(event: "finish", listener: () => void): this;
533
- prependListener(event: "open", listener: (fd: number) => void): this;
534
- prependListener(event: "pipe", listener: (src: stream.Readable) => void): this;
535
- prependListener(event: "ready", listener: () => void): this;
536
- prependListener(event: "unpipe", listener: (src: stream.Readable) => void): this;
537
- prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
538
- prependOnceListener(event: "close", listener: () => void): this;
539
- prependOnceListener(event: "drain", listener: () => void): this;
540
- prependOnceListener(event: "error", listener: (err: Error) => void): this;
541
- prependOnceListener(event: "finish", listener: () => void): this;
542
- prependOnceListener(event: "open", listener: (fd: number) => void): this;
543
- prependOnceListener(event: "pipe", listener: (src: stream.Readable) => void): this;
544
- prependOnceListener(event: "ready", listener: () => void): this;
545
- prependOnceListener(event: "unpipe", listener: (src: stream.Readable) => void): this;
546
- prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
757
+ addListener<K extends keyof WriteStreamEvents>(event: K, listener: WriteStreamEvents[K]): this;
758
+ on<K extends keyof WriteStreamEvents>(event: K, listener: WriteStreamEvents[K]): this;
759
+ once<K extends keyof WriteStreamEvents>(event: K, listener: WriteStreamEvents[K]): this;
760
+ prependListener<K extends keyof WriteStreamEvents>(event: K, listener: WriteStreamEvents[K]): this;
761
+ prependOnceListener<K extends keyof WriteStreamEvents>(event: K, listener: WriteStreamEvents[K]): this;
547
762
  }
548
763
  /**
549
764
  * Asynchronously rename file at `oldPath` to the pathname provided
@@ -603,7 +818,7 @@ declare module "fs" {
603
818
  * @since v0.8.6
604
819
  * @param [len=0]
605
820
  */
606
- export function truncate(path: PathLike, len: number | undefined | null, callback: NoParamCallback): void;
821
+ export function truncate(path: PathLike, len: number | undefined, callback: NoParamCallback): void;
607
822
  /**
608
823
  * Asynchronous truncate(2) - Truncate a file to a specified length.
609
824
  * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
@@ -615,7 +830,7 @@ declare module "fs" {
615
830
  * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
616
831
  * @param len If not specified, defaults to `0`.
617
832
  */
618
- function __promisify__(path: PathLike, len?: number | null): Promise<void>;
833
+ function __promisify__(path: PathLike, len?: number): Promise<void>;
619
834
  }
620
835
  /**
621
836
  * Truncates the file. Returns `undefined`. A file descriptor can also be
@@ -626,7 +841,7 @@ declare module "fs" {
626
841
  * @since v0.8.6
627
842
  * @param [len=0]
628
843
  */
629
- export function truncateSync(path: PathLike, len?: number | null): void;
844
+ export function truncateSync(path: PathLike, len?: number): void;
630
845
  /**
631
846
  * Truncates the file descriptor. No arguments other than a possible exception are
632
847
  * given to the completion callback.
@@ -670,7 +885,7 @@ declare module "fs" {
670
885
  * @since v0.8.6
671
886
  * @param [len=0]
672
887
  */
673
- export function ftruncate(fd: number, len: number | undefined | null, callback: NoParamCallback): void;
888
+ export function ftruncate(fd: number, len: number | undefined, callback: NoParamCallback): void;
674
889
  /**
675
890
  * Asynchronous ftruncate(2) - Truncate a file to a specified length.
676
891
  * @param fd A file descriptor.
@@ -682,7 +897,7 @@ declare module "fs" {
682
897
  * @param fd A file descriptor.
683
898
  * @param len If not specified, defaults to `0`.
684
899
  */
685
- function __promisify__(fd: number, len?: number | null): Promise<void>;
900
+ function __promisify__(fd: number, len?: number): Promise<void>;
686
901
  }
687
902
  /**
688
903
  * Truncates the file descriptor. Returns `undefined`.
@@ -692,7 +907,7 @@ declare module "fs" {
692
907
  * @since v0.8.6
693
908
  * @param [len=0]
694
909
  */
695
- export function ftruncateSync(fd: number, len?: number | null): void;
910
+ export function ftruncateSync(fd: number, len?: number): void;
696
911
  /**
697
912
  * Asynchronously changes owner and group of a file. No arguments other than a
698
913
  * possible exception are given to the completion callback.
@@ -1342,7 +1557,7 @@ declare module "fs" {
1342
1557
  export function readlink(
1343
1558
  path: PathLike,
1344
1559
  options: BufferEncodingOption,
1345
- callback: (err: NodeJS.ErrnoException | null, linkString: Buffer) => void,
1560
+ callback: (err: NodeJS.ErrnoException | null, linkString: NonSharedBuffer) => void,
1346
1561
  ): void;
1347
1562
  /**
1348
1563
  * Asynchronous readlink(2) - read value of a symbolic link.
@@ -1352,7 +1567,7 @@ declare module "fs" {
1352
1567
  export function readlink(
1353
1568
  path: PathLike,
1354
1569
  options: EncodingOption,
1355
- callback: (err: NodeJS.ErrnoException | null, linkString: string | Buffer) => void,
1570
+ callback: (err: NodeJS.ErrnoException | null, linkString: string | NonSharedBuffer) => void,
1356
1571
  ): void;
1357
1572
  /**
1358
1573
  * Asynchronous readlink(2) - read value of a symbolic link.
@@ -1374,13 +1589,13 @@ declare module "fs" {
1374
1589
  * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1375
1590
  * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
1376
1591
  */
1377
- function __promisify__(path: PathLike, options: BufferEncodingOption): Promise<Buffer>;
1592
+ function __promisify__(path: PathLike, options: BufferEncodingOption): Promise<NonSharedBuffer>;
1378
1593
  /**
1379
1594
  * Asynchronous readlink(2) - read value of a symbolic link.
1380
1595
  * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1381
1596
  * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
1382
1597
  */
1383
- function __promisify__(path: PathLike, options?: EncodingOption): Promise<string | Buffer>;
1598
+ function __promisify__(path: PathLike, options?: EncodingOption): Promise<string | NonSharedBuffer>;
1384
1599
  }
1385
1600
  /**
1386
1601
  * Returns the symbolic link's string value.
@@ -1399,13 +1614,13 @@ declare module "fs" {
1399
1614
  * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1400
1615
  * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
1401
1616
  */
1402
- export function readlinkSync(path: PathLike, options: BufferEncodingOption): Buffer;
1617
+ export function readlinkSync(path: PathLike, options: BufferEncodingOption): NonSharedBuffer;
1403
1618
  /**
1404
1619
  * Synchronous readlink(2) - read value of a symbolic link.
1405
1620
  * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1406
1621
  * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
1407
1622
  */
1408
- export function readlinkSync(path: PathLike, options?: EncodingOption): string | Buffer;
1623
+ export function readlinkSync(path: PathLike, options?: EncodingOption): string | NonSharedBuffer;
1409
1624
  /**
1410
1625
  * Asynchronously computes the canonical pathname by resolving `.`, `..`, and
1411
1626
  * symbolic links.
@@ -1419,7 +1634,7 @@ declare module "fs" {
1419
1634
  * 2. The maximum number of symbolic links is platform-independent and generally
1420
1635
  * (much) higher than what the native [`realpath(3)`](http://man7.org/linux/man-pages/man3/realpath.3.html) implementation supports.
1421
1636
  *
1422
- * The `callback` gets two arguments `(err, resolvedPath)`. May use `process.cwd`to resolve relative paths.
1637
+ * The `callback` gets two arguments `(err, resolvedPath)`. May use `process.cwd` to resolve relative paths.
1423
1638
  *
1424
1639
  * Only paths that can be converted to UTF8 strings are supported.
1425
1640
  *
@@ -1445,7 +1660,7 @@ declare module "fs" {
1445
1660
  export function realpath(
1446
1661
  path: PathLike,
1447
1662
  options: BufferEncodingOption,
1448
- callback: (err: NodeJS.ErrnoException | null, resolvedPath: Buffer) => void,
1663
+ callback: (err: NodeJS.ErrnoException | null, resolvedPath: NonSharedBuffer) => void,
1449
1664
  ): void;
1450
1665
  /**
1451
1666
  * Asynchronous realpath(3) - return the canonicalized absolute pathname.
@@ -1455,7 +1670,7 @@ declare module "fs" {
1455
1670
  export function realpath(
1456
1671
  path: PathLike,
1457
1672
  options: EncodingOption,
1458
- callback: (err: NodeJS.ErrnoException | null, resolvedPath: string | Buffer) => void,
1673
+ callback: (err: NodeJS.ErrnoException | null, resolvedPath: string | NonSharedBuffer) => void,
1459
1674
  ): void;
1460
1675
  /**
1461
1676
  * Asynchronous realpath(3) - return the canonicalized absolute pathname.
@@ -1477,13 +1692,13 @@ declare module "fs" {
1477
1692
  * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1478
1693
  * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
1479
1694
  */
1480
- function __promisify__(path: PathLike, options: BufferEncodingOption): Promise<Buffer>;
1695
+ function __promisify__(path: PathLike, options: BufferEncodingOption): Promise<NonSharedBuffer>;
1481
1696
  /**
1482
1697
  * Asynchronous realpath(3) - return the canonicalized absolute pathname.
1483
1698
  * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1484
1699
  * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
1485
1700
  */
1486
- function __promisify__(path: PathLike, options?: EncodingOption): Promise<string | Buffer>;
1701
+ function __promisify__(path: PathLike, options?: EncodingOption): Promise<string | NonSharedBuffer>;
1487
1702
  /**
1488
1703
  * Asynchronous [`realpath(3)`](http://man7.org/linux/man-pages/man3/realpath.3.html).
1489
1704
  *
@@ -1509,12 +1724,12 @@ declare module "fs" {
1509
1724
  function native(
1510
1725
  path: PathLike,
1511
1726
  options: BufferEncodingOption,
1512
- callback: (err: NodeJS.ErrnoException | null, resolvedPath: Buffer) => void,
1727
+ callback: (err: NodeJS.ErrnoException | null, resolvedPath: NonSharedBuffer) => void,
1513
1728
  ): void;
1514
1729
  function native(
1515
1730
  path: PathLike,
1516
1731
  options: EncodingOption,
1517
- callback: (err: NodeJS.ErrnoException | null, resolvedPath: string | Buffer) => void,
1732
+ callback: (err: NodeJS.ErrnoException | null, resolvedPath: string | NonSharedBuffer) => void,
1518
1733
  ): void;
1519
1734
  function native(
1520
1735
  path: PathLike,
@@ -1534,17 +1749,17 @@ declare module "fs" {
1534
1749
  * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1535
1750
  * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
1536
1751
  */
1537
- export function realpathSync(path: PathLike, options: BufferEncodingOption): Buffer;
1752
+ export function realpathSync(path: PathLike, options: BufferEncodingOption): NonSharedBuffer;
1538
1753
  /**
1539
1754
  * Synchronous realpath(3) - return the canonicalized absolute pathname.
1540
1755
  * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1541
1756
  * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
1542
1757
  */
1543
- export function realpathSync(path: PathLike, options?: EncodingOption): string | Buffer;
1758
+ export function realpathSync(path: PathLike, options?: EncodingOption): string | NonSharedBuffer;
1544
1759
  export namespace realpathSync {
1545
1760
  function native(path: PathLike, options?: EncodingOption): string;
1546
- function native(path: PathLike, options: BufferEncodingOption): Buffer;
1547
- function native(path: PathLike, options?: EncodingOption): string | Buffer;
1761
+ function native(path: PathLike, options: BufferEncodingOption): NonSharedBuffer;
1762
+ function native(path: PathLike, options?: EncodingOption): string | NonSharedBuffer;
1548
1763
  }
1549
1764
  /**
1550
1765
  * Asynchronously removes a file or symbolic link. No arguments other than a
@@ -1663,7 +1878,7 @@ declare module "fs" {
1663
1878
  retryDelay?: number | undefined;
1664
1879
  }
1665
1880
  /**
1666
- * Asynchronously removes files and directories (modeled on the standard POSIX `rm`utility). No arguments other than a possible exception are given to the
1881
+ * Asynchronously removes files and directories (modeled on the standard POSIX `rm` utility). No arguments other than a possible exception are given to the
1667
1882
  * completion callback.
1668
1883
  * @since v14.14.0
1669
1884
  */
@@ -1676,7 +1891,7 @@ declare module "fs" {
1676
1891
  function __promisify__(path: PathLike, options?: RmOptions): Promise<void>;
1677
1892
  }
1678
1893
  /**
1679
- * Synchronously removes files and directories (modeled on the standard POSIX `rm`utility). Returns `undefined`.
1894
+ * Synchronously removes files and directories (modeled on the standard POSIX `rm` utility). Returns `undefined`.
1680
1895
  * @since v14.14.0
1681
1896
  */
1682
1897
  export function rmSync(path: PathLike, options?: RmOptions): void;
@@ -1701,7 +1916,7 @@ declare module "fs" {
1701
1916
  * created (for instance, if it was previously created).
1702
1917
  *
1703
1918
  * The optional `options` argument can be an integer specifying `mode` (permission
1704
- * 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
1919
+ * 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
1705
1920
  * exists results in an error only
1706
1921
  * when `recursive` is false. If `recursive` is false and the directory exists,
1707
1922
  * an `EEXIST` error occurs.
@@ -1809,7 +2024,7 @@ declare module "fs" {
1809
2024
  ): Promise<string | undefined>;
1810
2025
  }
1811
2026
  /**
1812
- * Synchronously creates a directory. Returns `undefined`, or if `recursive` is`true`, the first directory path created.
2027
+ * Synchronously creates a directory. Returns `undefined`, or if `recursive` is `true`, the first directory path created.
1813
2028
  * This is the synchronous version of {@link mkdir}.
1814
2029
  *
1815
2030
  * See the POSIX [`mkdir(2)`](http://man7.org/linux/man-pages/man2/mkdir.2.html) documentation for more details.
@@ -1846,7 +2061,7 @@ declare module "fs" {
1846
2061
  /**
1847
2062
  * Creates a unique temporary directory.
1848
2063
  *
1849
- * Generates six random characters to be appended behind a required`prefix` to create a unique temporary directory. Due to platform
2064
+ * Generates six random characters to be appended behind a required `prefix` to create a unique temporary directory. Due to platform
1850
2065
  * inconsistencies, avoid trailing `X` characters in `prefix`. Some platforms,
1851
2066
  * notably the BSDs, can return more than six random characters, and replace
1852
2067
  * trailing `X` characters in `prefix` with random characters.
@@ -1872,7 +2087,7 @@ declare module "fs" {
1872
2087
  * The `fs.mkdtemp()` method will append the six randomly selected characters
1873
2088
  * directly to the `prefix` string. For instance, given a directory `/tmp`, if the
1874
2089
  * intention is to create a temporary directory _within_`/tmp`, the `prefix`must end with a trailing platform-specific path separator
1875
- * (`require('node:path').sep`).
2090
+ * (`import { sep } from 'node:path'`).
1876
2091
  *
1877
2092
  * ```js
1878
2093
  * import { tmpdir } from 'node:os';
@@ -1914,12 +2129,8 @@ declare module "fs" {
1914
2129
  */
1915
2130
  export function mkdtemp(
1916
2131
  prefix: string,
1917
- options:
1918
- | "buffer"
1919
- | {
1920
- encoding: "buffer";
1921
- },
1922
- callback: (err: NodeJS.ErrnoException | null, folder: Buffer) => void,
2132
+ options: BufferEncodingOption,
2133
+ callback: (err: NodeJS.ErrnoException | null, folder: NonSharedBuffer) => void,
1923
2134
  ): void;
1924
2135
  /**
1925
2136
  * Asynchronously creates a unique temporary directory.
@@ -1929,7 +2140,7 @@ declare module "fs" {
1929
2140
  export function mkdtemp(
1930
2141
  prefix: string,
1931
2142
  options: EncodingOption,
1932
- callback: (err: NodeJS.ErrnoException | null, folder: string | Buffer) => void,
2143
+ callback: (err: NodeJS.ErrnoException | null, folder: string | NonSharedBuffer) => void,
1933
2144
  ): void;
1934
2145
  /**
1935
2146
  * Asynchronously creates a unique temporary directory.
@@ -1951,13 +2162,13 @@ declare module "fs" {
1951
2162
  * Generates six random characters to be appended behind a required prefix to create a unique temporary directory.
1952
2163
  * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
1953
2164
  */
1954
- function __promisify__(prefix: string, options: BufferEncodingOption): Promise<Buffer>;
2165
+ function __promisify__(prefix: string, options: BufferEncodingOption): Promise<NonSharedBuffer>;
1955
2166
  /**
1956
2167
  * Asynchronously creates a unique temporary directory.
1957
2168
  * Generates six random characters to be appended behind a required prefix to create a unique temporary directory.
1958
2169
  * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
1959
2170
  */
1960
- function __promisify__(prefix: string, options?: EncodingOption): Promise<string | Buffer>;
2171
+ function __promisify__(prefix: string, options?: EncodingOption): Promise<string | NonSharedBuffer>;
1961
2172
  }
1962
2173
  /**
1963
2174
  * Returns the created directory path.
@@ -1975,15 +2186,48 @@ declare module "fs" {
1975
2186
  * Generates six random characters to be appended behind a required prefix to create a unique temporary directory.
1976
2187
  * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
1977
2188
  */
1978
- export function mkdtempSync(prefix: string, options: BufferEncodingOption): Buffer;
2189
+ export function mkdtempSync(prefix: string, options: BufferEncodingOption): NonSharedBuffer;
1979
2190
  /**
1980
2191
  * Synchronously creates a unique temporary directory.
1981
2192
  * Generates six random characters to be appended behind a required prefix to create a unique temporary directory.
1982
2193
  * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
1983
2194
  */
1984
- export function mkdtempSync(prefix: string, options?: EncodingOption): string | Buffer;
2195
+ export function mkdtempSync(prefix: string, options?: EncodingOption): string | NonSharedBuffer;
2196
+ export interface DisposableTempDir extends Disposable {
2197
+ /**
2198
+ * The path of the created directory.
2199
+ */
2200
+ path: string;
2201
+ /**
2202
+ * A function which removes the created directory.
2203
+ */
2204
+ remove(): void;
2205
+ /**
2206
+ * The same as `remove`.
2207
+ */
2208
+ [Symbol.dispose](): void;
2209
+ }
1985
2210
  /**
1986
- * 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 `'..'`.
2211
+ * Returns a disposable object whose `path` property holds the created directory
2212
+ * path. When the object is disposed, the directory and its contents will be
2213
+ * removed if it still exists. If the directory cannot be deleted, disposal will
2214
+ * throw an error. The object has a `remove()` method which will perform the same
2215
+ * task.
2216
+ *
2217
+ * <!-- TODO: link MDN docs for disposables once https://github.com/mdn/content/pull/38027 lands -->
2218
+ *
2219
+ * For detailed information, see the documentation of `fs.mkdtemp()`.
2220
+ *
2221
+ * There is no callback-based version of this API because it is designed for use
2222
+ * with the `using` syntax.
2223
+ *
2224
+ * The optional `options` argument can be a string specifying an encoding, or an
2225
+ * object with an `encoding` property specifying the character encoding to use.
2226
+ * @since v24.4.0
2227
+ */
2228
+ export function mkdtempDisposableSync(prefix: string, options?: EncodingOption): DisposableTempDir;
2229
+ /**
2230
+ * 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 `'..'`.
1987
2231
  *
1988
2232
  * See the POSIX [`readdir(3)`](http://man7.org/linux/man-pages/man3/readdir.3.html) documentation for more details.
1989
2233
  *
@@ -2022,7 +2266,7 @@ declare module "fs" {
2022
2266
  recursive?: boolean | undefined;
2023
2267
  }
2024
2268
  | "buffer",
2025
- callback: (err: NodeJS.ErrnoException | null, files: Buffer[]) => void,
2269
+ callback: (err: NodeJS.ErrnoException | null, files: NonSharedBuffer[]) => void,
2026
2270
  ): void;
2027
2271
  /**
2028
2272
  * Asynchronous readdir(3) - read a directory.
@@ -2039,7 +2283,7 @@ declare module "fs" {
2039
2283
  | BufferEncoding
2040
2284
  | undefined
2041
2285
  | null,
2042
- callback: (err: NodeJS.ErrnoException | null, files: string[] | Buffer[]) => void,
2286
+ callback: (err: NodeJS.ErrnoException | null, files: string[] | NonSharedBuffer[]) => void,
2043
2287
  ): void;
2044
2288
  /**
2045
2289
  * Asynchronous readdir(3) - read a directory.
@@ -2062,6 +2306,20 @@ declare module "fs" {
2062
2306
  },
2063
2307
  callback: (err: NodeJS.ErrnoException | null, files: Dirent[]) => void,
2064
2308
  ): void;
2309
+ /**
2310
+ * Asynchronous readdir(3) - read a directory.
2311
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
2312
+ * @param options Must include `withFileTypes: true` and `encoding: 'buffer'`.
2313
+ */
2314
+ export function readdir(
2315
+ path: PathLike,
2316
+ options: {
2317
+ encoding: "buffer";
2318
+ withFileTypes: true;
2319
+ recursive?: boolean | undefined;
2320
+ },
2321
+ callback: (err: NodeJS.ErrnoException | null, files: Dirent<NonSharedBuffer>[]) => void,
2322
+ ): void;
2065
2323
  export namespace readdir {
2066
2324
  /**
2067
2325
  * Asynchronous readdir(3) - read a directory.
@@ -2093,7 +2351,7 @@ declare module "fs" {
2093
2351
  withFileTypes?: false | undefined;
2094
2352
  recursive?: boolean | undefined;
2095
2353
  },
2096
- ): Promise<Buffer[]>;
2354
+ ): Promise<NonSharedBuffer[]>;
2097
2355
  /**
2098
2356
  * Asynchronous readdir(3) - read a directory.
2099
2357
  * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
@@ -2108,7 +2366,7 @@ declare module "fs" {
2108
2366
  })
2109
2367
  | BufferEncoding
2110
2368
  | null,
2111
- ): Promise<string[] | Buffer[]>;
2369
+ ): Promise<string[] | NonSharedBuffer[]>;
2112
2370
  /**
2113
2371
  * Asynchronous readdir(3) - read a directory.
2114
2372
  * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
@@ -2121,6 +2379,19 @@ declare module "fs" {
2121
2379
  recursive?: boolean | undefined;
2122
2380
  },
2123
2381
  ): Promise<Dirent[]>;
2382
+ /**
2383
+ * Asynchronous readdir(3) - read a directory.
2384
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
2385
+ * @param options Must include `withFileTypes: true` and `encoding: 'buffer'`.
2386
+ */
2387
+ function __promisify__(
2388
+ path: PathLike,
2389
+ options: {
2390
+ encoding: "buffer";
2391
+ withFileTypes: true;
2392
+ recursive?: boolean | undefined;
2393
+ },
2394
+ ): Promise<Dirent<NonSharedBuffer>[]>;
2124
2395
  }
2125
2396
  /**
2126
2397
  * Reads the contents of the directory.
@@ -2160,7 +2431,7 @@ declare module "fs" {
2160
2431
  recursive?: boolean | undefined;
2161
2432
  }
2162
2433
  | "buffer",
2163
- ): Buffer[];
2434
+ ): NonSharedBuffer[];
2164
2435
  /**
2165
2436
  * Synchronous readdir(3) - read a directory.
2166
2437
  * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
@@ -2175,7 +2446,7 @@ declare module "fs" {
2175
2446
  })
2176
2447
  | BufferEncoding
2177
2448
  | null,
2178
- ): string[] | Buffer[];
2449
+ ): string[] | NonSharedBuffer[];
2179
2450
  /**
2180
2451
  * Synchronous readdir(3) - read a directory.
2181
2452
  * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
@@ -2188,6 +2459,19 @@ declare module "fs" {
2188
2459
  recursive?: boolean | undefined;
2189
2460
  },
2190
2461
  ): Dirent[];
2462
+ /**
2463
+ * Synchronous readdir(3) - read a directory.
2464
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
2465
+ * @param options Must include `withFileTypes: true` and `encoding: 'buffer'`.
2466
+ */
2467
+ export function readdirSync(
2468
+ path: PathLike,
2469
+ options: {
2470
+ encoding: "buffer";
2471
+ withFileTypes: true;
2472
+ recursive?: boolean | undefined;
2473
+ },
2474
+ ): Dirent<NonSharedBuffer>[];
2191
2475
  /**
2192
2476
  * Closes the file descriptor. No arguments other than a possible exception are
2193
2477
  * given to the completion callback.
@@ -2277,8 +2561,8 @@ declare module "fs" {
2277
2561
  *
2278
2562
  * The `atime` and `mtime` arguments follow these rules:
2279
2563
  *
2280
- * * Values can be either numbers representing Unix epoch time in seconds,`Date`s, or a numeric string like `'123456789.0'`.
2281
- * * If the value can not be converted to a number, or is `NaN`, `Infinity`, or`-Infinity`, an `Error` will be thrown.
2564
+ * * Values can be either numbers representing Unix epoch time in seconds, `Date`s, or a numeric string like `'123456789.0'`.
2565
+ * * If the value can not be converted to a number, or is `NaN`, `Infinity`, or `-Infinity`, an `Error` will be thrown.
2282
2566
  * @since v0.4.2
2283
2567
  */
2284
2568
  export function utimes(path: PathLike, atime: TimeLike, mtime: TimeLike, callback: NoParamCallback): void;
@@ -2341,6 +2625,20 @@ declare module "fs" {
2341
2625
  * @since v0.1.96
2342
2626
  */
2343
2627
  export function fsyncSync(fd: number): void;
2628
+ export interface WriteOptions {
2629
+ /**
2630
+ * @default 0
2631
+ */
2632
+ offset?: number | undefined;
2633
+ /**
2634
+ * @default `buffer.byteLength - offset`
2635
+ */
2636
+ length?: number | undefined;
2637
+ /**
2638
+ * @default null
2639
+ */
2640
+ position?: number | null | undefined;
2641
+ }
2344
2642
  /**
2345
2643
  * Write `buffer` to the file specified by `fd`.
2346
2644
  *
@@ -2351,7 +2649,7 @@ declare module "fs" {
2351
2649
  * should be written. If `typeof position !== 'number'`, the data will be written
2352
2650
  * at the current position. See [`pwrite(2)`](http://man7.org/linux/man-pages/man2/pwrite.2.html).
2353
2651
  *
2354
- * The callback will be given three arguments `(err, bytesWritten, buffer)` where`bytesWritten` specifies how many _bytes_ were written from `buffer`.
2652
+ * The callback will be given three arguments `(err, bytesWritten, buffer)` where `bytesWritten` specifies how many _bytes_ were written from `buffer`.
2355
2653
  *
2356
2654
  * If this method is invoked as its `util.promisify()` ed version, it returns
2357
2655
  * a promise for an `Object` with `bytesWritten` and `buffer` properties.
@@ -2409,6 +2707,20 @@ declare module "fs" {
2409
2707
  buffer: TBuffer,
2410
2708
  callback: (err: NodeJS.ErrnoException | null, written: number, buffer: TBuffer) => void,
2411
2709
  ): void;
2710
+ /**
2711
+ * Asynchronously writes `buffer` to the file referenced by the supplied file descriptor.
2712
+ * @param fd A file descriptor.
2713
+ * @param options An object with the following properties:
2714
+ * * `offset` The part of the buffer to be written. If not supplied, defaults to `0`.
2715
+ * * `length` The number of bytes to write. If not supplied, defaults to `buffer.length - offset`.
2716
+ * * `position` The offset from the beginning of the file where this data should be written. If not supplied, defaults to the current position.
2717
+ */
2718
+ export function write<TBuffer extends NodeJS.ArrayBufferView>(
2719
+ fd: number,
2720
+ buffer: TBuffer,
2721
+ options: WriteOptions,
2722
+ callback: (err: NodeJS.ErrnoException | null, written: number, buffer: TBuffer) => void,
2723
+ ): void;
2412
2724
  /**
2413
2725
  * Asynchronously writes `string` to the file referenced by the supplied file descriptor.
2414
2726
  * @param fd A file descriptor.
@@ -2463,6 +2775,22 @@ declare module "fs" {
2463
2775
  bytesWritten: number;
2464
2776
  buffer: TBuffer;
2465
2777
  }>;
2778
+ /**
2779
+ * Asynchronously writes `buffer` to the file referenced by the supplied file descriptor.
2780
+ * @param fd A file descriptor.
2781
+ * @param options An object with the following properties:
2782
+ * * `offset` The part of the buffer to be written. If not supplied, defaults to `0`.
2783
+ * * `length` The number of bytes to write. If not supplied, defaults to `buffer.length - offset`.
2784
+ * * `position` The offset from the beginning of the file where this data should be written. If not supplied, defaults to the current position.
2785
+ */
2786
+ function __promisify__<TBuffer extends NodeJS.ArrayBufferView>(
2787
+ fd: number,
2788
+ buffer?: TBuffer,
2789
+ options?: WriteOptions,
2790
+ ): Promise<{
2791
+ bytesWritten: number;
2792
+ buffer: TBuffer;
2793
+ }>;
2466
2794
  /**
2467
2795
  * Asynchronously writes `string` to the file referenced by the supplied file descriptor.
2468
2796
  * @param fd A file descriptor.
@@ -2510,7 +2838,7 @@ declare module "fs" {
2510
2838
  encoding?: BufferEncoding | null,
2511
2839
  ): number;
2512
2840
  export type ReadPosition = number | bigint;
2513
- export interface ReadSyncOptions {
2841
+ export interface ReadOptions {
2514
2842
  /**
2515
2843
  * @default 0
2516
2844
  */
@@ -2524,9 +2852,15 @@ declare module "fs" {
2524
2852
  */
2525
2853
  position?: ReadPosition | null | undefined;
2526
2854
  }
2527
- export interface ReadAsyncOptions<TBuffer extends NodeJS.ArrayBufferView> extends ReadSyncOptions {
2528
- buffer?: TBuffer;
2855
+ export interface ReadOptionsWithBuffer<T extends NodeJS.ArrayBufferView> extends ReadOptions {
2856
+ buffer?: T | undefined;
2529
2857
  }
2858
+ /** @deprecated Use `ReadOptions` instead. */
2859
+ // TODO: remove in future major
2860
+ export interface ReadSyncOptions extends ReadOptions {}
2861
+ /** @deprecated Use `ReadOptionsWithBuffer` instead. */
2862
+ // TODO: remove in future major
2863
+ export interface ReadAsyncOptions<T extends NodeJS.ArrayBufferView> extends ReadOptionsWithBuffer<T> {}
2530
2864
  /**
2531
2865
  * Read data from the file specified by `fd`.
2532
2866
  *
@@ -2561,14 +2895,25 @@ declare module "fs" {
2561
2895
  * `position` defaults to `null`
2562
2896
  * @since v12.17.0, 13.11.0
2563
2897
  */
2898
+ export function read<TBuffer extends NodeJS.ArrayBufferView = NonSharedBuffer>(
2899
+ fd: number,
2900
+ options: ReadOptionsWithBuffer<TBuffer>,
2901
+ callback: (err: NodeJS.ErrnoException | null, bytesRead: number, buffer: TBuffer) => void,
2902
+ ): void;
2903
+ export function read<TBuffer extends NodeJS.ArrayBufferView>(
2904
+ fd: number,
2905
+ buffer: TBuffer,
2906
+ options: ReadOptions,
2907
+ callback: (err: NodeJS.ErrnoException | null, bytesRead: number, buffer: TBuffer) => void,
2908
+ ): void;
2564
2909
  export function read<TBuffer extends NodeJS.ArrayBufferView>(
2565
2910
  fd: number,
2566
- options: ReadAsyncOptions<TBuffer>,
2911
+ buffer: TBuffer,
2567
2912
  callback: (err: NodeJS.ErrnoException | null, bytesRead: number, buffer: TBuffer) => void,
2568
2913
  ): void;
2569
2914
  export function read(
2570
2915
  fd: number,
2571
- callback: (err: NodeJS.ErrnoException | null, bytesRead: number, buffer: NodeJS.ArrayBufferView) => void,
2916
+ callback: (err: NodeJS.ErrnoException | null, bytesRead: number, buffer: NonSharedBuffer) => void,
2572
2917
  ): void;
2573
2918
  export namespace read {
2574
2919
  /**
@@ -2583,21 +2928,21 @@ declare module "fs" {
2583
2928
  buffer: TBuffer,
2584
2929
  offset: number,
2585
2930
  length: number,
2586
- position: number | null,
2931
+ position: ReadPosition | null,
2587
2932
  ): Promise<{
2588
2933
  bytesRead: number;
2589
2934
  buffer: TBuffer;
2590
2935
  }>;
2591
- function __promisify__<TBuffer extends NodeJS.ArrayBufferView>(
2936
+ function __promisify__<TBuffer extends NodeJS.ArrayBufferView = NonSharedBuffer>(
2592
2937
  fd: number,
2593
- options: ReadAsyncOptions<TBuffer>,
2938
+ options: ReadOptionsWithBuffer<TBuffer>,
2594
2939
  ): Promise<{
2595
2940
  bytesRead: number;
2596
2941
  buffer: TBuffer;
2597
2942
  }>;
2598
2943
  function __promisify__(fd: number): Promise<{
2599
2944
  bytesRead: number;
2600
- buffer: NodeJS.ArrayBufferView;
2945
+ buffer: NonSharedBuffer;
2601
2946
  }>;
2602
2947
  }
2603
2948
  /**
@@ -2619,7 +2964,7 @@ declare module "fs" {
2619
2964
  * Similar to the above `fs.readSync` function, this version takes an optional `options` object.
2620
2965
  * If no `options` object is specified, it will default with the above values.
2621
2966
  */
2622
- export function readSync(fd: number, buffer: NodeJS.ArrayBufferView, opts?: ReadSyncOptions): number;
2967
+ export function readSync(fd: number, buffer: NodeJS.ArrayBufferView, opts?: ReadOptions): number;
2623
2968
  /**
2624
2969
  * Asynchronously reads the entire contents of a file.
2625
2970
  *
@@ -2695,7 +3040,7 @@ declare module "fs" {
2695
3040
  } & Abortable)
2696
3041
  | undefined
2697
3042
  | null,
2698
- callback: (err: NodeJS.ErrnoException | null, data: Buffer) => void,
3043
+ callback: (err: NodeJS.ErrnoException | null, data: NonSharedBuffer) => void,
2699
3044
  ): void;
2700
3045
  /**
2701
3046
  * Asynchronously reads the entire contents of a file.
@@ -2730,7 +3075,7 @@ declare module "fs" {
2730
3075
  | BufferEncoding
2731
3076
  | undefined
2732
3077
  | null,
2733
- callback: (err: NodeJS.ErrnoException | null, data: string | Buffer) => void,
3078
+ callback: (err: NodeJS.ErrnoException | null, data: string | NonSharedBuffer) => void,
2734
3079
  ): void;
2735
3080
  /**
2736
3081
  * Asynchronously reads the entire contents of a file.
@@ -2739,7 +3084,7 @@ declare module "fs" {
2739
3084
  */
2740
3085
  export function readFile(
2741
3086
  path: PathOrFileDescriptor,
2742
- callback: (err: NodeJS.ErrnoException | null, data: Buffer) => void,
3087
+ callback: (err: NodeJS.ErrnoException | null, data: NonSharedBuffer) => void,
2743
3088
  ): void;
2744
3089
  export namespace readFile {
2745
3090
  /**
@@ -2755,7 +3100,7 @@ declare module "fs" {
2755
3100
  encoding?: null | undefined;
2756
3101
  flag?: string | undefined;
2757
3102
  } | null,
2758
- ): Promise<Buffer>;
3103
+ ): Promise<NonSharedBuffer>;
2759
3104
  /**
2760
3105
  * Asynchronously reads the entire contents of a file.
2761
3106
  * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
@@ -2789,7 +3134,7 @@ declare module "fs" {
2789
3134
  })
2790
3135
  | BufferEncoding
2791
3136
  | null,
2792
- ): Promise<string | Buffer>;
3137
+ ): Promise<string | NonSharedBuffer>;
2793
3138
  }
2794
3139
  /**
2795
3140
  * Returns the contents of the `path`.
@@ -2800,7 +3145,7 @@ declare module "fs" {
2800
3145
  * If the `encoding` option is specified then this function returns a
2801
3146
  * string. Otherwise it returns a buffer.
2802
3147
  *
2803
- * Similar to {@link readFile}, when the path is a directory, the behavior of`fs.readFileSync()` is platform-specific.
3148
+ * Similar to {@link readFile}, when the path is a directory, the behavior of `fs.readFileSync()` is platform-specific.
2804
3149
  *
2805
3150
  * ```js
2806
3151
  * import { readFileSync } from 'node:fs';
@@ -2821,7 +3166,7 @@ declare module "fs" {
2821
3166
  encoding?: null | undefined;
2822
3167
  flag?: string | undefined;
2823
3168
  } | null,
2824
- ): Buffer;
3169
+ ): NonSharedBuffer;
2825
3170
  /**
2826
3171
  * Synchronously reads the entire contents of a file.
2827
3172
  * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
@@ -2853,7 +3198,7 @@ declare module "fs" {
2853
3198
  })
2854
3199
  | BufferEncoding
2855
3200
  | null,
2856
- ): string | Buffer;
3201
+ ): string | NonSharedBuffer;
2857
3202
  export type WriteFileOptions =
2858
3203
  | (
2859
3204
  & ObjectEncodingOptions
@@ -2861,6 +3206,7 @@ declare module "fs" {
2861
3206
  & {
2862
3207
  mode?: Mode | undefined;
2863
3208
  flag?: string | undefined;
3209
+ flush?: boolean | undefined;
2864
3210
  }
2865
3211
  )
2866
3212
  | BufferEncoding
@@ -2869,7 +3215,7 @@ declare module "fs" {
2869
3215
  * When `file` is a filename, asynchronously writes data to the file, replacing the
2870
3216
  * file if it already exists. `data` can be a string or a buffer.
2871
3217
  *
2872
- * When `file` is a file descriptor, the behavior is similar to calling`fs.write()` directly (which is recommended). See the notes below on using
3218
+ * When `file` is a file descriptor, the behavior is similar to calling `fs.write()` directly (which is recommended). See the notes below on using
2873
3219
  * a file descriptor.
2874
3220
  *
2875
3221
  * The `encoding` option is ignored if `data` is a buffer.
@@ -3118,7 +3464,7 @@ declare module "fs" {
3118
3464
  * Watch for changes on `filename`. The callback `listener` will be called each
3119
3465
  * time the file is accessed.
3120
3466
  *
3121
- * The `options` argument may be omitted. If provided, it should be an object. The`options` object may contain a boolean named `persistent` that indicates
3467
+ * The `options` argument may be omitted. If provided, it should be an object. The `options` object may contain a boolean named `persistent` that indicates
3122
3468
  * whether the process should continue to run as long as files are being watched.
3123
3469
  * The `options` object may specify an `interval` property indicating how often the
3124
3470
  * target should be polled in milliseconds.
@@ -3127,7 +3473,7 @@ declare module "fs" {
3127
3473
  * stat object:
3128
3474
  *
3129
3475
  * ```js
3130
- * import { watchFile } from 'fs';
3476
+ * import { watchFile } from 'node:fs';
3131
3477
  *
3132
3478
  * watchFile('message.text', (curr, prev) => {
3133
3479
  * console.log(`the current mtime is: ${curr.mtime}`);
@@ -3147,7 +3493,7 @@ declare module "fs" {
3147
3493
  * again, with the latest stat objects. This is a change in functionality since
3148
3494
  * v0.10.
3149
3495
  *
3150
- * 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.
3496
+ * 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.
3151
3497
  *
3152
3498
  * When a file being watched by `fs.watchFile()` disappears and reappears,
3153
3499
  * then the contents of `previous` in the second callback event (the file's
@@ -3169,7 +3515,7 @@ declare module "fs" {
3169
3515
  * Watch for changes on `filename`. The callback `listener` will be called each
3170
3516
  * time the file is accessed.
3171
3517
  *
3172
- * The `options` argument may be omitted. If provided, it should be an object. The`options` object may contain a boolean named `persistent` that indicates
3518
+ * The `options` argument may be omitted. If provided, it should be an object. The `options` object may contain a boolean named `persistent` that indicates
3173
3519
  * whether the process should continue to run as long as files are being watched.
3174
3520
  * The `options` object may specify an `interval` property indicating how often the
3175
3521
  * target should be polled in milliseconds.
@@ -3198,7 +3544,7 @@ declare module "fs" {
3198
3544
  * again, with the latest stat objects. This is a change in functionality since
3199
3545
  * v0.10.
3200
3546
  *
3201
- * 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.
3547
+ * 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.
3202
3548
  *
3203
3549
  * When a file being watched by `fs.watchFile()` disappears and reappears,
3204
3550
  * then the contents of `previous` in the second callback event (the file's
@@ -3242,7 +3588,7 @@ declare module "fs" {
3242
3588
  * Calling `fs.unwatchFile()` with a filename that is not being watched is a
3243
3589
  * no-op, not an error.
3244
3590
  *
3245
- * 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.
3591
+ * 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.
3246
3592
  * @since v0.1.31
3247
3593
  * @param listener Optional, a listener previously attached using `fs.watchFile()`
3248
3594
  */
@@ -3253,6 +3599,12 @@ declare module "fs" {
3253
3599
  persistent?: boolean | undefined;
3254
3600
  recursive?: boolean | undefined;
3255
3601
  }
3602
+ export interface WatchOptionsWithBufferEncoding extends WatchOptions {
3603
+ encoding: "buffer";
3604
+ }
3605
+ export interface WatchOptionsWithStringEncoding extends WatchOptions {
3606
+ encoding?: BufferEncoding | undefined;
3607
+ }
3256
3608
  export type WatchEventType = "rename" | "change";
3257
3609
  export type WatchListener<T> = (event: WatchEventType, filename: T | null) => void;
3258
3610
  export type StatsListener = (curr: Stats, prev: Stats) => void;
@@ -3270,7 +3622,7 @@ declare module "fs" {
3270
3622
  * On most platforms, `'rename'` is emitted whenever a filename appears or
3271
3623
  * disappears in the directory.
3272
3624
  *
3273
- * 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`.
3625
+ * 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`.
3274
3626
  *
3275
3627
  * If a `signal` is passed, aborting the corresponding AbortController will close
3276
3628
  * the returned `fs.FSWatcher`.
@@ -3279,44 +3631,20 @@ declare module "fs" {
3279
3631
  */
3280
3632
  export function watch(
3281
3633
  filename: PathLike,
3282
- options:
3283
- | (WatchOptions & {
3284
- encoding: "buffer";
3285
- })
3286
- | "buffer",
3287
- listener?: WatchListener<Buffer>,
3634
+ options?: WatchOptionsWithStringEncoding | BufferEncoding | null,
3635
+ listener?: WatchListener<string>,
3288
3636
  ): FSWatcher;
3289
- /**
3290
- * Watch for changes on `filename`, where `filename` is either a file or a directory, returning an `FSWatcher`.
3291
- * @param filename A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
3292
- * @param options Either the encoding for the filename provided to the listener, or an object optionally specifying encoding, persistent, and recursive options.
3293
- * If `encoding` is not supplied, the default of `'utf8'` is used.
3294
- * If `persistent` is not supplied, the default of `true` is used.
3295
- * If `recursive` is not supplied, the default of `false` is used.
3296
- */
3297
3637
  export function watch(
3298
3638
  filename: PathLike,
3299
- options?: WatchOptions | BufferEncoding | null,
3300
- listener?: WatchListener<string>,
3639
+ options: WatchOptionsWithBufferEncoding | "buffer",
3640
+ listener: WatchListener<NonSharedBuffer>,
3301
3641
  ): FSWatcher;
3302
- /**
3303
- * Watch for changes on `filename`, where `filename` is either a file or a directory, returning an `FSWatcher`.
3304
- * @param filename A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
3305
- * @param options Either the encoding for the filename provided to the listener, or an object optionally specifying encoding, persistent, and recursive options.
3306
- * If `encoding` is not supplied, the default of `'utf8'` is used.
3307
- * If `persistent` is not supplied, the default of `true` is used.
3308
- * If `recursive` is not supplied, the default of `false` is used.
3309
- */
3310
3642
  export function watch(
3311
3643
  filename: PathLike,
3312
- options: WatchOptions | string,
3313
- listener?: WatchListener<string | Buffer>,
3644
+ options: WatchOptions | BufferEncoding | "buffer" | null,
3645
+ listener: WatchListener<string | NonSharedBuffer>,
3314
3646
  ): FSWatcher;
3315
- /**
3316
- * Watch for changes on `filename`, where `filename` is either a file or a directory, returning an `FSWatcher`.
3317
- * @param filename A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
3318
- */
3319
- export function watch(filename: PathLike, listener?: WatchListener<string>): FSWatcher;
3647
+ export function watch(filename: PathLike, listener: WatchListener<string>): FSWatcher;
3320
3648
  /**
3321
3649
  * Test whether or not the given path exists by checking with the file system.
3322
3650
  * Then call the `callback` argument with either true or false:
@@ -3330,11 +3658,11 @@ declare module "fs" {
3330
3658
  * ```
3331
3659
  *
3332
3660
  * **The parameters for this callback are not consistent with other Node.js**
3333
- * **callbacks.** Normally, the first parameter to a Node.js callback is an `err`parameter, optionally followed by other parameters. The `fs.exists()` callback
3661
+ * **callbacks.** Normally, the first parameter to a Node.js callback is an `err` parameter, optionally followed by other parameters. The `fs.exists()` callback
3334
3662
  * has only one boolean parameter. This is one reason `fs.access()` is recommended
3335
3663
  * instead of `fs.exists()`.
3336
3664
  *
3337
- * Using `fs.exists()` to check for the existence of a file before calling`fs.open()`, `fs.readFile()`, or `fs.writeFile()` is not recommended. Doing
3665
+ * Using `fs.exists()` to check for the existence of a file before calling `fs.open()`, `fs.readFile()`, or `fs.writeFile()` is not recommended. Doing
3338
3666
  * so introduces a race condition, since other processes may change the file's
3339
3667
  * state between the two calls. Instead, user code should open/read/write the
3340
3668
  * file directly and handle the error raised if the file does not exist.
@@ -3461,7 +3789,7 @@ declare module "fs" {
3461
3789
  * For detailed information, see the documentation of the asynchronous version of
3462
3790
  * this API: {@link exists}.
3463
3791
  *
3464
- * `fs.exists()` is deprecated, but `fs.existsSync()` is not. The `callback`parameter to `fs.exists()` accepts parameters that are inconsistent with other
3792
+ * `fs.exists()` is deprecated, but `fs.existsSync()` is not. The `callback` parameter to `fs.exists()` accepts parameters that are inconsistent with other
3465
3793
  * Node.js callbacks. `fs.existsSync()` does not use a callback.
3466
3794
  *
3467
3795
  * ```js
@@ -3590,13 +3918,13 @@ declare module "fs" {
3590
3918
  /**
3591
3919
  * Tests a user's permissions for the file or directory specified by `path`.
3592
3920
  * The `mode` argument is an optional integer that specifies the accessibility
3593
- * checks to be performed. `mode` should be either the value `fs.constants.F_OK`or a mask consisting of the bitwise OR of any of `fs.constants.R_OK`,`fs.constants.W_OK`, and `fs.constants.X_OK`
3921
+ * checks to be performed. `mode` should be either the value `fs.constants.F_OK` or a mask consisting of the bitwise OR of any of `fs.constants.R_OK`, `fs.constants.W_OK`, and `fs.constants.X_OK`
3594
3922
  * (e.g.`fs.constants.W_OK | fs.constants.R_OK`). Check `File access constants` for
3595
3923
  * possible values of `mode`.
3596
3924
  *
3597
3925
  * The final argument, `callback`, is a callback function that is invoked with
3598
3926
  * a possible error argument. If any of the accessibility checks fail, the error
3599
- * argument will be an `Error` object. The following examples check if`package.json` exists, and if it is readable or writable.
3927
+ * argument will be an `Error` object. The following examples check if `package.json` exists, and if it is readable or writable.
3600
3928
  *
3601
3929
  * ```js
3602
3930
  * import { access, constants } from 'node:fs';
@@ -3624,7 +3952,7 @@ declare module "fs" {
3624
3952
  * });
3625
3953
  * ```
3626
3954
  *
3627
- * Do not use `fs.access()` to check for the accessibility of a file before calling`fs.open()`, `fs.readFile()`, or `fs.writeFile()`. Doing
3955
+ * Do not use `fs.access()` to check for the accessibility of a file before calling `fs.open()`, `fs.readFile()`, or `fs.writeFile()`. Doing
3628
3956
  * so introduces a race condition, since other processes may change the file's
3629
3957
  * state between the two calls. Instead, user code should open/read/write the
3630
3958
  * file directly and handle the error raised if the file is not accessible.
@@ -3764,7 +4092,7 @@ declare module "fs" {
3764
4092
  /**
3765
4093
  * Synchronously tests a user's permissions for the file or directory specified
3766
4094
  * by `path`. The `mode` argument is an optional integer that specifies the
3767
- * accessibility checks to be performed. `mode` should be either the value`fs.constants.F_OK` or a mask consisting of the bitwise OR of any of`fs.constants.R_OK`, `fs.constants.W_OK`, and
4095
+ * accessibility checks to be performed. `mode` should be either the value `fs.constants.F_OK` or a mask consisting of the bitwise OR of any of `fs.constants.R_OK`, `fs.constants.W_OK`, and
3768
4096
  * `fs.constants.X_OK` (e.g.`fs.constants.W_OK | fs.constants.R_OK`). Check `File access constants` for
3769
4097
  * possible values of `mode`.
3770
4098
  *
@@ -3813,11 +4141,9 @@ declare module "fs" {
3813
4141
  }
3814
4142
  interface WriteStreamOptions extends StreamOptions {
3815
4143
  fs?: CreateWriteStreamFSImplementation | null | undefined;
4144
+ flush?: boolean | undefined;
3816
4145
  }
3817
4146
  /**
3818
- * Unlike the 16 KiB default `highWaterMark` for a `stream.Readable`, the stream
3819
- * returned by this method has a default `highWaterMark` of 64 KiB.
3820
- *
3821
4147
  * `options` can include `start` and `end` values to read a range of bytes from
3822
4148
  * the file instead of the entire file. Both `start` and `end` are inclusive and
3823
4149
  * start counting at 0, allowed values are in the
@@ -3837,8 +4163,8 @@ declare module "fs" {
3837
4163
  * By default, the stream will emit a `'close'` event after it has been
3838
4164
  * destroyed. Set the `emitClose` option to `false` to change this behavior.
3839
4165
  *
3840
- * By providing the `fs` option, it is possible to override the corresponding `fs`implementations for `open`, `read`, and `close`. When providing the `fs` option,
3841
- * 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
4166
+ * By providing the `fs` option, it is possible to override the corresponding `fs` implementations for `open`, `read`, and `close`. When providing the `fs` option,
4167
+ * 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
3842
4168
  * also required.
3843
4169
  *
3844
4170
  * ```js
@@ -3886,7 +4212,7 @@ declare module "fs" {
3886
4212
  * replacing it may require the `flags` option to be set to `r+` rather than the
3887
4213
  * default `w`. The `encoding` can be any one of those accepted by `Buffer`.
3888
4214
  *
3889
- * If `autoClose` is set to true (default behavior) on `'error'` or `'finish'`the file descriptor will be closed automatically. If `autoClose` is false,
4215
+ * If `autoClose` is set to true (default behavior) on `'error'` or `'finish'` the file descriptor will be closed automatically. If `autoClose` is false,
3890
4216
  * then the file descriptor won't be closed, even if there's an error.
3891
4217
  * It is the application's responsibility to close it and make sure there's no
3892
4218
  * file descriptor leak.
@@ -3894,12 +4220,12 @@ declare module "fs" {
3894
4220
  * By default, the stream will emit a `'close'` event after it has been
3895
4221
  * destroyed. Set the `emitClose` option to `false` to change this behavior.
3896
4222
  *
3897
- * 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
4223
+ * 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
3898
4224
  * performance as some optimizations (`_writev()`)
3899
- * 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
3900
- * for `open` is also required. If `autoClose` is `true`, an override for `close`is also required.
4225
+ * 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
4226
+ * for `open` is also required. If `autoClose` is `true`, an override for `close` is also required.
3901
4227
  *
3902
- * 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
4228
+ * 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
3903
4229
  * emitted. `fd` should be blocking; non-blocking `fd`s
3904
4230
  * should be passed to `net.Socket`.
3905
4231
  *
@@ -4008,15 +4334,15 @@ declare module "fs" {
4008
4334
  */
4009
4335
  export function copyFileSync(src: PathLike, dest: PathLike, mode?: number): void;
4010
4336
  /**
4011
- * Write an array of `ArrayBufferView`s to the file specified by `fd` using`writev()`.
4337
+ * Write an array of `ArrayBufferView`s to the file specified by `fd` using `writev()`.
4012
4338
  *
4013
4339
  * `position` is the offset from the beginning of the file where this data
4014
4340
  * should be written. If `typeof position !== 'number'`, the data will be written
4015
4341
  * at the current position.
4016
4342
  *
4017
- * The callback will be given three arguments: `err`, `bytesWritten`, and`buffers`. `bytesWritten` is how many bytes were written from `buffers`.
4343
+ * The callback will be given three arguments: `err`, `bytesWritten`, and `buffers`. `bytesWritten` is how many bytes were written from `buffers`.
4018
4344
  *
4019
- * If this method is `util.promisify()` ed, it returns a promise for an`Object` with `bytesWritten` and `buffers` properties.
4345
+ * If this method is `util.promisify()` ed, it returns a promise for an `Object` with `bytesWritten` and `buffers` properties.
4020
4346
  *
4021
4347
  * It is unsafe to use `fs.writev()` multiple times on the same file without
4022
4348
  * waiting for the callback. For this scenario, use {@link createWriteStream}.
@@ -4027,27 +4353,29 @@ declare module "fs" {
4027
4353
  * @since v12.9.0
4028
4354
  * @param [position='null']
4029
4355
  */
4030
- export function writev(
4356
+ export function writev<TBuffers extends readonly NodeJS.ArrayBufferView[]>(
4031
4357
  fd: number,
4032
- buffers: readonly NodeJS.ArrayBufferView[],
4033
- cb: (err: NodeJS.ErrnoException | null, bytesWritten: number, buffers: NodeJS.ArrayBufferView[]) => void,
4358
+ buffers: TBuffers,
4359
+ cb: (err: NodeJS.ErrnoException | null, bytesWritten: number, buffers: TBuffers) => void,
4034
4360
  ): void;
4035
- export function writev(
4361
+ export function writev<TBuffers extends readonly NodeJS.ArrayBufferView[]>(
4036
4362
  fd: number,
4037
- buffers: readonly NodeJS.ArrayBufferView[],
4038
- position: number,
4039
- cb: (err: NodeJS.ErrnoException | null, bytesWritten: number, buffers: NodeJS.ArrayBufferView[]) => void,
4363
+ buffers: TBuffers,
4364
+ position: number | null,
4365
+ cb: (err: NodeJS.ErrnoException | null, bytesWritten: number, buffers: TBuffers) => void,
4040
4366
  ): void;
4041
- export interface WriteVResult {
4367
+ // Providing a default type parameter doesn't provide true BC for userland consumers, but at least suppresses TS2314
4368
+ // TODO: remove default in future major version
4369
+ export interface WriteVResult<T extends readonly NodeJS.ArrayBufferView[] = NodeJS.ArrayBufferView[]> {
4042
4370
  bytesWritten: number;
4043
- buffers: NodeJS.ArrayBufferView[];
4371
+ buffers: T;
4044
4372
  }
4045
4373
  export namespace writev {
4046
- function __promisify__(
4374
+ function __promisify__<TBuffers extends readonly NodeJS.ArrayBufferView[]>(
4047
4375
  fd: number,
4048
- buffers: readonly NodeJS.ArrayBufferView[],
4376
+ buffers: TBuffers,
4049
4377
  position?: number,
4050
- ): Promise<WriteVResult>;
4378
+ ): Promise<WriteVResult<TBuffers>>;
4051
4379
  }
4052
4380
  /**
4053
4381
  * For detailed information, see the documentation of the asynchronous version of
@@ -4065,34 +4393,36 @@ declare module "fs" {
4065
4393
  * should be read. If `typeof position !== 'number'`, the data will be read
4066
4394
  * from the current position.
4067
4395
  *
4068
- * The callback will be given three arguments: `err`, `bytesRead`, and`buffers`. `bytesRead` is how many bytes were read from the file.
4396
+ * The callback will be given three arguments: `err`, `bytesRead`, and `buffers`. `bytesRead` is how many bytes were read from the file.
4069
4397
  *
4070
4398
  * If this method is invoked as its `util.promisify()` ed version, it returns
4071
4399
  * a promise for an `Object` with `bytesRead` and `buffers` properties.
4072
4400
  * @since v13.13.0, v12.17.0
4073
4401
  * @param [position='null']
4074
4402
  */
4075
- export function readv(
4403
+ export function readv<TBuffers extends readonly NodeJS.ArrayBufferView[]>(
4076
4404
  fd: number,
4077
- buffers: readonly NodeJS.ArrayBufferView[],
4078
- cb: (err: NodeJS.ErrnoException | null, bytesRead: number, buffers: NodeJS.ArrayBufferView[]) => void,
4405
+ buffers: TBuffers,
4406
+ cb: (err: NodeJS.ErrnoException | null, bytesRead: number, buffers: TBuffers) => void,
4079
4407
  ): void;
4080
- export function readv(
4408
+ export function readv<TBuffers extends readonly NodeJS.ArrayBufferView[]>(
4081
4409
  fd: number,
4082
- buffers: readonly NodeJS.ArrayBufferView[],
4083
- position: number,
4084
- cb: (err: NodeJS.ErrnoException | null, bytesRead: number, buffers: NodeJS.ArrayBufferView[]) => void,
4410
+ buffers: TBuffers,
4411
+ position: number | null,
4412
+ cb: (err: NodeJS.ErrnoException | null, bytesRead: number, buffers: TBuffers) => void,
4085
4413
  ): void;
4086
- export interface ReadVResult {
4414
+ // Providing a default type parameter doesn't provide true BC for userland consumers, but at least suppresses TS2314
4415
+ // TODO: remove default in future major version
4416
+ export interface ReadVResult<T extends readonly NodeJS.ArrayBufferView[] = NodeJS.ArrayBufferView[]> {
4087
4417
  bytesRead: number;
4088
- buffers: NodeJS.ArrayBufferView[];
4418
+ buffers: T;
4089
4419
  }
4090
4420
  export namespace readv {
4091
- function __promisify__(
4421
+ function __promisify__<TBuffers extends readonly NodeJS.ArrayBufferView[]>(
4092
4422
  fd: number,
4093
- buffers: readonly NodeJS.ArrayBufferView[],
4423
+ buffers: TBuffers,
4094
4424
  position?: number,
4095
- ): Promise<ReadVResult>;
4425
+ ): Promise<ReadVResult<TBuffers>>;
4096
4426
  }
4097
4427
  /**
4098
4428
  * For detailed information, see the documentation of the asynchronous version of
@@ -4128,7 +4458,6 @@ declare module "fs" {
4128
4458
  * blob.stream();
4129
4459
  * ```
4130
4460
  * @since v19.8.0
4131
- * @experimental
4132
4461
  */
4133
4462
  export function openAsBlob(path: PathLike, options?: OpenAsBlobOptions): Promise<Blob>;
4134
4463
 
@@ -4147,7 +4476,7 @@ declare module "fs" {
4147
4476
  /**
4148
4477
  * @default false
4149
4478
  */
4150
- recursive?: boolean;
4479
+ recursive?: boolean | undefined;
4151
4480
  }
4152
4481
  /**
4153
4482
  * Synchronously open a directory. See [`opendir(3)`](http://man7.org/linux/man-pages/man3/opendir.3.html).
@@ -4200,54 +4529,54 @@ declare module "fs" {
4200
4529
  * Dereference symlinks
4201
4530
  * @default false
4202
4531
  */
4203
- dereference?: boolean;
4532
+ dereference?: boolean | undefined;
4204
4533
  /**
4205
4534
  * When `force` is `false`, and the destination
4206
4535
  * exists, throw an error.
4207
4536
  * @default false
4208
4537
  */
4209
- errorOnExist?: boolean;
4538
+ errorOnExist?: boolean | undefined;
4210
4539
  /**
4211
4540
  * Overwrite existing file or directory. _The copy
4212
4541
  * operation will ignore errors if you set this to false and the destination
4213
4542
  * exists. Use the `errorOnExist` option to change this behavior.
4214
4543
  * @default true
4215
4544
  */
4216
- force?: boolean;
4545
+ force?: boolean | undefined;
4217
4546
  /**
4218
4547
  * Modifiers for copy operation. See `mode` flag of {@link copyFileSync()}
4219
4548
  */
4220
- mode?: number;
4549
+ mode?: number | undefined;
4221
4550
  /**
4222
4551
  * When `true` timestamps from `src` will
4223
4552
  * be preserved.
4224
4553
  * @default false
4225
4554
  */
4226
- preserveTimestamps?: boolean;
4555
+ preserveTimestamps?: boolean | undefined;
4227
4556
  /**
4228
4557
  * Copy directories recursively.
4229
4558
  * @default false
4230
4559
  */
4231
- recursive?: boolean;
4560
+ recursive?: boolean | undefined;
4232
4561
  /**
4233
4562
  * When true, path resolution for symlinks will be skipped
4234
4563
  * @default false
4235
4564
  */
4236
- verbatimSymlinks?: boolean;
4565
+ verbatimSymlinks?: boolean | undefined;
4237
4566
  }
4238
4567
  export interface CopyOptions extends CopyOptionsBase {
4239
4568
  /**
4240
4569
  * Function to filter copied files/directories. Return
4241
4570
  * `true` to copy the item, `false` to ignore it.
4242
4571
  */
4243
- filter?(source: string, destination: string): boolean | Promise<boolean>;
4572
+ filter?: ((source: string, destination: string) => boolean | Promise<boolean>) | undefined;
4244
4573
  }
4245
4574
  export interface CopySyncOptions extends CopyOptionsBase {
4246
4575
  /**
4247
4576
  * Function to filter copied files/directories. Return
4248
4577
  * `true` to copy the item, `false` to ignore it.
4249
4578
  */
4250
- filter?(source: string, destination: string): boolean;
4579
+ filter?: ((source: string, destination: string) => boolean) | undefined;
4251
4580
  }
4252
4581
  /**
4253
4582
  * Asynchronously copies the entire directory structure from `src` to `dest`,
@@ -4283,6 +4612,102 @@ declare module "fs" {
4283
4612
  * @param dest destination path to copy to.
4284
4613
  */
4285
4614
  export function cpSync(source: string | URL, destination: string | URL, opts?: CopySyncOptions): void;
4615
+
4616
+ // TODO: collapse
4617
+ interface _GlobOptions<T extends Dirent | string> {
4618
+ /**
4619
+ * Current working directory.
4620
+ * @default process.cwd()
4621
+ */
4622
+ cwd?: string | URL | undefined;
4623
+ /**
4624
+ * `true` if the glob should return paths as `Dirent`s, `false` otherwise.
4625
+ * @default false
4626
+ * @since v22.2.0
4627
+ */
4628
+ withFileTypes?: boolean | undefined;
4629
+ /**
4630
+ * Function to filter out files/directories or a
4631
+ * list of glob patterns to be excluded. If a function is provided, return
4632
+ * `true` to exclude the item, `false` to include it.
4633
+ * If a string array is provided, each string should be a glob pattern that
4634
+ * specifies paths to exclude. Note: Negation patterns (e.g., '!foo.js') are
4635
+ * not supported.
4636
+ * @default undefined
4637
+ */
4638
+ exclude?: ((fileName: T) => boolean) | readonly string[] | undefined;
4639
+ }
4640
+ export interface GlobOptions extends _GlobOptions<Dirent | string> {}
4641
+ export interface GlobOptionsWithFileTypes extends _GlobOptions<Dirent> {
4642
+ withFileTypes: true;
4643
+ }
4644
+ export interface GlobOptionsWithoutFileTypes extends _GlobOptions<string> {
4645
+ withFileTypes?: false | undefined;
4646
+ }
4647
+
4648
+ /**
4649
+ * Retrieves the files matching the specified pattern.
4650
+ *
4651
+ * ```js
4652
+ * import { glob } from 'node:fs';
4653
+ *
4654
+ * glob('*.js', (err, matches) => {
4655
+ * if (err) throw err;
4656
+ * console.log(matches);
4657
+ * });
4658
+ * ```
4659
+ * @since v22.0.0
4660
+ */
4661
+ export function glob(
4662
+ pattern: string | readonly string[],
4663
+ callback: (err: NodeJS.ErrnoException | null, matches: string[]) => void,
4664
+ ): void;
4665
+ export function glob(
4666
+ pattern: string | readonly string[],
4667
+ options: GlobOptionsWithFileTypes,
4668
+ callback: (
4669
+ err: NodeJS.ErrnoException | null,
4670
+ matches: Dirent[],
4671
+ ) => void,
4672
+ ): void;
4673
+ export function glob(
4674
+ pattern: string | readonly string[],
4675
+ options: GlobOptionsWithoutFileTypes,
4676
+ callback: (
4677
+ err: NodeJS.ErrnoException | null,
4678
+ matches: string[],
4679
+ ) => void,
4680
+ ): void;
4681
+ export function glob(
4682
+ pattern: string | readonly string[],
4683
+ options: GlobOptions,
4684
+ callback: (
4685
+ err: NodeJS.ErrnoException | null,
4686
+ matches: Dirent[] | string[],
4687
+ ) => void,
4688
+ ): void;
4689
+ /**
4690
+ * ```js
4691
+ * import { globSync } from 'node:fs';
4692
+ *
4693
+ * console.log(globSync('*.js'));
4694
+ * ```
4695
+ * @since v22.0.0
4696
+ * @returns paths of files that match the pattern.
4697
+ */
4698
+ export function globSync(pattern: string | readonly string[]): string[];
4699
+ export function globSync(
4700
+ pattern: string | readonly string[],
4701
+ options: GlobOptionsWithFileTypes,
4702
+ ): Dirent[];
4703
+ export function globSync(
4704
+ pattern: string | readonly string[],
4705
+ options: GlobOptionsWithoutFileTypes,
4706
+ ): string[];
4707
+ export function globSync(
4708
+ pattern: string | readonly string[],
4709
+ options: GlobOptions,
4710
+ ): Dirent[] | string[];
4286
4711
  }
4287
4712
  declare module "node:fs" {
4288
4713
  export * from "fs";