@ykdz/template 0.0.37 → 0.0.40

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 (225) hide show
  1. package/dist/application.d.ts +1 -52
  2. package/dist/application.js +0 -81
  3. package/dist/cli.js +14 -28
  4. package/dist/input-schemas.d.ts +30 -0
  5. package/dist/input-schemas.js +75 -0
  6. package/dist/main.d.ts +3 -14
  7. package/dist/main.js +496 -378
  8. package/dist/result-schemas.d.ts +222 -0
  9. package/dist/result-schemas.js +74 -0
  10. package/dist/standard-schema.d.ts +3 -0
  11. package/dist/standard-schema.js +29 -0
  12. package/node_modules/@standard-schema/spec/LICENSE +21 -0
  13. package/node_modules/@standard-schema/spec/README.md +198 -0
  14. package/node_modules/@standard-schema/spec/dist/index.cjs +18 -0
  15. package/node_modules/@standard-schema/spec/dist/index.d.cts +119 -0
  16. package/node_modules/@standard-schema/spec/dist/index.d.ts +119 -0
  17. package/node_modules/@standard-schema/spec/dist/index.js +0 -0
  18. package/node_modules/@standard-schema/spec/package.json +52 -0
  19. package/node_modules/@types/node/LICENSE +21 -0
  20. package/node_modules/@types/node/README.md +15 -0
  21. package/node_modules/@types/node/assert/strict.d.ts +111 -0
  22. package/node_modules/@types/node/assert.d.ts +1115 -0
  23. package/node_modules/@types/node/async_hooks.d.ts +619 -0
  24. package/node_modules/@types/node/buffer.buffer.d.ts +477 -0
  25. package/node_modules/@types/node/buffer.d.ts +1941 -0
  26. package/node_modules/@types/node/child_process.d.ts +1480 -0
  27. package/node_modules/@types/node/cluster.d.ts +578 -0
  28. package/node_modules/@types/node/compatibility/iterators.d.ts +21 -0
  29. package/node_modules/@types/node/console.d.ts +453 -0
  30. package/node_modules/@types/node/constants.d.ts +21 -0
  31. package/node_modules/@types/node/crypto.d.ts +5484 -0
  32. package/node_modules/@types/node/dgram.d.ts +715 -0
  33. package/node_modules/@types/node/diagnostics_channel.d.ts +576 -0
  34. package/node_modules/@types/node/dns/promises.d.ts +503 -0
  35. package/node_modules/@types/node/dns.d.ts +923 -0
  36. package/node_modules/@types/node/domain.d.ts +166 -0
  37. package/node_modules/@types/node/events.d.ts +967 -0
  38. package/node_modules/@types/node/fs/promises.d.ts +1354 -0
  39. package/node_modules/@types/node/fs.d.ts +4777 -0
  40. package/node_modules/@types/node/globals.d.ts +170 -0
  41. package/node_modules/@types/node/globals.typedarray.d.ts +41 -0
  42. package/node_modules/@types/node/http.d.ts +2246 -0
  43. package/node_modules/@types/node/http2.d.ts +2882 -0
  44. package/node_modules/@types/node/https.d.ts +585 -0
  45. package/node_modules/@types/node/index.d.ts +101 -0
  46. package/node_modules/@types/node/inspector.d.ts +323 -0
  47. package/node_modules/@types/node/inspector.generated.d.ts +4406 -0
  48. package/node_modules/@types/node/module.d.ts +844 -0
  49. package/node_modules/@types/node/net.d.ts +1197 -0
  50. package/node_modules/@types/node/os.d.ts +507 -0
  51. package/node_modules/@types/node/package.json +140 -0
  52. package/node_modules/@types/node/path.d.ts +200 -0
  53. package/node_modules/@types/node/perf_hooks.d.ts +1054 -0
  54. package/node_modules/@types/node/process.d.ts +2101 -0
  55. package/node_modules/@types/node/punycode.d.ts +117 -0
  56. package/node_modules/@types/node/querystring.d.ts +152 -0
  57. package/node_modules/@types/node/readline/promises.d.ts +161 -0
  58. package/node_modules/@types/node/readline.d.ts +600 -0
  59. package/node_modules/@types/node/repl.d.ts +438 -0
  60. package/node_modules/@types/node/sea.d.ts +162 -0
  61. package/node_modules/@types/node/sqlite.d.ts +1182 -0
  62. package/node_modules/@types/node/stream/consumers.d.ts +45 -0
  63. package/node_modules/@types/node/stream/promises.d.ts +90 -0
  64. package/node_modules/@types/node/stream/web.d.ts +596 -0
  65. package/node_modules/@types/node/stream.d.ts +1707 -0
  66. package/node_modules/@types/node/string_decoder.d.ts +67 -0
  67. package/node_modules/@types/node/test.d.ts +2656 -0
  68. package/node_modules/@types/node/timers/promises.d.ts +108 -0
  69. package/node_modules/@types/node/timers.d.ts +285 -0
  70. package/node_modules/@types/node/tls.d.ts +1314 -0
  71. package/node_modules/@types/node/trace_events.d.ts +197 -0
  72. package/node_modules/@types/node/ts5.6/buffer.buffer.d.ts +473 -0
  73. package/node_modules/@types/node/ts5.6/compatibility/float16array.d.ts +71 -0
  74. package/node_modules/@types/node/ts5.6/globals.typedarray.d.ts +36 -0
  75. package/node_modules/@types/node/ts5.6/index.d.ts +103 -0
  76. package/node_modules/@types/node/ts5.7/compatibility/float16array.d.ts +72 -0
  77. package/node_modules/@types/node/ts5.7/index.d.ts +103 -0
  78. package/node_modules/@types/node/tty.d.ts +209 -0
  79. package/node_modules/@types/node/url.d.ts +1103 -0
  80. package/node_modules/@types/node/util.d.ts +2376 -0
  81. package/node_modules/@types/node/v8.d.ts +1010 -0
  82. package/node_modules/@types/node/vm.d.ts +1160 -0
  83. package/node_modules/@types/node/wasi.d.ts +202 -0
  84. package/node_modules/@types/node/web-globals/abortcontroller.d.ts +34 -0
  85. package/node_modules/@types/node/web-globals/crypto.d.ts +32 -0
  86. package/node_modules/@types/node/web-globals/domexception.d.ts +68 -0
  87. package/node_modules/@types/node/web-globals/events.d.ts +97 -0
  88. package/node_modules/@types/node/web-globals/fetch.d.ts +62 -0
  89. package/node_modules/@types/node/web-globals/navigator.d.ts +25 -0
  90. package/node_modules/@types/node/web-globals/storage.d.ts +24 -0
  91. package/node_modules/@types/node/web-globals/streams.d.ts +22 -0
  92. package/node_modules/@types/node/worker_threads.d.ts +894 -0
  93. package/node_modules/@types/node/zlib.d.ts +768 -0
  94. package/node_modules/@valibot/to-json-schema/LICENSE.md +9 -0
  95. package/node_modules/@valibot/to-json-schema/README.md +475 -0
  96. package/node_modules/@valibot/to-json-schema/dist/index.cjs +800 -0
  97. package/node_modules/@valibot/to-json-schema/dist/index.d.cts +991 -0
  98. package/node_modules/@valibot/to-json-schema/dist/index.d.mts +991 -0
  99. package/node_modules/@valibot/to-json-schema/dist/index.min.cjs +1 -0
  100. package/node_modules/@valibot/to-json-schema/dist/index.min.mjs +1 -0
  101. package/node_modules/@valibot/to-json-schema/dist/index.mjs +795 -0
  102. package/node_modules/@valibot/to-json-schema/package.json +75 -0
  103. package/node_modules/@ykdz/cli-contract/LICENSE +21 -0
  104. package/node_modules/@ykdz/cli-contract/dist/atomic-variant-compiler.d.ts +17 -0
  105. package/node_modules/@ykdz/cli-contract/dist/atomic-variant-compiler.js +55 -0
  106. package/node_modules/@ykdz/cli-contract/dist/cli-contract.d.ts +1164 -0
  107. package/node_modules/@ykdz/cli-contract/dist/cli-contract.js +1408 -0
  108. package/node_modules/@ykdz/cli-contract/dist/cli-execution.d.ts +54 -0
  109. package/node_modules/@ykdz/cli-contract/dist/cli-execution.js +708 -0
  110. package/node_modules/@ykdz/cli-contract/dist/cli-invocation.d.ts +174 -0
  111. package/node_modules/@ykdz/cli-contract/dist/cli-invocation.js +524 -0
  112. package/node_modules/@ykdz/cli-contract/dist/cli-write-error.d.ts +10 -0
  113. package/node_modules/@ykdz/cli-contract/dist/cli-write-error.js +14 -0
  114. package/node_modules/@ykdz/cli-contract/dist/contract-definition-error.d.ts +260 -0
  115. package/node_modules/@ykdz/cli-contract/dist/contract-definition-error.js +130 -0
  116. package/node_modules/@ykdz/cli-contract/dist/contract-execution-error.d.ts +63 -0
  117. package/node_modules/@ykdz/cli-contract/dist/contract-execution-error.js +17 -0
  118. package/node_modules/@ykdz/cli-contract/dist/contract-schema-compiler.d.ts +6 -0
  119. package/node_modules/@ykdz/cli-contract/dist/contract-schema-compiler.js +532 -0
  120. package/node_modules/@ykdz/cli-contract/dist/contract-schema.d.ts +14 -0
  121. package/node_modules/@ykdz/cli-contract/dist/contract-schema.js +1 -0
  122. package/node_modules/@ykdz/cli-contract/dist/description.d.ts +2 -0
  123. package/node_modules/@ykdz/cli-contract/dist/description.js +13 -0
  124. package/node_modules/@ykdz/cli-contract/dist/index.d.ts +8 -0
  125. package/node_modules/@ykdz/cli-contract/dist/index.js +7 -0
  126. package/node_modules/@ykdz/cli-contract/dist/json-value.d.ts +4 -0
  127. package/node_modules/@ykdz/cli-contract/dist/json-value.js +64 -0
  128. package/node_modules/@ykdz/cli-contract/dist/node.d.ts +21 -0
  129. package/node_modules/@ykdz/cli-contract/dist/node.js +109 -0
  130. package/node_modules/@ykdz/cli-contract/dist/outcome-fact.d.ts +162 -0
  131. package/node_modules/@ykdz/cli-contract/dist/outcome-fact.js +113 -0
  132. package/node_modules/@ykdz/cli-contract/dist/outcome-wire.d.ts +53 -0
  133. package/node_modules/@ykdz/cli-contract/dist/outcome-wire.js +189 -0
  134. package/node_modules/@ykdz/cli-contract/dist/stream-variant-compiler.d.ts +16 -0
  135. package/node_modules/@ykdz/cli-contract/dist/stream-variant-compiler.js +45 -0
  136. package/node_modules/@ykdz/cli-contract/package.json +69 -0
  137. package/node_modules/@ykdz/template-builtin-presets/dist/src/foundation.d.ts +20 -0
  138. package/node_modules/@ykdz/template-builtin-presets/dist/src/foundation.js +27 -28
  139. package/node_modules/@ykdz/template-builtin-presets/dist/src/generation-record.d.ts +19 -0
  140. package/node_modules/@ykdz/template-builtin-presets/dist/src/generation-record.js +1 -1
  141. package/node_modules/@ykdz/template-builtin-presets/dist/src/index.d.ts +2 -1
  142. package/node_modules/@ykdz/template-builtin-presets/dist/src/index.js +2 -1
  143. package/node_modules/@ykdz/template-builtin-presets/dist/src/ts-cli/definition.js +9 -5
  144. package/node_modules/@ykdz/template-builtin-presets/dist/src/vike-app/definition.js +0 -4
  145. package/node_modules/@ykdz/template-builtin-presets/package.json +2 -1
  146. package/node_modules/@ykdz/template-builtin-presets/templates/foundation/AGENTS.md.template +10 -4
  147. package/node_modules/@ykdz/template-builtin-presets/templates/foundation/devcontainer.json +3 -0
  148. package/node_modules/@ykdz/template-builtin-presets/templates/ts-cli/publication/artifact.ts +128 -59
  149. package/node_modules/@ykdz/template-builtin-presets/templates/ts-cli/publication/handoff.ts +80 -8
  150. package/node_modules/@ykdz/template-builtin-presets/templates/ts-cli/publication/readiness.ts +7 -3
  151. package/node_modules/@ykdz/template-builtin-presets/templates/ts-cli/src/cli.ts +9 -19
  152. package/node_modules/@ykdz/template-builtin-presets/templates/ts-cli/src/main.ts +144 -60
  153. package/node_modules/@ykdz/template-builtin-presets/templates/ts-cli/src/standard-schema.ts +37 -0
  154. package/node_modules/@ykdz/template-builtin-presets/templates/ts-cli/test/e2e/journeys/lookup.journey.ts +71 -0
  155. package/node_modules/@ykdz/template-builtin-presets/templates/ts-cli/test/integration/command.test.ts +118 -59
  156. package/node_modules/@ykdz/template-core/dist/package-contribution.d.ts +0 -1
  157. package/node_modules/@ykdz/template-core/dist/pnpm-workspace.yaml +2 -1
  158. package/node_modules/@ykdz/template-core/dist/project-blueprint.d.ts +15 -0
  159. package/node_modules/@ykdz/template-core/dist/project-blueprint.js +1 -1
  160. package/node_modules/@ykdz/template-core/dist/project-github.d.ts +1 -1
  161. package/node_modules/undici-types/LICENSE +21 -0
  162. package/node_modules/undici-types/README.md +6 -0
  163. package/node_modules/undici-types/agent.d.ts +32 -0
  164. package/node_modules/undici-types/api.d.ts +43 -0
  165. package/node_modules/undici-types/balanced-pool.d.ts +30 -0
  166. package/node_modules/undici-types/cache-interceptor.d.ts +179 -0
  167. package/node_modules/undici-types/cache.d.ts +36 -0
  168. package/node_modules/undici-types/client-stats.d.ts +15 -0
  169. package/node_modules/undici-types/client.d.ts +123 -0
  170. package/node_modules/undici-types/connector.d.ts +36 -0
  171. package/node_modules/undici-types/content-type.d.ts +21 -0
  172. package/node_modules/undici-types/cookies.d.ts +30 -0
  173. package/node_modules/undici-types/diagnostics-channel.d.ts +74 -0
  174. package/node_modules/undici-types/dispatcher.d.ts +279 -0
  175. package/node_modules/undici-types/env-http-proxy-agent.d.ts +22 -0
  176. package/node_modules/undici-types/errors.d.ts +177 -0
  177. package/node_modules/undici-types/eventsource.d.ts +66 -0
  178. package/node_modules/undici-types/fetch.d.ts +211 -0
  179. package/node_modules/undici-types/formdata.d.ts +108 -0
  180. package/node_modules/undici-types/global-dispatcher.d.ts +9 -0
  181. package/node_modules/undici-types/global-origin.d.ts +7 -0
  182. package/node_modules/undici-types/h2c-client.d.ts +73 -0
  183. package/node_modules/undici-types/handlers.d.ts +15 -0
  184. package/node_modules/undici-types/header.d.ts +160 -0
  185. package/node_modules/undici-types/index.d.ts +91 -0
  186. package/node_modules/undici-types/interceptors.d.ts +80 -0
  187. package/node_modules/undici-types/mock-agent.d.ts +68 -0
  188. package/node_modules/undici-types/mock-call-history.d.ts +111 -0
  189. package/node_modules/undici-types/mock-client.d.ts +27 -0
  190. package/node_modules/undici-types/mock-errors.d.ts +12 -0
  191. package/node_modules/undici-types/mock-interceptor.d.ts +94 -0
  192. package/node_modules/undici-types/mock-pool.d.ts +27 -0
  193. package/node_modules/undici-types/package.json +55 -0
  194. package/node_modules/undici-types/patch.d.ts +29 -0
  195. package/node_modules/undici-types/pool-stats.d.ts +19 -0
  196. package/node_modules/undici-types/pool.d.ts +41 -0
  197. package/node_modules/undici-types/proxy-agent.d.ts +29 -0
  198. package/node_modules/undici-types/readable.d.ts +68 -0
  199. package/node_modules/undici-types/retry-agent.d.ts +8 -0
  200. package/node_modules/undici-types/retry-handler.d.ts +125 -0
  201. package/node_modules/undici-types/round-robin-pool.d.ts +41 -0
  202. package/node_modules/undici-types/snapshot-agent.d.ts +109 -0
  203. package/node_modules/undici-types/socks5-proxy-agent.d.ts +25 -0
  204. package/node_modules/undici-types/util.d.ts +18 -0
  205. package/node_modules/undici-types/utility.d.ts +7 -0
  206. package/node_modules/undici-types/webidl.d.ts +347 -0
  207. package/node_modules/undici-types/websocket.d.ts +188 -0
  208. package/package.json +5 -3
  209. package/dist/command-result.d.ts +0 -9
  210. package/dist/command-result.js +0 -231
  211. package/node_modules/@ykdz/template-builtin-presets/templates/ts-cli/test/e2e/journeys/greet.journey.ts +0 -46
  212. package/node_modules/@ykdz/template-builtin-presets/templates/ts-cli/test/unit/greet.test.ts +0 -15
  213. package/node_modules/@ykdz/template-builtin-presets/templates/vike-app/devcontainer/docker-client.Dockerfile +0 -3
  214. package/node_modules/commander/LICENSE +0 -22
  215. package/node_modules/commander/Readme.md +0 -1172
  216. package/node_modules/commander/index.js +0 -21
  217. package/node_modules/commander/lib/argument.js +0 -147
  218. package/node_modules/commander/lib/command.js +0 -2790
  219. package/node_modules/commander/lib/error.js +0 -36
  220. package/node_modules/commander/lib/help.js +0 -731
  221. package/node_modules/commander/lib/option.js +0 -377
  222. package/node_modules/commander/lib/suggestSimilar.js +0 -99
  223. package/node_modules/commander/package-support.json +0 -19
  224. package/node_modules/commander/package.json +0 -64
  225. package/node_modules/commander/typings/index.d.ts +0 -1113
@@ -0,0 +1,4777 @@
1
+ /**
2
+ * The `node:fs` module enables interacting with the file system in a
3
+ * way modeled on standard POSIX functions.
4
+ *
5
+ * To use the promise-based APIs:
6
+ *
7
+ * ```js
8
+ * import * as fs from 'node:fs/promises';
9
+ * ```
10
+ *
11
+ * To use the callback and sync APIs:
12
+ *
13
+ * ```js
14
+ * import * as fs from 'node:fs';
15
+ * ```
16
+ *
17
+ * All file system operations have synchronous, callback, and promise-based
18
+ * forms, and are accessible using both CommonJS syntax and ES6 Modules (ESM).
19
+ * @see [source](https://github.com/nodejs/node/blob/v24.x/lib/fs.js)
20
+ */
21
+ declare module "fs" {
22
+ import { BufferView, NonSharedBuffer } from "node:buffer";
23
+ import * as stream from "node:stream";
24
+ import { Abortable, EventEmitter } from "node:events";
25
+ import { URL } from "node:url";
26
+ import * as promises from "node:fs/promises";
27
+ export { promises };
28
+ /**
29
+ * Valid types for path values in "fs".
30
+ */
31
+ export type PathLike = string | Buffer | URL;
32
+ export type PathOrFileDescriptor = PathLike | number;
33
+ export type TimeLike = string | number | Date;
34
+ export type NoParamCallback = (err: NodeJS.ErrnoException | null) => void;
35
+ export type BufferEncodingOption =
36
+ | "buffer"
37
+ | {
38
+ encoding: "buffer";
39
+ };
40
+ export interface ObjectEncodingOptions {
41
+ encoding?: BufferEncoding | null | undefined;
42
+ }
43
+ export type EncodingOption = ObjectEncodingOptions | BufferEncoding | undefined | null;
44
+ export type OpenMode = number | string;
45
+ export type Mode = number | string;
46
+ export interface StatsBase<T> {
47
+ isFile(): boolean;
48
+ isDirectory(): boolean;
49
+ isBlockDevice(): boolean;
50
+ isCharacterDevice(): boolean;
51
+ isSymbolicLink(): boolean;
52
+ isFIFO(): boolean;
53
+ isSocket(): boolean;
54
+ dev: T;
55
+ ino: T;
56
+ mode: T;
57
+ nlink: T;
58
+ uid: T;
59
+ gid: T;
60
+ rdev: T;
61
+ size: T;
62
+ blksize: T;
63
+ blocks: T;
64
+ atimeMs: T;
65
+ mtimeMs: T;
66
+ ctimeMs: T;
67
+ birthtimeMs: T;
68
+ atime: Date;
69
+ mtime: Date;
70
+ ctime: Date;
71
+ birthtime: Date;
72
+ }
73
+ export interface Stats extends StatsBase<number> {}
74
+ /**
75
+ * A `fs.Stats` object provides information about a file.
76
+ *
77
+ * Objects returned from {@link stat}, {@link lstat}, {@link fstat}, and
78
+ * their synchronous counterparts are of this type.
79
+ * If `bigint` in the `options` passed to those methods is true, the numeric values
80
+ * will be `bigint` instead of `number`, and the object will contain additional
81
+ * nanosecond-precision properties suffixed with `Ns`. `Stat` objects are not to be created directly using the `new` keyword.
82
+ *
83
+ * ```console
84
+ * Stats {
85
+ * dev: 2114,
86
+ * ino: 48064969,
87
+ * mode: 33188,
88
+ * nlink: 1,
89
+ * uid: 85,
90
+ * gid: 100,
91
+ * rdev: 0,
92
+ * size: 527,
93
+ * blksize: 4096,
94
+ * blocks: 8,
95
+ * atimeMs: 1318289051000.1,
96
+ * mtimeMs: 1318289051000.1,
97
+ * ctimeMs: 1318289051000.1,
98
+ * birthtimeMs: 1318289051000.1,
99
+ * atime: Mon, 10 Oct 2011 23:24:11 GMT,
100
+ * mtime: Mon, 10 Oct 2011 23:24:11 GMT,
101
+ * ctime: Mon, 10 Oct 2011 23:24:11 GMT,
102
+ * birthtime: Mon, 10 Oct 2011 23:24:11 GMT }
103
+ * ```
104
+ *
105
+ * `bigint` version:
106
+ *
107
+ * ```console
108
+ * BigIntStats {
109
+ * dev: 2114n,
110
+ * ino: 48064969n,
111
+ * mode: 33188n,
112
+ * nlink: 1n,
113
+ * uid: 85n,
114
+ * gid: 100n,
115
+ * rdev: 0n,
116
+ * size: 527n,
117
+ * blksize: 4096n,
118
+ * blocks: 8n,
119
+ * atimeMs: 1318289051000n,
120
+ * mtimeMs: 1318289051000n,
121
+ * ctimeMs: 1318289051000n,
122
+ * birthtimeMs: 1318289051000n,
123
+ * atimeNs: 1318289051000000000n,
124
+ * mtimeNs: 1318289051000000000n,
125
+ * ctimeNs: 1318289051000000000n,
126
+ * birthtimeNs: 1318289051000000000n,
127
+ * atime: Mon, 10 Oct 2011 23:24:11 GMT,
128
+ * mtime: Mon, 10 Oct 2011 23:24:11 GMT,
129
+ * ctime: Mon, 10 Oct 2011 23:24:11 GMT,
130
+ * birthtime: Mon, 10 Oct 2011 23:24:11 GMT }
131
+ * ```
132
+ * @since v0.1.21
133
+ */
134
+ export class Stats {
135
+ private constructor();
136
+ }
137
+ export interface StatsFsBase<T> {
138
+ /** Type of file system. */
139
+ type: T;
140
+ /** Optimal transfer block size. */
141
+ bsize: T;
142
+ /** Total data blocks in file system. */
143
+ blocks: T;
144
+ /** Free blocks in file system. */
145
+ bfree: T;
146
+ /** Available blocks for unprivileged users */
147
+ bavail: T;
148
+ /** Total file nodes in file system. */
149
+ files: T;
150
+ /** Fundamental file system block size. */
151
+ frsize: T;
152
+ /** Free file nodes in file system. */
153
+ ffree: T;
154
+ }
155
+ export interface StatsFs extends StatsFsBase<number> {}
156
+ /**
157
+ * Provides information about a mounted file system.
158
+ *
159
+ * Objects returned from {@link statfs} and its synchronous counterpart are of
160
+ * this type. If `bigint` in the `options` passed to those methods is `true`, the
161
+ * numeric values will be `bigint` instead of `number`.
162
+ *
163
+ * ```console
164
+ * StatFs {
165
+ * type: 1397114950,
166
+ * bsize: 4096,
167
+ * blocks: 121938943,
168
+ * bfree: 61058895,
169
+ * bavail: 61058895,
170
+ * files: 999,
171
+ * ffree: 1000000
172
+ * }
173
+ * ```
174
+ *
175
+ * `bigint` version:
176
+ *
177
+ * ```console
178
+ * StatFs {
179
+ * type: 1397114950n,
180
+ * bsize: 4096n,
181
+ * blocks: 121938943n,
182
+ * bfree: 61058895n,
183
+ * bavail: 61058895n,
184
+ * files: 999n,
185
+ * ffree: 1000000n
186
+ * }
187
+ * ```
188
+ * @since v19.6.0, v18.15.0
189
+ */
190
+ export class StatsFs {}
191
+ export interface BigIntStatsFs extends StatsFsBase<bigint> {}
192
+ export interface StatFsOptions {
193
+ bigint?: boolean | undefined;
194
+ }
195
+ /**
196
+ * A representation of a directory entry, which can be a file or a subdirectory
197
+ * within the directory, as returned by reading from an `fs.Dir`. The
198
+ * directory entry is a combination of the file name and file type pairs.
199
+ *
200
+ * Additionally, when {@link readdir} or {@link readdirSync} is called with
201
+ * the `withFileTypes` option set to `true`, the resulting array is filled with `fs.Dirent` objects, rather than strings or `Buffer` s.
202
+ * @since v10.10.0
203
+ */
204
+ export class Dirent<Name extends string | Buffer = string> {
205
+ /**
206
+ * Returns `true` if the `fs.Dirent` object describes a regular file.
207
+ * @since v10.10.0
208
+ */
209
+ isFile(): boolean;
210
+ /**
211
+ * Returns `true` if the `fs.Dirent` object describes a file system
212
+ * directory.
213
+ * @since v10.10.0
214
+ */
215
+ isDirectory(): boolean;
216
+ /**
217
+ * Returns `true` if the `fs.Dirent` object describes a block device.
218
+ * @since v10.10.0
219
+ */
220
+ isBlockDevice(): boolean;
221
+ /**
222
+ * Returns `true` if the `fs.Dirent` object describes a character device.
223
+ * @since v10.10.0
224
+ */
225
+ isCharacterDevice(): boolean;
226
+ /**
227
+ * Returns `true` if the `fs.Dirent` object describes a symbolic link.
228
+ * @since v10.10.0
229
+ */
230
+ isSymbolicLink(): boolean;
231
+ /**
232
+ * Returns `true` if the `fs.Dirent` object describes a first-in-first-out
233
+ * (FIFO) pipe.
234
+ * @since v10.10.0
235
+ */
236
+ isFIFO(): boolean;
237
+ /**
238
+ * Returns `true` if the `fs.Dirent` object describes a socket.
239
+ * @since v10.10.0
240
+ */
241
+ isSocket(): boolean;
242
+ /**
243
+ * The file name that this `fs.Dirent` object refers to. The type of this
244
+ * value is determined by the `options.encoding` passed to {@link readdir} or {@link readdirSync}.
245
+ * @since v10.10.0
246
+ */
247
+ name: Name;
248
+ /**
249
+ * The path to the parent directory of the file this `fs.Dirent` object refers to.
250
+ * @since v20.12.0, v18.20.0
251
+ */
252
+ parentPath: string;
253
+ }
254
+ /**
255
+ * A class representing a directory stream.
256
+ *
257
+ * Created by {@link opendir}, {@link opendirSync}, or `fsPromises.opendir()`.
258
+ *
259
+ * ```js
260
+ * import { opendir } from 'node:fs/promises';
261
+ *
262
+ * try {
263
+ * const dir = await opendir('./');
264
+ * for await (const dirent of dir)
265
+ * console.log(dirent.name);
266
+ * } catch (err) {
267
+ * console.error(err);
268
+ * }
269
+ * ```
270
+ *
271
+ * When using the async iterator, the `fs.Dir` object will be automatically
272
+ * closed after the iterator exits.
273
+ * @since v12.12.0
274
+ */
275
+ export class Dir implements AsyncIterable<Dirent> {
276
+ /**
277
+ * The read-only path of this directory as was provided to {@link opendir},{@link opendirSync}, or `fsPromises.opendir()`.
278
+ * @since v12.12.0
279
+ */
280
+ readonly path: string;
281
+ /**
282
+ * Asynchronously iterates over the directory via `readdir(3)` until all entries have been read.
283
+ */
284
+ [Symbol.asyncIterator](): NodeJS.AsyncIterator<Dirent>;
285
+ /**
286
+ * Asynchronously close the directory's underlying resource handle.
287
+ * Subsequent reads will result in errors.
288
+ *
289
+ * A promise is returned that will be fulfilled after the resource has been
290
+ * closed.
291
+ * @since v12.12.0
292
+ */
293
+ close(): Promise<void>;
294
+ close(cb: NoParamCallback): void;
295
+ /**
296
+ * Synchronously close the directory's underlying resource handle.
297
+ * Subsequent reads will result in errors.
298
+ * @since v12.12.0
299
+ */
300
+ closeSync(): void;
301
+ /**
302
+ * Asynchronously read the next directory entry via [`readdir(3)`](http://man7.org/linux/man-pages/man3/readdir.3.html) as an `fs.Dirent`.
303
+ *
304
+ * A promise is returned that will be fulfilled with an `fs.Dirent`, or `null` if there are no more directory entries to read.
305
+ *
306
+ * Directory entries returned by this function are in no particular order as
307
+ * provided by the operating system's underlying directory mechanisms.
308
+ * Entries added or removed while iterating over the directory might not be
309
+ * included in the iteration results.
310
+ * @since v12.12.0
311
+ * @return containing {fs.Dirent|null}
312
+ */
313
+ read(): Promise<Dirent | null>;
314
+ read(cb: (err: NodeJS.ErrnoException | null, dirEnt: Dirent | null) => void): void;
315
+ /**
316
+ * Synchronously read the next directory entry as an `fs.Dirent`. See the
317
+ * POSIX [`readdir(3)`](http://man7.org/linux/man-pages/man3/readdir.3.html) documentation for more detail.
318
+ *
319
+ * If there are no more directory entries to read, `null` will be returned.
320
+ *
321
+ * Directory entries returned by this function are in no particular order as
322
+ * provided by the operating system's underlying directory mechanisms.
323
+ * Entries added or removed while iterating over the directory might not be
324
+ * included in the iteration results.
325
+ * @since v12.12.0
326
+ */
327
+ readSync(): Dirent | null;
328
+ /**
329
+ * Calls `dir.close()` if the directory handle is open, and returns a promise that
330
+ * fulfills when disposal is complete.
331
+ * @since v24.1.0
332
+ */
333
+ [Symbol.asyncDispose](): Promise<void>;
334
+ /**
335
+ * Calls `dir.closeSync()` if the directory handle is open, and returns
336
+ * `undefined`.
337
+ * @since v24.1.0
338
+ */
339
+ [Symbol.dispose](): void;
340
+ }
341
+ /**
342
+ * Class: fs.StatWatcher
343
+ * @since v14.3.0, v12.20.0
344
+ * Extends `EventEmitter`
345
+ * A successful call to {@link watchFile} method will return a new fs.StatWatcher object.
346
+ */
347
+ export interface StatWatcher extends EventEmitter {
348
+ /**
349
+ * When called, requests that the Node.js event loop _not_ exit so long as the `fs.StatWatcher` is active. Calling `watcher.ref()` multiple times will have
350
+ * no effect.
351
+ *
352
+ * By default, all `fs.StatWatcher` objects are "ref'ed", making it normally
353
+ * unnecessary to call `watcher.ref()` unless `watcher.unref()` had been
354
+ * called previously.
355
+ * @since v14.3.0, v12.20.0
356
+ */
357
+ ref(): this;
358
+ /**
359
+ * When called, the active `fs.StatWatcher` object will not require the Node.js
360
+ * event loop to remain active. If there is no other activity keeping the
361
+ * event loop running, the process may exit before the `fs.StatWatcher` object's
362
+ * callback is invoked. Calling `watcher.unref()` multiple times will have
363
+ * no effect.
364
+ * @since v14.3.0, v12.20.0
365
+ */
366
+ unref(): this;
367
+ }
368
+ export interface FSWatcher extends EventEmitter {
369
+ /**
370
+ * Stop watching for changes on the given `fs.FSWatcher`. Once stopped, the `fs.FSWatcher` object is no longer usable.
371
+ * @since v0.5.8
372
+ */
373
+ close(): void;
374
+ /**
375
+ * 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
376
+ * no effect.
377
+ *
378
+ * By default, all `fs.FSWatcher` objects are "ref'ed", making it normally
379
+ * unnecessary to call `watcher.ref()` unless `watcher.unref()` had been
380
+ * called previously.
381
+ * @since v14.3.0, v12.20.0
382
+ */
383
+ ref(): this;
384
+ /**
385
+ * When called, the active `fs.FSWatcher` object will not require the Node.js
386
+ * event loop to remain active. If there is no other activity keeping the
387
+ * event loop running, the process may exit before the `fs.FSWatcher` object's
388
+ * callback is invoked. Calling `watcher.unref()` multiple times will have
389
+ * no effect.
390
+ * @since v14.3.0, v12.20.0
391
+ */
392
+ unref(): this;
393
+ /**
394
+ * events.EventEmitter
395
+ * 1. change
396
+ * 2. close
397
+ * 3. error
398
+ */
399
+ addListener(event: string, listener: (...args: any[]) => void): this;
400
+ addListener(event: "change", listener: (eventType: string, filename: string | NonSharedBuffer) => void): this;
401
+ addListener(event: "close", listener: () => void): this;
402
+ addListener(event: "error", listener: (error: Error) => void): this;
403
+ on(event: string, listener: (...args: any[]) => void): this;
404
+ on(event: "change", listener: (eventType: string, filename: string | NonSharedBuffer) => void): this;
405
+ on(event: "close", listener: () => void): this;
406
+ on(event: "error", listener: (error: Error) => void): this;
407
+ once(event: string, listener: (...args: any[]) => void): this;
408
+ once(event: "change", listener: (eventType: string, filename: string | NonSharedBuffer) => void): this;
409
+ once(event: "close", listener: () => void): this;
410
+ once(event: "error", listener: (error: Error) => void): this;
411
+ prependListener(event: string, listener: (...args: any[]) => void): this;
412
+ prependListener(
413
+ event: "change",
414
+ listener: (eventType: string, filename: string | NonSharedBuffer) => void,
415
+ ): this;
416
+ prependListener(event: "close", listener: () => void): this;
417
+ prependListener(event: "error", listener: (error: Error) => void): this;
418
+ prependOnceListener(event: string, listener: (...args: any[]) => void): this;
419
+ prependOnceListener(
420
+ event: "change",
421
+ listener: (eventType: string, filename: string | NonSharedBuffer) => void,
422
+ ): this;
423
+ prependOnceListener(event: "close", listener: () => void): this;
424
+ prependOnceListener(event: "error", listener: (error: Error) => void): this;
425
+ }
426
+ /**
427
+ * Instances of `fs.ReadStream` cannot be constructed directly. They are created and
428
+ * returned using the `fs.createReadStream()` function.
429
+ * @since v0.1.93
430
+ */
431
+ export class ReadStream extends stream.Readable {
432
+ close(callback?: (err?: NodeJS.ErrnoException | null) => void): void;
433
+ /**
434
+ * The number of bytes that have been read so far.
435
+ * @since v6.4.0
436
+ */
437
+ bytesRead: number;
438
+ /**
439
+ * The path to the file the stream is reading from as specified in the first
440
+ * argument to `fs.createReadStream()`. If `path` is passed as a string, then`readStream.path` will be a string. If `path` is passed as a `Buffer`, then`readStream.path` will be a
441
+ * `Buffer`. If `fd` is specified, then`readStream.path` will be `undefined`.
442
+ * @since v0.1.93
443
+ */
444
+ path: string | Buffer;
445
+ /**
446
+ * This property is `true` if the underlying file has not been opened yet,
447
+ * i.e. before the `'ready'` event is emitted.
448
+ * @since v11.2.0, v10.16.0
449
+ */
450
+ pending: boolean;
451
+ /**
452
+ * events.EventEmitter
453
+ * 1. open
454
+ * 2. close
455
+ * 3. ready
456
+ */
457
+ addListener<K extends keyof ReadStreamEvents>(event: K, listener: ReadStreamEvents[K]): this;
458
+ on<K extends keyof ReadStreamEvents>(event: K, listener: ReadStreamEvents[K]): this;
459
+ once<K extends keyof ReadStreamEvents>(event: K, listener: ReadStreamEvents[K]): this;
460
+ prependListener<K extends keyof ReadStreamEvents>(event: K, listener: ReadStreamEvents[K]): this;
461
+ prependOnceListener<K extends keyof ReadStreamEvents>(event: K, listener: ReadStreamEvents[K]): this;
462
+ }
463
+ export interface Utf8StreamOptions {
464
+ /**
465
+ * Appends writes to dest file instead of truncating it.
466
+ * @default true
467
+ */
468
+ append?: boolean | undefined;
469
+ /**
470
+ * Which type of data you can send to the write
471
+ * function, supported values are `'utf8'` or `'buffer'`.
472
+ * @default 'utf8'
473
+ */
474
+ contentMode?: "utf8" | "buffer" | undefined;
475
+ /**
476
+ * A path to a file to be written to (mode controlled by the
477
+ * append option).
478
+ */
479
+ dest?: string | undefined;
480
+ /**
481
+ * A file descriptor, something that is returned by `fs.open()`
482
+ * or `fs.openSync()`.
483
+ */
484
+ fd?: number | undefined;
485
+ /**
486
+ * An object that has the same API as the `fs` module, useful
487
+ * for mocking, testing, or customizing the behavior of the stream.
488
+ */
489
+ fs?: object | undefined;
490
+ /**
491
+ * Perform a `fs.fsyncSync()` every time a write is
492
+ * completed.
493
+ */
494
+ fsync?: boolean | undefined;
495
+ /**
496
+ * The maximum length of the internal buffer. If a write
497
+ * operation would cause the buffer to exceed `maxLength`, the data written is
498
+ * dropped and a drop event is emitted with the dropped data
499
+ */
500
+ maxLength?: number | undefined;
501
+ /**
502
+ * The maximum number of bytes that can be written;
503
+ * @default 16384
504
+ */
505
+ maxWrite?: number | undefined;
506
+ /**
507
+ * The minimum length of the internal buffer that is
508
+ * required to be full before flushing.
509
+ */
510
+ minLength?: number | undefined;
511
+ /**
512
+ * Ensure directory for `dest` file exists when true.
513
+ * @default false
514
+ */
515
+ mkdir?: boolean | undefined;
516
+ /**
517
+ * Specify the creating file mode (see `fs.open()`).
518
+ */
519
+ mode?: number | string | undefined;
520
+ /**
521
+ * Calls flush every `periodicFlush` milliseconds.
522
+ */
523
+ periodicFlush?: number | undefined;
524
+ /**
525
+ * A function that will be called when `write()`,
526
+ * `writeSync()`, or `flushSync()` encounters an `EAGAIN` or `EBUSY` error.
527
+ * If the return value is `true` the operation will be retried, otherwise it
528
+ * will bubble the error. The `err` is the error that caused this function to
529
+ * be called, `writeBufferLen` is the length of the buffer that was written,
530
+ * and `remainingBufferLen` is the length of the remaining buffer that the
531
+ * stream did not try to write.
532
+ */
533
+ retryEAGAIN?: ((err: Error | null, writeBufferLen: number, remainingBufferLen: number) => boolean) | undefined;
534
+ /**
535
+ * Perform writes synchronously.
536
+ */
537
+ sync?: boolean | undefined;
538
+ }
539
+ /**
540
+ * An optimized UTF-8 stream writer that allows for flushing all the internal
541
+ * buffering on demand. It handles `EAGAIN` errors correctly, allowing for
542
+ * customization, for example, by dropping content if the disk is busy.
543
+ * @since v24.6.0
544
+ * @experimental
545
+ */
546
+ export class Utf8Stream extends EventEmitter {
547
+ constructor(options: Utf8StreamOptions);
548
+ /**
549
+ * Whether the stream is appending to the file or truncating it.
550
+ */
551
+ readonly append: boolean;
552
+ /**
553
+ * The type of data that can be written to the stream. Supported
554
+ * values are `'utf8'` or `'buffer'`.
555
+ * @default 'utf8'
556
+ */
557
+ readonly contentMode: "utf8" | "buffer";
558
+ /**
559
+ * Close the stream immediately, without flushing the internal buffer.
560
+ */
561
+ destroy(): void;
562
+ /**
563
+ * Close the stream gracefully, flushing the internal buffer before closing.
564
+ */
565
+ end(): void;
566
+ /**
567
+ * The file descriptor that is being written to.
568
+ */
569
+ readonly fd: number;
570
+ /**
571
+ * The file that is being written to.
572
+ */
573
+ readonly file: string;
574
+ /**
575
+ * Writes the current buffer to the file if a write was not in progress. Do
576
+ * nothing if `minLength` is zero or if it is already writing.
577
+ */
578
+ flush(callback: (err: Error | null) => void): void;
579
+ /**
580
+ * Flushes the buffered data synchronously. This is a costly operation.
581
+ */
582
+ flushSync(): void;
583
+ /**
584
+ * Whether the stream is performing a `fs.fsyncSync()` after every
585
+ * write operation.
586
+ */
587
+ readonly fsync: boolean;
588
+ /**
589
+ * The maximum length of the internal buffer. If a write
590
+ * operation would cause the buffer to exceed `maxLength`, the data written is
591
+ * dropped and a drop event is emitted with the dropped data.
592
+ */
593
+ readonly maxLength: number;
594
+ /**
595
+ * The minimum length of the internal buffer that is required to be
596
+ * full before flushing.
597
+ */
598
+ readonly minLength: number;
599
+ /**
600
+ * Whether the stream should ensure that the directory for the
601
+ * `dest` file exists. If `true`, it will create the directory if it does not
602
+ * exist.
603
+ * @default false
604
+ */
605
+ readonly mkdir: boolean;
606
+ /**
607
+ * The mode of the file that is being written to.
608
+ */
609
+ readonly mode: number | string;
610
+ /**
611
+ * The number of milliseconds between flushes. If set to `0`, no
612
+ * periodic flushes will be performed.
613
+ */
614
+ readonly periodicFlush: number;
615
+ /**
616
+ * Reopen the file in place, useful for log rotation.
617
+ * @param file A path to a file to be written to (mode
618
+ * controlled by the append option).
619
+ */
620
+ reopen(file: PathLike): void;
621
+ /**
622
+ * Whether the stream is writing synchronously or asynchronously.
623
+ */
624
+ readonly sync: boolean;
625
+ /**
626
+ * When the `options.contentMode` is set to `'utf8'` when the stream is created,
627
+ * the `data` argument must be a string. If the `contentMode` is set to `'buffer'`,
628
+ * the `data` argument must be a `Buffer`.
629
+ * @param data The data to write.
630
+ */
631
+ write(data: string | Buffer): boolean;
632
+ /**
633
+ * Whether the stream is currently writing data to the file.
634
+ */
635
+ readonly writing: boolean;
636
+ /**
637
+ * Calls `utf8Stream.destroy()`.
638
+ */
639
+ [Symbol.dispose](): void;
640
+ /**
641
+ * events.EventEmitter
642
+ * 1. change
643
+ * 2. close
644
+ * 3. error
645
+ */
646
+ addListener(event: "close", listener: () => void): this;
647
+ addListener(event: "drain", listener: () => void): this;
648
+ addListener(event: "drop", listener: (data: string | Buffer) => void): this;
649
+ addListener(event: "error", listener: (error: Error) => void): this;
650
+ addListener(event: "finish", listener: () => void): this;
651
+ addListener(event: "ready", listener: () => void): this;
652
+ addListener(event: "write", listener: (n: number) => void): this;
653
+ addListener(event: string, listener: (...args: any[]) => void): this;
654
+ on(event: "close", listener: () => void): this;
655
+ on(event: "drain", listener: () => void): this;
656
+ on(event: "drop", listener: (data: string | Buffer) => void): this;
657
+ on(event: "error", listener: (error: Error) => void): this;
658
+ on(event: "finish", listener: () => void): this;
659
+ on(event: "ready", listener: () => void): this;
660
+ on(event: "write", listener: (n: number) => void): this;
661
+ on(event: string, listener: (...args: any[]) => void): this;
662
+ once(event: "close", listener: () => void): this;
663
+ once(event: "drain", listener: () => void): this;
664
+ once(event: "drop", listener: (data: string | Buffer) => void): this;
665
+ once(event: "error", listener: (error: Error) => void): this;
666
+ once(event: "finish", listener: () => void): this;
667
+ once(event: "ready", listener: () => void): this;
668
+ once(event: "write", listener: (n: number) => void): this;
669
+ once(event: string, listener: (...args: any[]) => void): this;
670
+ prependListener(event: "close", listener: () => void): this;
671
+ prependListener(event: "drain", listener: () => void): this;
672
+ prependListener(event: "drop", listener: (data: string | Buffer) => void): this;
673
+ prependListener(event: "error", listener: (error: Error) => void): this;
674
+ prependListener(event: "finish", listener: () => void): this;
675
+ prependListener(event: "ready", listener: () => void): this;
676
+ prependListener(event: "write", listener: (n: number) => void): this;
677
+ prependListener(event: string, listener: (...args: any[]) => void): this;
678
+ prependOnceListener(event: "close", listener: () => void): this;
679
+ prependOnceListener(event: "drain", listener: () => void): this;
680
+ prependOnceListener(event: "drop", listener: (data: string | Buffer) => void): this;
681
+ prependOnceListener(event: "error", listener: (error: Error) => void): this;
682
+ prependOnceListener(event: "finish", listener: () => void): this;
683
+ prependOnceListener(event: "ready", listener: () => void): this;
684
+ prependOnceListener(event: "write", listener: (n: number) => void): this;
685
+ prependOnceListener(event: string, listener: (...args: any[]) => void): this;
686
+ }
687
+
688
+ /**
689
+ * The Keys are events of the ReadStream and the values are the functions that are called when the event is emitted.
690
+ */
691
+ type ReadStreamEvents = {
692
+ close: () => void;
693
+ data: (chunk: Buffer | string) => void;
694
+ end: () => void;
695
+ error: (err: Error) => void;
696
+ open: (fd: number) => void;
697
+ pause: () => void;
698
+ readable: () => void;
699
+ ready: () => void;
700
+ resume: () => void;
701
+ } & CustomEvents;
702
+
703
+ /**
704
+ * string & {} allows to allow any kind of strings for the event
705
+ * but still allows to have auto completion for the normal events.
706
+ */
707
+ type CustomEvents = { [Key in string & {} | symbol]: (...args: any[]) => void };
708
+
709
+ /**
710
+ * The Keys are events of the WriteStream and the values are the functions that are called when the event is emitted.
711
+ */
712
+ type WriteStreamEvents = {
713
+ close: () => void;
714
+ drain: () => void;
715
+ error: (err: Error) => void;
716
+ finish: () => void;
717
+ open: (fd: number) => void;
718
+ pipe: (src: stream.Readable) => void;
719
+ ready: () => void;
720
+ unpipe: (src: stream.Readable) => void;
721
+ } & CustomEvents;
722
+ /**
723
+ * Instances of `fs.WriteStream` cannot be constructed directly. They are created and
724
+ * returned using the `fs.createWriteStream()` function.
725
+ * @since v0.1.93
726
+ */
727
+ export class WriteStream extends stream.Writable {
728
+ /**
729
+ * Closes `writeStream`. Optionally accepts a
730
+ * callback that will be executed once the `writeStream`is closed.
731
+ * @since v0.9.4
732
+ */
733
+ close(callback?: (err?: NodeJS.ErrnoException | null) => void): void;
734
+ /**
735
+ * The number of bytes written so far. Does not include data that is still queued
736
+ * for writing.
737
+ * @since v0.4.7
738
+ */
739
+ bytesWritten: number;
740
+ /**
741
+ * The path to the file the stream is writing to as specified in the first
742
+ * argument to {@link createWriteStream}. If `path` is passed as a string, then`writeStream.path` will be a string. If `path` is passed as a `Buffer`, then`writeStream.path` will be a
743
+ * `Buffer`.
744
+ * @since v0.1.93
745
+ */
746
+ path: string | Buffer;
747
+ /**
748
+ * This property is `true` if the underlying file has not been opened yet,
749
+ * i.e. before the `'ready'` event is emitted.
750
+ * @since v11.2.0
751
+ */
752
+ pending: boolean;
753
+ /**
754
+ * events.EventEmitter
755
+ * 1. open
756
+ * 2. close
757
+ * 3. ready
758
+ */
759
+ addListener<K extends keyof WriteStreamEvents>(event: K, listener: WriteStreamEvents[K]): this;
760
+ on<K extends keyof WriteStreamEvents>(event: K, listener: WriteStreamEvents[K]): this;
761
+ once<K extends keyof WriteStreamEvents>(event: K, listener: WriteStreamEvents[K]): this;
762
+ prependListener<K extends keyof WriteStreamEvents>(event: K, listener: WriteStreamEvents[K]): this;
763
+ prependOnceListener<K extends keyof WriteStreamEvents>(event: K, listener: WriteStreamEvents[K]): this;
764
+ }
765
+ /**
766
+ * Asynchronously rename file at `oldPath` to the pathname provided
767
+ * as `newPath`. In the case that `newPath` already exists, it will
768
+ * be overwritten. If there is a directory at `newPath`, an error will
769
+ * be raised instead. No arguments other than a possible exception are
770
+ * given to the completion callback.
771
+ *
772
+ * See also: [`rename(2)`](http://man7.org/linux/man-pages/man2/rename.2.html).
773
+ *
774
+ * ```js
775
+ * import { rename } from 'node:fs';
776
+ *
777
+ * rename('oldFile.txt', 'newFile.txt', (err) => {
778
+ * if (err) throw err;
779
+ * console.log('Rename complete!');
780
+ * });
781
+ * ```
782
+ * @since v0.0.2
783
+ */
784
+ export function rename(oldPath: PathLike, newPath: PathLike, callback: NoParamCallback): void;
785
+ export namespace rename {
786
+ /**
787
+ * Asynchronous rename(2) - Change the name or location of a file or directory.
788
+ * @param oldPath A path to a file. If a URL is provided, it must use the `file:` protocol.
789
+ * URL support is _experimental_.
790
+ * @param newPath A path to a file. If a URL is provided, it must use the `file:` protocol.
791
+ * URL support is _experimental_.
792
+ */
793
+ function __promisify__(oldPath: PathLike, newPath: PathLike): Promise<void>;
794
+ }
795
+ /**
796
+ * Renames the file from `oldPath` to `newPath`. Returns `undefined`.
797
+ *
798
+ * See the POSIX [`rename(2)`](http://man7.org/linux/man-pages/man2/rename.2.html) documentation for more details.
799
+ * @since v0.1.21
800
+ */
801
+ export function renameSync(oldPath: PathLike, newPath: PathLike): void;
802
+ /**
803
+ * Truncates the file. No arguments other than a possible exception are
804
+ * given to the completion callback. A file descriptor can also be passed as the
805
+ * first argument. In this case, `fs.ftruncate()` is called.
806
+ *
807
+ * ```js
808
+ * import { truncate } from 'node:fs';
809
+ * // Assuming that 'path/file.txt' is a regular file.
810
+ * truncate('path/file.txt', (err) => {
811
+ * if (err) throw err;
812
+ * console.log('path/file.txt was truncated');
813
+ * });
814
+ * ```
815
+ *
816
+ * Passing a file descriptor is deprecated and may result in an error being thrown
817
+ * in the future.
818
+ *
819
+ * See the POSIX [`truncate(2)`](http://man7.org/linux/man-pages/man2/truncate.2.html) documentation for more details.
820
+ * @since v0.8.6
821
+ * @param [len=0]
822
+ */
823
+ export function truncate(path: PathLike, len: number | undefined, callback: NoParamCallback): void;
824
+ /**
825
+ * Asynchronous truncate(2) - Truncate a file to a specified length.
826
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
827
+ */
828
+ export function truncate(path: PathLike, callback: NoParamCallback): void;
829
+ export namespace truncate {
830
+ /**
831
+ * Asynchronous truncate(2) - Truncate a file to a specified length.
832
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
833
+ * @param len If not specified, defaults to `0`.
834
+ */
835
+ function __promisify__(path: PathLike, len?: number): Promise<void>;
836
+ }
837
+ /**
838
+ * Truncates the file. Returns `undefined`. A file descriptor can also be
839
+ * passed as the first argument. In this case, `fs.ftruncateSync()` is called.
840
+ *
841
+ * Passing a file descriptor is deprecated and may result in an error being thrown
842
+ * in the future.
843
+ * @since v0.8.6
844
+ * @param [len=0]
845
+ */
846
+ export function truncateSync(path: PathLike, len?: number): void;
847
+ /**
848
+ * Truncates the file descriptor. No arguments other than a possible exception are
849
+ * given to the completion callback.
850
+ *
851
+ * See the POSIX [`ftruncate(2)`](http://man7.org/linux/man-pages/man2/ftruncate.2.html) documentation for more detail.
852
+ *
853
+ * If the file referred to by the file descriptor was larger than `len` bytes, only
854
+ * the first `len` bytes will be retained in the file.
855
+ *
856
+ * For example, the following program retains only the first four bytes of the
857
+ * file:
858
+ *
859
+ * ```js
860
+ * import { open, close, ftruncate } from 'node:fs';
861
+ *
862
+ * function closeFd(fd) {
863
+ * close(fd, (err) => {
864
+ * if (err) throw err;
865
+ * });
866
+ * }
867
+ *
868
+ * open('temp.txt', 'r+', (err, fd) => {
869
+ * if (err) throw err;
870
+ *
871
+ * try {
872
+ * ftruncate(fd, 4, (err) => {
873
+ * closeFd(fd);
874
+ * if (err) throw err;
875
+ * });
876
+ * } catch (err) {
877
+ * closeFd(fd);
878
+ * if (err) throw err;
879
+ * }
880
+ * });
881
+ * ```
882
+ *
883
+ * If the file previously was shorter than `len` bytes, it is extended, and the
884
+ * extended part is filled with null bytes (`'\0'`):
885
+ *
886
+ * If `len` is negative then `0` will be used.
887
+ * @since v0.8.6
888
+ * @param [len=0]
889
+ */
890
+ export function ftruncate(fd: number, len: number | undefined, callback: NoParamCallback): void;
891
+ /**
892
+ * Asynchronous ftruncate(2) - Truncate a file to a specified length.
893
+ * @param fd A file descriptor.
894
+ */
895
+ export function ftruncate(fd: number, callback: NoParamCallback): void;
896
+ export namespace ftruncate {
897
+ /**
898
+ * Asynchronous ftruncate(2) - Truncate a file to a specified length.
899
+ * @param fd A file descriptor.
900
+ * @param len If not specified, defaults to `0`.
901
+ */
902
+ function __promisify__(fd: number, len?: number): Promise<void>;
903
+ }
904
+ /**
905
+ * Truncates the file descriptor. Returns `undefined`.
906
+ *
907
+ * For detailed information, see the documentation of the asynchronous version of
908
+ * this API: {@link ftruncate}.
909
+ * @since v0.8.6
910
+ * @param [len=0]
911
+ */
912
+ export function ftruncateSync(fd: number, len?: number): void;
913
+ /**
914
+ * Asynchronously changes owner and group of a file. No arguments other than a
915
+ * possible exception are given to the completion callback.
916
+ *
917
+ * See the POSIX [`chown(2)`](http://man7.org/linux/man-pages/man2/chown.2.html) documentation for more detail.
918
+ * @since v0.1.97
919
+ */
920
+ export function chown(path: PathLike, uid: number, gid: number, callback: NoParamCallback): void;
921
+ export namespace chown {
922
+ /**
923
+ * Asynchronous chown(2) - Change ownership of a file.
924
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
925
+ */
926
+ function __promisify__(path: PathLike, uid: number, gid: number): Promise<void>;
927
+ }
928
+ /**
929
+ * Synchronously changes owner and group of a file. Returns `undefined`.
930
+ * This is the synchronous version of {@link chown}.
931
+ *
932
+ * See the POSIX [`chown(2)`](http://man7.org/linux/man-pages/man2/chown.2.html) documentation for more detail.
933
+ * @since v0.1.97
934
+ */
935
+ export function chownSync(path: PathLike, uid: number, gid: number): void;
936
+ /**
937
+ * Sets the owner of the file. No arguments other than a possible exception are
938
+ * given to the completion callback.
939
+ *
940
+ * See the POSIX [`fchown(2)`](http://man7.org/linux/man-pages/man2/fchown.2.html) documentation for more detail.
941
+ * @since v0.4.7
942
+ */
943
+ export function fchown(fd: number, uid: number, gid: number, callback: NoParamCallback): void;
944
+ export namespace fchown {
945
+ /**
946
+ * Asynchronous fchown(2) - Change ownership of a file.
947
+ * @param fd A file descriptor.
948
+ */
949
+ function __promisify__(fd: number, uid: number, gid: number): Promise<void>;
950
+ }
951
+ /**
952
+ * Sets the owner of the file. Returns `undefined`.
953
+ *
954
+ * See the POSIX [`fchown(2)`](http://man7.org/linux/man-pages/man2/fchown.2.html) documentation for more detail.
955
+ * @since v0.4.7
956
+ * @param uid The file's new owner's user id.
957
+ * @param gid The file's new group's group id.
958
+ */
959
+ export function fchownSync(fd: number, uid: number, gid: number): void;
960
+ /**
961
+ * Set the owner of the symbolic link. No arguments other than a possible
962
+ * exception are given to the completion callback.
963
+ *
964
+ * See the POSIX [`lchown(2)`](http://man7.org/linux/man-pages/man2/lchown.2.html) documentation for more detail.
965
+ */
966
+ export function lchown(path: PathLike, uid: number, gid: number, callback: NoParamCallback): void;
967
+ export namespace lchown {
968
+ /**
969
+ * Asynchronous lchown(2) - Change ownership of a file. Does not dereference symbolic links.
970
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
971
+ */
972
+ function __promisify__(path: PathLike, uid: number, gid: number): Promise<void>;
973
+ }
974
+ /**
975
+ * Set the owner for the path. Returns `undefined`.
976
+ *
977
+ * See the POSIX [`lchown(2)`](http://man7.org/linux/man-pages/man2/lchown.2.html) documentation for more details.
978
+ * @param uid The file's new owner's user id.
979
+ * @param gid The file's new group's group id.
980
+ */
981
+ export function lchownSync(path: PathLike, uid: number, gid: number): void;
982
+ /**
983
+ * Changes the access and modification times of a file in the same way as {@link utimes}, with the difference that if the path refers to a symbolic
984
+ * link, then the link is not dereferenced: instead, the timestamps of the
985
+ * symbolic link itself are changed.
986
+ *
987
+ * No arguments other than a possible exception are given to the completion
988
+ * callback.
989
+ * @since v14.5.0, v12.19.0
990
+ */
991
+ export function lutimes(path: PathLike, atime: TimeLike, mtime: TimeLike, callback: NoParamCallback): void;
992
+ export namespace lutimes {
993
+ /**
994
+ * Changes the access and modification times of a file in the same way as `fsPromises.utimes()`,
995
+ * with the difference that if the path refers to a symbolic link, then the link is not
996
+ * dereferenced: instead, the timestamps of the symbolic link itself are changed.
997
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
998
+ * @param atime The last access time. If a string is provided, it will be coerced to number.
999
+ * @param mtime The last modified time. If a string is provided, it will be coerced to number.
1000
+ */
1001
+ function __promisify__(path: PathLike, atime: TimeLike, mtime: TimeLike): Promise<void>;
1002
+ }
1003
+ /**
1004
+ * Change the file system timestamps of the symbolic link referenced by `path`.
1005
+ * Returns `undefined`, or throws an exception when parameters are incorrect or
1006
+ * the operation fails. This is the synchronous version of {@link lutimes}.
1007
+ * @since v14.5.0, v12.19.0
1008
+ */
1009
+ export function lutimesSync(path: PathLike, atime: TimeLike, mtime: TimeLike): void;
1010
+ /**
1011
+ * Asynchronously changes the permissions of a file. No arguments other than a
1012
+ * possible exception are given to the completion callback.
1013
+ *
1014
+ * See the POSIX [`chmod(2)`](http://man7.org/linux/man-pages/man2/chmod.2.html) documentation for more detail.
1015
+ *
1016
+ * ```js
1017
+ * import { chmod } from 'node:fs';
1018
+ *
1019
+ * chmod('my_file.txt', 0o775, (err) => {
1020
+ * if (err) throw err;
1021
+ * console.log('The permissions for file "my_file.txt" have been changed!');
1022
+ * });
1023
+ * ```
1024
+ * @since v0.1.30
1025
+ */
1026
+ export function chmod(path: PathLike, mode: Mode, callback: NoParamCallback): void;
1027
+ export namespace chmod {
1028
+ /**
1029
+ * Asynchronous chmod(2) - Change permissions of a file.
1030
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1031
+ * @param mode A file mode. If a string is passed, it is parsed as an octal integer.
1032
+ */
1033
+ function __promisify__(path: PathLike, mode: Mode): Promise<void>;
1034
+ }
1035
+ /**
1036
+ * For detailed information, see the documentation of the asynchronous version of
1037
+ * this API: {@link chmod}.
1038
+ *
1039
+ * See the POSIX [`chmod(2)`](http://man7.org/linux/man-pages/man2/chmod.2.html) documentation for more detail.
1040
+ * @since v0.6.7
1041
+ */
1042
+ export function chmodSync(path: PathLike, mode: Mode): void;
1043
+ /**
1044
+ * Sets the permissions on the file. No arguments other than a possible exception
1045
+ * are given to the completion callback.
1046
+ *
1047
+ * See the POSIX [`fchmod(2)`](http://man7.org/linux/man-pages/man2/fchmod.2.html) documentation for more detail.
1048
+ * @since v0.4.7
1049
+ */
1050
+ export function fchmod(fd: number, mode: Mode, callback: NoParamCallback): void;
1051
+ export namespace fchmod {
1052
+ /**
1053
+ * Asynchronous fchmod(2) - Change permissions of a file.
1054
+ * @param fd A file descriptor.
1055
+ * @param mode A file mode. If a string is passed, it is parsed as an octal integer.
1056
+ */
1057
+ function __promisify__(fd: number, mode: Mode): Promise<void>;
1058
+ }
1059
+ /**
1060
+ * Sets the permissions on the file. Returns `undefined`.
1061
+ *
1062
+ * See the POSIX [`fchmod(2)`](http://man7.org/linux/man-pages/man2/fchmod.2.html) documentation for more detail.
1063
+ * @since v0.4.7
1064
+ */
1065
+ export function fchmodSync(fd: number, mode: Mode): void;
1066
+ /**
1067
+ * Changes the permissions on a symbolic link. No arguments other than a possible
1068
+ * exception are given to the completion callback.
1069
+ *
1070
+ * This method is only implemented on macOS.
1071
+ *
1072
+ * See the POSIX [`lchmod(2)`](https://www.freebsd.org/cgi/man.cgi?query=lchmod&sektion=2) documentation for more detail.
1073
+ * @deprecated Since v0.4.7
1074
+ */
1075
+ export function lchmod(path: PathLike, mode: Mode, callback: NoParamCallback): void;
1076
+ /** @deprecated */
1077
+ export namespace lchmod {
1078
+ /**
1079
+ * Asynchronous lchmod(2) - Change permissions of a file. Does not dereference symbolic links.
1080
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1081
+ * @param mode A file mode. If a string is passed, it is parsed as an octal integer.
1082
+ */
1083
+ function __promisify__(path: PathLike, mode: Mode): Promise<void>;
1084
+ }
1085
+ /**
1086
+ * Changes the permissions on a symbolic link. Returns `undefined`.
1087
+ *
1088
+ * This method is only implemented on macOS.
1089
+ *
1090
+ * See the POSIX [`lchmod(2)`](https://www.freebsd.org/cgi/man.cgi?query=lchmod&sektion=2) documentation for more detail.
1091
+ * @deprecated Since v0.4.7
1092
+ */
1093
+ export function lchmodSync(path: PathLike, mode: Mode): void;
1094
+ /**
1095
+ * Asynchronous [`stat(2)`](http://man7.org/linux/man-pages/man2/stat.2.html). The callback gets two arguments `(err, stats)` where`stats` is an `fs.Stats` object.
1096
+ *
1097
+ * In case of an error, the `err.code` will be one of `Common System Errors`.
1098
+ *
1099
+ * {@link stat} follows symbolic links. Use {@link lstat} to look at the
1100
+ * links themselves.
1101
+ *
1102
+ * Using `fs.stat()` to check for the existence of a file before calling`fs.open()`, `fs.readFile()`, or `fs.writeFile()` is not recommended.
1103
+ * Instead, user code should open/read/write the file directly and handle the
1104
+ * error raised if the file is not available.
1105
+ *
1106
+ * To check if a file exists without manipulating it afterwards, {@link access} is recommended.
1107
+ *
1108
+ * For example, given the following directory structure:
1109
+ *
1110
+ * ```text
1111
+ * - txtDir
1112
+ * -- file.txt
1113
+ * - app.js
1114
+ * ```
1115
+ *
1116
+ * The next program will check for the stats of the given paths:
1117
+ *
1118
+ * ```js
1119
+ * import { stat } from 'node:fs';
1120
+ *
1121
+ * const pathsToCheck = ['./txtDir', './txtDir/file.txt'];
1122
+ *
1123
+ * for (let i = 0; i < pathsToCheck.length; i++) {
1124
+ * stat(pathsToCheck[i], (err, stats) => {
1125
+ * console.log(stats.isDirectory());
1126
+ * console.log(stats);
1127
+ * });
1128
+ * }
1129
+ * ```
1130
+ *
1131
+ * The resulting output will resemble:
1132
+ *
1133
+ * ```console
1134
+ * true
1135
+ * Stats {
1136
+ * dev: 16777220,
1137
+ * mode: 16877,
1138
+ * nlink: 3,
1139
+ * uid: 501,
1140
+ * gid: 20,
1141
+ * rdev: 0,
1142
+ * blksize: 4096,
1143
+ * ino: 14214262,
1144
+ * size: 96,
1145
+ * blocks: 0,
1146
+ * atimeMs: 1561174653071.963,
1147
+ * mtimeMs: 1561174614583.3518,
1148
+ * ctimeMs: 1561174626623.5366,
1149
+ * birthtimeMs: 1561174126937.2893,
1150
+ * atime: 2019-06-22T03:37:33.072Z,
1151
+ * mtime: 2019-06-22T03:36:54.583Z,
1152
+ * ctime: 2019-06-22T03:37:06.624Z,
1153
+ * birthtime: 2019-06-22T03:28:46.937Z
1154
+ * }
1155
+ * false
1156
+ * Stats {
1157
+ * dev: 16777220,
1158
+ * mode: 33188,
1159
+ * nlink: 1,
1160
+ * uid: 501,
1161
+ * gid: 20,
1162
+ * rdev: 0,
1163
+ * blksize: 4096,
1164
+ * ino: 14214074,
1165
+ * size: 8,
1166
+ * blocks: 8,
1167
+ * atimeMs: 1561174616618.8555,
1168
+ * mtimeMs: 1561174614584,
1169
+ * ctimeMs: 1561174614583.8145,
1170
+ * birthtimeMs: 1561174007710.7478,
1171
+ * atime: 2019-06-22T03:36:56.619Z,
1172
+ * mtime: 2019-06-22T03:36:54.584Z,
1173
+ * ctime: 2019-06-22T03:36:54.584Z,
1174
+ * birthtime: 2019-06-22T03:26:47.711Z
1175
+ * }
1176
+ * ```
1177
+ * @since v0.0.2
1178
+ */
1179
+ export function stat(path: PathLike, callback: (err: NodeJS.ErrnoException | null, stats: Stats) => void): void;
1180
+ export function stat(
1181
+ path: PathLike,
1182
+ options:
1183
+ | (StatOptions & {
1184
+ bigint?: false | undefined;
1185
+ throwIfNoEntry?: true | undefined;
1186
+ })
1187
+ | undefined,
1188
+ callback: (err: NodeJS.ErrnoException | null, stats: Stats) => void,
1189
+ ): void;
1190
+ export function stat(
1191
+ path: PathLike,
1192
+ options: StatOptions & {
1193
+ bigint: true;
1194
+ throwIfNoEntry?: true | undefined;
1195
+ },
1196
+ callback: (err: NodeJS.ErrnoException | null, stats: BigIntStats) => void,
1197
+ ): void;
1198
+ export function stat(
1199
+ path: PathLike,
1200
+ options:
1201
+ | (StatOptions & {
1202
+ bigint?: false | undefined;
1203
+ throwIfNoEntry: false;
1204
+ })
1205
+ | undefined,
1206
+ callback: (err: NodeJS.ErrnoException | null, stats: Stats | undefined) => void,
1207
+ ): void;
1208
+ export function stat(
1209
+ path: PathLike,
1210
+ options: StatOptions & {
1211
+ bigint: true;
1212
+ throwIfNoEntry: false;
1213
+ },
1214
+ callback: (err: NodeJS.ErrnoException | null, stats: BigIntStats | undefined) => void,
1215
+ ): void;
1216
+ export function stat(
1217
+ path: PathLike,
1218
+ options: StatOptions | undefined,
1219
+ callback: (err: NodeJS.ErrnoException | null, stats: Stats | BigIntStats | undefined) => void,
1220
+ ): void;
1221
+ export namespace stat {
1222
+ /**
1223
+ * Asynchronous stat(2) - Get file status.
1224
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1225
+ */
1226
+ function __promisify__(
1227
+ path: PathLike,
1228
+ options?: StatOptions & {
1229
+ bigint?: false | undefined;
1230
+ throwIfNoEntry?: true | undefined;
1231
+ },
1232
+ ): Promise<Stats>;
1233
+ function __promisify__(
1234
+ path: PathLike,
1235
+ options: StatOptions & {
1236
+ bigint: true;
1237
+ throwIfNoEntry?: true | undefined;
1238
+ },
1239
+ ): Promise<BigIntStats>;
1240
+ function __promisify__(
1241
+ path: PathLike,
1242
+ options?: StatOptions & {
1243
+ bigint?: false | undefined;
1244
+ throwIfNoEntry: false;
1245
+ },
1246
+ ): Promise<Stats | undefined>;
1247
+ function __promisify__(
1248
+ path: PathLike,
1249
+ options: StatOptions & {
1250
+ bigint: true;
1251
+ throwIfNoEntry: false;
1252
+ },
1253
+ ): Promise<BigIntStats | undefined>;
1254
+ function __promisify__(path: PathLike, options?: StatOptions): Promise<Stats | BigIntStats | undefined>;
1255
+ }
1256
+ export interface StatSyncFn extends Function {
1257
+ (path: PathLike, options?: undefined): Stats;
1258
+ (
1259
+ path: PathLike,
1260
+ options?: StatSyncOptions & {
1261
+ bigint?: false | undefined;
1262
+ throwIfNoEntry: false;
1263
+ },
1264
+ ): Stats | undefined;
1265
+ (
1266
+ path: PathLike,
1267
+ options: StatSyncOptions & {
1268
+ bigint: true;
1269
+ throwIfNoEntry: false;
1270
+ },
1271
+ ): BigIntStats | undefined;
1272
+ (
1273
+ path: PathLike,
1274
+ options?: StatSyncOptions & {
1275
+ bigint?: false | undefined;
1276
+ },
1277
+ ): Stats;
1278
+ (
1279
+ path: PathLike,
1280
+ options: StatSyncOptions & {
1281
+ bigint: true;
1282
+ },
1283
+ ): BigIntStats;
1284
+ (
1285
+ path: PathLike,
1286
+ options: StatSyncOptions & {
1287
+ bigint: boolean;
1288
+ throwIfNoEntry?: false | undefined;
1289
+ },
1290
+ ): Stats | BigIntStats;
1291
+ (path: PathLike, options?: StatSyncOptions): Stats | BigIntStats | undefined;
1292
+ }
1293
+ /**
1294
+ * Synchronous stat(2) - Get file status.
1295
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1296
+ */
1297
+ export const statSync: StatSyncFn;
1298
+ /**
1299
+ * Invokes the callback with the `fs.Stats` for the file descriptor.
1300
+ *
1301
+ * See the POSIX [`fstat(2)`](http://man7.org/linux/man-pages/man2/fstat.2.html) documentation for more detail.
1302
+ * @since v0.1.95
1303
+ */
1304
+ export function fstat(fd: number, callback: (err: NodeJS.ErrnoException | null, stats: Stats) => void): void;
1305
+ export function fstat(
1306
+ fd: number,
1307
+ options:
1308
+ | (StatOptions & {
1309
+ bigint?: false | undefined;
1310
+ })
1311
+ | undefined,
1312
+ callback: (err: NodeJS.ErrnoException | null, stats: Stats) => void,
1313
+ ): void;
1314
+ export function fstat(
1315
+ fd: number,
1316
+ options: StatOptions & {
1317
+ bigint: true;
1318
+ },
1319
+ callback: (err: NodeJS.ErrnoException | null, stats: BigIntStats) => void,
1320
+ ): void;
1321
+ export function fstat(
1322
+ fd: number,
1323
+ options: StatOptions | undefined,
1324
+ callback: (err: NodeJS.ErrnoException | null, stats: Stats | BigIntStats) => void,
1325
+ ): void;
1326
+ export namespace fstat {
1327
+ /**
1328
+ * Asynchronous fstat(2) - Get file status.
1329
+ * @param fd A file descriptor.
1330
+ */
1331
+ function __promisify__(
1332
+ fd: number,
1333
+ options?: StatOptions & {
1334
+ bigint?: false | undefined;
1335
+ },
1336
+ ): Promise<Stats>;
1337
+ function __promisify__(
1338
+ fd: number,
1339
+ options: StatOptions & {
1340
+ bigint: true;
1341
+ },
1342
+ ): Promise<BigIntStats>;
1343
+ function __promisify__(fd: number, options?: StatOptions): Promise<Stats | BigIntStats>;
1344
+ }
1345
+ /**
1346
+ * Retrieves the `fs.Stats` for the file descriptor.
1347
+ *
1348
+ * See the POSIX [`fstat(2)`](http://man7.org/linux/man-pages/man2/fstat.2.html) documentation for more detail.
1349
+ * @since v0.1.95
1350
+ */
1351
+ export function fstatSync(
1352
+ fd: number,
1353
+ options?: StatOptions & {
1354
+ bigint?: false | undefined;
1355
+ },
1356
+ ): Stats;
1357
+ export function fstatSync(
1358
+ fd: number,
1359
+ options: StatOptions & {
1360
+ bigint: true;
1361
+ },
1362
+ ): BigIntStats;
1363
+ export function fstatSync(fd: number, options?: StatOptions): Stats | BigIntStats;
1364
+ /**
1365
+ * Retrieves the `fs.Stats` for the symbolic link referred to by the path.
1366
+ * The callback gets two arguments `(err, stats)` where `stats` is a `fs.Stats` object. `lstat()` is identical to `stat()`, except that if `path` is a symbolic
1367
+ * link, then the link itself is stat-ed, not the file that it refers to.
1368
+ *
1369
+ * See the POSIX [`lstat(2)`](http://man7.org/linux/man-pages/man2/lstat.2.html) documentation for more details.
1370
+ * @since v0.1.30
1371
+ */
1372
+ export function lstat(path: PathLike, callback: (err: NodeJS.ErrnoException | null, stats: Stats) => void): void;
1373
+ export function lstat(
1374
+ path: PathLike,
1375
+ options:
1376
+ | (StatOptions & {
1377
+ bigint?: false | undefined;
1378
+ })
1379
+ | undefined,
1380
+ callback: (err: NodeJS.ErrnoException | null, stats: Stats) => void,
1381
+ ): void;
1382
+ export function lstat(
1383
+ path: PathLike,
1384
+ options: StatOptions & {
1385
+ bigint: true;
1386
+ },
1387
+ callback: (err: NodeJS.ErrnoException | null, stats: BigIntStats) => void,
1388
+ ): void;
1389
+ export function lstat(
1390
+ path: PathLike,
1391
+ options: StatOptions | undefined,
1392
+ callback: (err: NodeJS.ErrnoException | null, stats: Stats | BigIntStats) => void,
1393
+ ): void;
1394
+ export namespace lstat {
1395
+ /**
1396
+ * Asynchronous lstat(2) - Get file status. Does not dereference symbolic links.
1397
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1398
+ */
1399
+ function __promisify__(
1400
+ path: PathLike,
1401
+ options?: StatOptions & {
1402
+ bigint?: false | undefined;
1403
+ },
1404
+ ): Promise<Stats>;
1405
+ function __promisify__(
1406
+ path: PathLike,
1407
+ options: StatOptions & {
1408
+ bigint: true;
1409
+ },
1410
+ ): Promise<BigIntStats>;
1411
+ function __promisify__(path: PathLike, options?: StatOptions): Promise<Stats | BigIntStats>;
1412
+ }
1413
+ /**
1414
+ * Asynchronous [`statfs(2)`](http://man7.org/linux/man-pages/man2/statfs.2.html). Returns information about the mounted file system which
1415
+ * contains `path`. The callback gets two arguments `(err, stats)` where `stats`is an `fs.StatFs` object.
1416
+ *
1417
+ * In case of an error, the `err.code` will be one of `Common System Errors`.
1418
+ * @since v19.6.0, v18.15.0
1419
+ * @param path A path to an existing file or directory on the file system to be queried.
1420
+ */
1421
+ export function statfs(path: PathLike, callback: (err: NodeJS.ErrnoException | null, stats: StatsFs) => void): void;
1422
+ export function statfs(
1423
+ path: PathLike,
1424
+ options:
1425
+ | (StatFsOptions & {
1426
+ bigint?: false | undefined;
1427
+ })
1428
+ | undefined,
1429
+ callback: (err: NodeJS.ErrnoException | null, stats: StatsFs) => void,
1430
+ ): void;
1431
+ export function statfs(
1432
+ path: PathLike,
1433
+ options: StatFsOptions & {
1434
+ bigint: true;
1435
+ },
1436
+ callback: (err: NodeJS.ErrnoException | null, stats: BigIntStatsFs) => void,
1437
+ ): void;
1438
+ export function statfs(
1439
+ path: PathLike,
1440
+ options: StatFsOptions | undefined,
1441
+ callback: (err: NodeJS.ErrnoException | null, stats: StatsFs | BigIntStatsFs) => void,
1442
+ ): void;
1443
+ export namespace statfs {
1444
+ /**
1445
+ * Asynchronous statfs(2) - Returns information about the mounted file system which contains path. The callback gets two arguments (err, stats) where stats is an <fs.StatFs> object.
1446
+ * @param path A path to an existing file or directory on the file system to be queried.
1447
+ */
1448
+ function __promisify__(
1449
+ path: PathLike,
1450
+ options?: StatFsOptions & {
1451
+ bigint?: false | undefined;
1452
+ },
1453
+ ): Promise<StatsFs>;
1454
+ function __promisify__(
1455
+ path: PathLike,
1456
+ options: StatFsOptions & {
1457
+ bigint: true;
1458
+ },
1459
+ ): Promise<BigIntStatsFs>;
1460
+ function __promisify__(path: PathLike, options?: StatFsOptions): Promise<StatsFs | BigIntStatsFs>;
1461
+ }
1462
+ /**
1463
+ * Synchronous [`statfs(2)`](http://man7.org/linux/man-pages/man2/statfs.2.html). Returns information about the mounted file system which
1464
+ * contains `path`.
1465
+ *
1466
+ * In case of an error, the `err.code` will be one of `Common System Errors`.
1467
+ * @since v19.6.0, v18.15.0
1468
+ * @param path A path to an existing file or directory on the file system to be queried.
1469
+ */
1470
+ export function statfsSync(
1471
+ path: PathLike,
1472
+ options?: StatFsOptions & {
1473
+ bigint?: false | undefined;
1474
+ },
1475
+ ): StatsFs;
1476
+ export function statfsSync(
1477
+ path: PathLike,
1478
+ options: StatFsOptions & {
1479
+ bigint: true;
1480
+ },
1481
+ ): BigIntStatsFs;
1482
+ export function statfsSync(path: PathLike, options?: StatFsOptions): StatsFs | BigIntStatsFs;
1483
+ /**
1484
+ * Synchronous lstat(2) - Get file status. Does not dereference symbolic links.
1485
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1486
+ */
1487
+ export const lstatSync: StatSyncFn;
1488
+ /**
1489
+ * Creates a new link from the `existingPath` to the `newPath`. See the POSIX [`link(2)`](http://man7.org/linux/man-pages/man2/link.2.html) documentation for more detail. No arguments other than
1490
+ * a possible
1491
+ * exception are given to the completion callback.
1492
+ * @since v0.1.31
1493
+ */
1494
+ export function link(existingPath: PathLike, newPath: PathLike, callback: NoParamCallback): void;
1495
+ export namespace link {
1496
+ /**
1497
+ * Asynchronous link(2) - Create a new link (also known as a hard link) to an existing file.
1498
+ * @param existingPath A path to a file. If a URL is provided, it must use the `file:` protocol.
1499
+ * @param newPath A path to a file. If a URL is provided, it must use the `file:` protocol.
1500
+ */
1501
+ function __promisify__(existingPath: PathLike, newPath: PathLike): Promise<void>;
1502
+ }
1503
+ /**
1504
+ * Creates a new link from the `existingPath` to the `newPath`. See the POSIX [`link(2)`](http://man7.org/linux/man-pages/man2/link.2.html) documentation for more detail. Returns `undefined`.
1505
+ * @since v0.1.31
1506
+ */
1507
+ export function linkSync(existingPath: PathLike, newPath: PathLike): void;
1508
+ /**
1509
+ * Creates the link called `path` pointing to `target`. No arguments other than a
1510
+ * possible exception are given to the completion callback.
1511
+ *
1512
+ * See the POSIX [`symlink(2)`](http://man7.org/linux/man-pages/man2/symlink.2.html) documentation for more details.
1513
+ *
1514
+ * The `type` argument is only available on Windows and ignored on other platforms.
1515
+ * It can be set to `'dir'`, `'file'`, or `'junction'`. If the `type` argument is
1516
+ * not a string, Node.js will autodetect `target` type and use `'file'` or `'dir'`.
1517
+ * If the `target` does not exist, `'file'` will be used. Windows junction points
1518
+ * require the destination path to be absolute. When using `'junction'`, the`target` argument will automatically be normalized to absolute path. Junction
1519
+ * points on NTFS volumes can only point to directories.
1520
+ *
1521
+ * Relative targets are relative to the link's parent directory.
1522
+ *
1523
+ * ```js
1524
+ * import { symlink } from 'node:fs';
1525
+ *
1526
+ * symlink('./mew', './mewtwo', callback);
1527
+ * ```
1528
+ *
1529
+ * The above example creates a symbolic link `mewtwo` which points to `mew` in the
1530
+ * same directory:
1531
+ *
1532
+ * ```bash
1533
+ * $ tree .
1534
+ * .
1535
+ * ├── mew
1536
+ * └── mewtwo -> ./mew
1537
+ * ```
1538
+ * @since v0.1.31
1539
+ * @param [type='null']
1540
+ */
1541
+ export function symlink(
1542
+ target: PathLike,
1543
+ path: PathLike,
1544
+ type: symlink.Type | undefined | null,
1545
+ callback: NoParamCallback,
1546
+ ): void;
1547
+ /**
1548
+ * Asynchronous symlink(2) - Create a new symbolic link to an existing file.
1549
+ * @param target A path to an existing file. If a URL is provided, it must use the `file:` protocol.
1550
+ * @param path A path to the new symlink. If a URL is provided, it must use the `file:` protocol.
1551
+ */
1552
+ export function symlink(target: PathLike, path: PathLike, callback: NoParamCallback): void;
1553
+ export namespace symlink {
1554
+ /**
1555
+ * Asynchronous symlink(2) - Create a new symbolic link to an existing file.
1556
+ * @param target A path to an existing file. If a URL is provided, it must use the `file:` protocol.
1557
+ * @param path A path to the new symlink. If a URL is provided, it must use the `file:` protocol.
1558
+ * @param type May be set to `'dir'`, `'file'`, or `'junction'` (default is `'file'`) and is only available on Windows (ignored on other platforms).
1559
+ * When using `'junction'`, the `target` argument will automatically be normalized to an absolute path.
1560
+ */
1561
+ function __promisify__(target: PathLike, path: PathLike, type?: string | null): Promise<void>;
1562
+ type Type = "dir" | "file" | "junction";
1563
+ }
1564
+ /**
1565
+ * Returns `undefined`.
1566
+ *
1567
+ * For detailed information, see the documentation of the asynchronous version of
1568
+ * this API: {@link symlink}.
1569
+ * @since v0.1.31
1570
+ * @param [type='null']
1571
+ */
1572
+ export function symlinkSync(target: PathLike, path: PathLike, type?: symlink.Type | null): void;
1573
+ /**
1574
+ * Reads the contents of the symbolic link referred to by `path`. The callback gets
1575
+ * two arguments `(err, linkString)`.
1576
+ *
1577
+ * See the POSIX [`readlink(2)`](http://man7.org/linux/man-pages/man2/readlink.2.html) documentation for more details.
1578
+ *
1579
+ * The optional `options` argument can be a string specifying an encoding, or an
1580
+ * object with an `encoding` property specifying the character encoding to use for
1581
+ * the link path passed to the callback. If the `encoding` is set to `'buffer'`,
1582
+ * the link path returned will be passed as a `Buffer` object.
1583
+ * @since v0.1.31
1584
+ */
1585
+ export function readlink(
1586
+ path: PathLike,
1587
+ options: EncodingOption,
1588
+ callback: (err: NodeJS.ErrnoException | null, linkString: string) => void,
1589
+ ): void;
1590
+ /**
1591
+ * Asynchronous readlink(2) - read value of a symbolic link.
1592
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1593
+ * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
1594
+ */
1595
+ export function readlink(
1596
+ path: PathLike,
1597
+ options: BufferEncodingOption,
1598
+ callback: (err: NodeJS.ErrnoException | null, linkString: NonSharedBuffer) => void,
1599
+ ): void;
1600
+ /**
1601
+ * Asynchronous readlink(2) - read value of a symbolic link.
1602
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1603
+ * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
1604
+ */
1605
+ export function readlink(
1606
+ path: PathLike,
1607
+ options: EncodingOption,
1608
+ callback: (err: NodeJS.ErrnoException | null, linkString: string | NonSharedBuffer) => void,
1609
+ ): void;
1610
+ /**
1611
+ * Asynchronous readlink(2) - read value of a symbolic link.
1612
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1613
+ */
1614
+ export function readlink(
1615
+ path: PathLike,
1616
+ callback: (err: NodeJS.ErrnoException | null, linkString: string) => void,
1617
+ ): void;
1618
+ export namespace readlink {
1619
+ /**
1620
+ * Asynchronous readlink(2) - read value of a symbolic link.
1621
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1622
+ * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
1623
+ */
1624
+ function __promisify__(path: PathLike, options?: EncodingOption): Promise<string>;
1625
+ /**
1626
+ * Asynchronous readlink(2) - read value of a symbolic link.
1627
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1628
+ * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
1629
+ */
1630
+ function __promisify__(path: PathLike, options: BufferEncodingOption): Promise<NonSharedBuffer>;
1631
+ /**
1632
+ * Asynchronous readlink(2) - read value of a symbolic link.
1633
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1634
+ * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
1635
+ */
1636
+ function __promisify__(path: PathLike, options?: EncodingOption): Promise<string | NonSharedBuffer>;
1637
+ }
1638
+ /**
1639
+ * Returns the symbolic link's string value.
1640
+ *
1641
+ * See the POSIX [`readlink(2)`](http://man7.org/linux/man-pages/man2/readlink.2.html) documentation for more details.
1642
+ *
1643
+ * The optional `options` argument can be a string specifying an encoding, or an
1644
+ * object with an `encoding` property specifying the character encoding to use for
1645
+ * the link path returned. If the `encoding` is set to `'buffer'`,
1646
+ * the link path returned will be passed as a `Buffer` object.
1647
+ * @since v0.1.31
1648
+ */
1649
+ export function readlinkSync(path: PathLike, options?: EncodingOption): string;
1650
+ /**
1651
+ * Synchronous readlink(2) - read value of a symbolic link.
1652
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1653
+ * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
1654
+ */
1655
+ export function readlinkSync(path: PathLike, options: BufferEncodingOption): NonSharedBuffer;
1656
+ /**
1657
+ * Synchronous readlink(2) - read value of a symbolic link.
1658
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1659
+ * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
1660
+ */
1661
+ export function readlinkSync(path: PathLike, options?: EncodingOption): string | NonSharedBuffer;
1662
+ /**
1663
+ * Asynchronously computes the canonical pathname by resolving `.`, `..`, and
1664
+ * symbolic links.
1665
+ *
1666
+ * A canonical pathname is not necessarily unique. Hard links and bind mounts can
1667
+ * expose a file system entity through many pathnames.
1668
+ *
1669
+ * This function behaves like [`realpath(3)`](http://man7.org/linux/man-pages/man3/realpath.3.html), with some exceptions:
1670
+ *
1671
+ * 1. No case conversion is performed on case-insensitive file systems.
1672
+ * 2. The maximum number of symbolic links is platform-independent and generally
1673
+ * (much) higher than what the native [`realpath(3)`](http://man7.org/linux/man-pages/man3/realpath.3.html) implementation supports.
1674
+ *
1675
+ * The `callback` gets two arguments `(err, resolvedPath)`. May use `process.cwd` to resolve relative paths.
1676
+ *
1677
+ * Only paths that can be converted to UTF8 strings are supported.
1678
+ *
1679
+ * The optional `options` argument can be a string specifying an encoding, or an
1680
+ * object with an `encoding` property specifying the character encoding to use for
1681
+ * the path passed to the callback. If the `encoding` is set to `'buffer'`,
1682
+ * the path returned will be passed as a `Buffer` object.
1683
+ *
1684
+ * If `path` resolves to a socket or a pipe, the function will return a system
1685
+ * dependent name for that object.
1686
+ * @since v0.1.31
1687
+ */
1688
+ export function realpath(
1689
+ path: PathLike,
1690
+ options: EncodingOption,
1691
+ callback: (err: NodeJS.ErrnoException | null, resolvedPath: string) => void,
1692
+ ): void;
1693
+ /**
1694
+ * Asynchronous realpath(3) - return the canonicalized absolute pathname.
1695
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1696
+ * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
1697
+ */
1698
+ export function realpath(
1699
+ path: PathLike,
1700
+ options: BufferEncodingOption,
1701
+ callback: (err: NodeJS.ErrnoException | null, resolvedPath: NonSharedBuffer) => void,
1702
+ ): void;
1703
+ /**
1704
+ * Asynchronous realpath(3) - return the canonicalized absolute pathname.
1705
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1706
+ * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
1707
+ */
1708
+ export function realpath(
1709
+ path: PathLike,
1710
+ options: EncodingOption,
1711
+ callback: (err: NodeJS.ErrnoException | null, resolvedPath: string | NonSharedBuffer) => void,
1712
+ ): void;
1713
+ /**
1714
+ * Asynchronous realpath(3) - return the canonicalized absolute pathname.
1715
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1716
+ */
1717
+ export function realpath(
1718
+ path: PathLike,
1719
+ callback: (err: NodeJS.ErrnoException | null, resolvedPath: string) => void,
1720
+ ): void;
1721
+ export namespace realpath {
1722
+ /**
1723
+ * Asynchronous realpath(3) - return the canonicalized absolute pathname.
1724
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1725
+ * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
1726
+ */
1727
+ function __promisify__(path: PathLike, options?: EncodingOption): Promise<string>;
1728
+ /**
1729
+ * Asynchronous realpath(3) - return the canonicalized absolute pathname.
1730
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1731
+ * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
1732
+ */
1733
+ function __promisify__(path: PathLike, options: BufferEncodingOption): Promise<NonSharedBuffer>;
1734
+ /**
1735
+ * Asynchronous realpath(3) - return the canonicalized absolute pathname.
1736
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1737
+ * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
1738
+ */
1739
+ function __promisify__(path: PathLike, options?: EncodingOption): Promise<string | NonSharedBuffer>;
1740
+ /**
1741
+ * Asynchronous [`realpath(3)`](http://man7.org/linux/man-pages/man3/realpath.3.html).
1742
+ *
1743
+ * The `callback` gets two arguments `(err, resolvedPath)`.
1744
+ *
1745
+ * Only paths that can be converted to UTF8 strings are supported.
1746
+ *
1747
+ * The optional `options` argument can be a string specifying an encoding, or an
1748
+ * object with an `encoding` property specifying the character encoding to use for
1749
+ * the path passed to the callback. If the `encoding` is set to `'buffer'`,
1750
+ * the path returned will be passed as a `Buffer` object.
1751
+ *
1752
+ * On Linux, when Node.js is linked against musl libc, the procfs file system must
1753
+ * be mounted on `/proc` in order for this function to work. Glibc does not have
1754
+ * this restriction.
1755
+ * @since v9.2.0
1756
+ */
1757
+ function native(
1758
+ path: PathLike,
1759
+ options: EncodingOption,
1760
+ callback: (err: NodeJS.ErrnoException | null, resolvedPath: string) => void,
1761
+ ): void;
1762
+ function native(
1763
+ path: PathLike,
1764
+ options: BufferEncodingOption,
1765
+ callback: (err: NodeJS.ErrnoException | null, resolvedPath: NonSharedBuffer) => void,
1766
+ ): void;
1767
+ function native(
1768
+ path: PathLike,
1769
+ options: EncodingOption,
1770
+ callback: (err: NodeJS.ErrnoException | null, resolvedPath: string | NonSharedBuffer) => void,
1771
+ ): void;
1772
+ function native(
1773
+ path: PathLike,
1774
+ callback: (err: NodeJS.ErrnoException | null, resolvedPath: string) => void,
1775
+ ): void;
1776
+ }
1777
+ /**
1778
+ * Returns the resolved pathname.
1779
+ *
1780
+ * For detailed information, see the documentation of the asynchronous version of
1781
+ * this API: {@link realpath}.
1782
+ * @since v0.1.31
1783
+ */
1784
+ export function realpathSync(path: PathLike, options?: EncodingOption): string;
1785
+ /**
1786
+ * Synchronous realpath(3) - return the canonicalized absolute pathname.
1787
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1788
+ * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
1789
+ */
1790
+ export function realpathSync(path: PathLike, options: BufferEncodingOption): NonSharedBuffer;
1791
+ /**
1792
+ * Synchronous realpath(3) - return the canonicalized absolute pathname.
1793
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1794
+ * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
1795
+ */
1796
+ export function realpathSync(path: PathLike, options?: EncodingOption): string | NonSharedBuffer;
1797
+ export namespace realpathSync {
1798
+ function native(path: PathLike, options?: EncodingOption): string;
1799
+ function native(path: PathLike, options: BufferEncodingOption): NonSharedBuffer;
1800
+ function native(path: PathLike, options?: EncodingOption): string | NonSharedBuffer;
1801
+ }
1802
+ /**
1803
+ * Asynchronously removes a file or symbolic link. No arguments other than a
1804
+ * possible exception are given to the completion callback.
1805
+ *
1806
+ * ```js
1807
+ * import { unlink } from 'node:fs';
1808
+ * // Assuming that 'path/file.txt' is a regular file.
1809
+ * unlink('path/file.txt', (err) => {
1810
+ * if (err) throw err;
1811
+ * console.log('path/file.txt was deleted');
1812
+ * });
1813
+ * ```
1814
+ *
1815
+ * `fs.unlink()` will not work on a directory, empty or otherwise. To remove a
1816
+ * directory, use {@link rmdir}.
1817
+ *
1818
+ * See the POSIX [`unlink(2)`](http://man7.org/linux/man-pages/man2/unlink.2.html) documentation for more details.
1819
+ * @since v0.0.2
1820
+ */
1821
+ export function unlink(path: PathLike, callback: NoParamCallback): void;
1822
+ export namespace unlink {
1823
+ /**
1824
+ * Asynchronous unlink(2) - delete a name and possibly the file it refers to.
1825
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1826
+ */
1827
+ function __promisify__(path: PathLike): Promise<void>;
1828
+ }
1829
+ /**
1830
+ * Synchronous [`unlink(2)`](http://man7.org/linux/man-pages/man2/unlink.2.html). Returns `undefined`.
1831
+ * @since v0.1.21
1832
+ */
1833
+ export function unlinkSync(path: PathLike): void;
1834
+ export interface RmDirOptions {
1835
+ /**
1836
+ * If an `EBUSY`, `EMFILE`, `ENFILE`, `ENOTEMPTY`, or
1837
+ * `EPERM` error is encountered, Node.js will retry the operation with a linear
1838
+ * backoff wait of `retryDelay` ms longer on each try. This option represents the
1839
+ * number of retries. This option is ignored if the `recursive` option is not
1840
+ * `true`.
1841
+ * @default 0
1842
+ */
1843
+ maxRetries?: number | undefined;
1844
+ /**
1845
+ * @deprecated since v14.14.0 In future versions of Node.js and will trigger a warning
1846
+ * `fs.rmdir(path, { recursive: true })` will throw if `path` does not exist or is a file.
1847
+ * Use `fs.rm(path, { recursive: true, force: true })` instead.
1848
+ *
1849
+ * If `true`, perform a recursive directory removal. In
1850
+ * recursive mode, operations are retried on failure.
1851
+ * @default false
1852
+ */
1853
+ recursive?: boolean | undefined;
1854
+ /**
1855
+ * The amount of time in milliseconds to wait between retries.
1856
+ * This option is ignored if the `recursive` option is not `true`.
1857
+ * @default 100
1858
+ */
1859
+ retryDelay?: number | undefined;
1860
+ }
1861
+ /**
1862
+ * Asynchronous [`rmdir(2)`](http://man7.org/linux/man-pages/man2/rmdir.2.html). No arguments other than a possible exception are given
1863
+ * to the completion callback.
1864
+ *
1865
+ * Using `fs.rmdir()` on a file (not a directory) results in an `ENOENT` error on
1866
+ * Windows and an `ENOTDIR` error on POSIX.
1867
+ *
1868
+ * To get a behavior similar to the `rm -rf` Unix command, use {@link rm} with options `{ recursive: true, force: true }`.
1869
+ * @since v0.0.2
1870
+ */
1871
+ export function rmdir(path: PathLike, callback: NoParamCallback): void;
1872
+ export function rmdir(path: PathLike, options: RmDirOptions, callback: NoParamCallback): void;
1873
+ export namespace rmdir {
1874
+ /**
1875
+ * Asynchronous rmdir(2) - delete a directory.
1876
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1877
+ */
1878
+ function __promisify__(path: PathLike, options?: RmDirOptions): Promise<void>;
1879
+ }
1880
+ /**
1881
+ * Synchronous [`rmdir(2)`](http://man7.org/linux/man-pages/man2/rmdir.2.html). Returns `undefined`.
1882
+ *
1883
+ * Using `fs.rmdirSync()` on a file (not a directory) results in an `ENOENT` error
1884
+ * on Windows and an `ENOTDIR` error on POSIX.
1885
+ *
1886
+ * To get a behavior similar to the `rm -rf` Unix command, use {@link rmSync} with options `{ recursive: true, force: true }`.
1887
+ * @since v0.1.21
1888
+ */
1889
+ export function rmdirSync(path: PathLike, options?: RmDirOptions): void;
1890
+ export interface RmOptions {
1891
+ /**
1892
+ * When `true`, exceptions will be ignored if `path` does not exist.
1893
+ * @default false
1894
+ */
1895
+ force?: boolean | undefined;
1896
+ /**
1897
+ * If an `EBUSY`, `EMFILE`, `ENFILE`, `ENOTEMPTY`, or
1898
+ * `EPERM` error is encountered, Node.js will retry the operation with a linear
1899
+ * backoff wait of `retryDelay` ms longer on each try. This option represents the
1900
+ * number of retries. This option is ignored if the `recursive` option is not
1901
+ * `true`.
1902
+ * @default 0
1903
+ */
1904
+ maxRetries?: number | undefined;
1905
+ /**
1906
+ * If `true`, perform a recursive directory removal. In
1907
+ * recursive mode, operations are retried on failure.
1908
+ * @default false
1909
+ */
1910
+ recursive?: boolean | undefined;
1911
+ /**
1912
+ * The amount of time in milliseconds to wait between retries.
1913
+ * This option is ignored if the `recursive` option is not `true`.
1914
+ * @default 100
1915
+ */
1916
+ retryDelay?: number | undefined;
1917
+ }
1918
+ /**
1919
+ * Asynchronously removes files and directories (modeled on the standard POSIX `rm` utility). No arguments other than a possible exception are given to the
1920
+ * completion callback.
1921
+ * @since v14.14.0
1922
+ */
1923
+ export function rm(path: PathLike, callback: NoParamCallback): void;
1924
+ export function rm(path: PathLike, options: RmOptions, callback: NoParamCallback): void;
1925
+ export namespace rm {
1926
+ /**
1927
+ * Asynchronously removes files and directories (modeled on the standard POSIX `rm` utility).
1928
+ */
1929
+ function __promisify__(path: PathLike, options?: RmOptions): Promise<void>;
1930
+ }
1931
+ /**
1932
+ * Synchronously removes files and directories (modeled on the standard POSIX `rm` utility). Returns `undefined`.
1933
+ * @since v14.14.0
1934
+ */
1935
+ export function rmSync(path: PathLike, options?: RmOptions): void;
1936
+ export interface MakeDirectoryOptions {
1937
+ /**
1938
+ * Indicates whether parent folders should be created.
1939
+ * If a folder was created, the path to the first created folder will be returned.
1940
+ * @default false
1941
+ */
1942
+ recursive?: boolean | undefined;
1943
+ /**
1944
+ * A file mode. If a string is passed, it is parsed as an octal integer. If not specified
1945
+ * @default 0o777
1946
+ */
1947
+ mode?: Mode | undefined;
1948
+ }
1949
+ /**
1950
+ * Asynchronously creates a directory.
1951
+ *
1952
+ * The callback is given a possible exception and, if `recursive` is `true`, the
1953
+ * first directory path created, `(err[, path])`.`path` can still be `undefined` when `recursive` is `true`, if no directory was
1954
+ * created (for instance, if it was previously created).
1955
+ *
1956
+ * The optional `options` argument can be an integer specifying `mode` (permission
1957
+ * 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
1958
+ * exists results in an error only
1959
+ * when `recursive` is false. If `recursive` is false and the directory exists,
1960
+ * an `EEXIST` error occurs.
1961
+ *
1962
+ * ```js
1963
+ * import { mkdir } from 'node:fs';
1964
+ *
1965
+ * // Create ./tmp/a/apple, regardless of whether ./tmp and ./tmp/a exist.
1966
+ * mkdir('./tmp/a/apple', { recursive: true }, (err) => {
1967
+ * if (err) throw err;
1968
+ * });
1969
+ * ```
1970
+ *
1971
+ * On Windows, using `fs.mkdir()` on the root directory even with recursion will
1972
+ * result in an error:
1973
+ *
1974
+ * ```js
1975
+ * import { mkdir } from 'node:fs';
1976
+ *
1977
+ * mkdir('/', { recursive: true }, (err) => {
1978
+ * // => [Error: EPERM: operation not permitted, mkdir 'C:\']
1979
+ * });
1980
+ * ```
1981
+ *
1982
+ * See the POSIX [`mkdir(2)`](http://man7.org/linux/man-pages/man2/mkdir.2.html) documentation for more details.
1983
+ * @since v0.1.8
1984
+ */
1985
+ export function mkdir(
1986
+ path: PathLike,
1987
+ options: MakeDirectoryOptions & {
1988
+ recursive: true;
1989
+ },
1990
+ callback: (err: NodeJS.ErrnoException | null, path?: string) => void,
1991
+ ): void;
1992
+ /**
1993
+ * Asynchronous mkdir(2) - create a directory.
1994
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1995
+ * @param options Either the file mode, or an object optionally specifying the file mode and whether parent folders
1996
+ * should be created. If a string is passed, it is parsed as an octal integer. If not specified, defaults to `0o777`.
1997
+ */
1998
+ export function mkdir(
1999
+ path: PathLike,
2000
+ options:
2001
+ | Mode
2002
+ | (MakeDirectoryOptions & {
2003
+ recursive?: false | undefined;
2004
+ })
2005
+ | null
2006
+ | undefined,
2007
+ callback: NoParamCallback,
2008
+ ): void;
2009
+ /**
2010
+ * Asynchronous mkdir(2) - create a directory.
2011
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
2012
+ * @param options Either the file mode, or an object optionally specifying the file mode and whether parent folders
2013
+ * should be created. If a string is passed, it is parsed as an octal integer. If not specified, defaults to `0o777`.
2014
+ */
2015
+ export function mkdir(
2016
+ path: PathLike,
2017
+ options: Mode | MakeDirectoryOptions | null | undefined,
2018
+ callback: (err: NodeJS.ErrnoException | null, path?: string) => void,
2019
+ ): void;
2020
+ /**
2021
+ * Asynchronous mkdir(2) - create a directory with a mode of `0o777`.
2022
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
2023
+ */
2024
+ export function mkdir(path: PathLike, callback: NoParamCallback): void;
2025
+ export namespace mkdir {
2026
+ /**
2027
+ * Asynchronous mkdir(2) - create a directory.
2028
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
2029
+ * @param options Either the file mode, or an object optionally specifying the file mode and whether parent folders
2030
+ * should be created. If a string is passed, it is parsed as an octal integer. If not specified, defaults to `0o777`.
2031
+ */
2032
+ function __promisify__(
2033
+ path: PathLike,
2034
+ options: MakeDirectoryOptions & {
2035
+ recursive: true;
2036
+ },
2037
+ ): Promise<string | undefined>;
2038
+ /**
2039
+ * Asynchronous mkdir(2) - create a directory.
2040
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
2041
+ * @param options Either the file mode, or an object optionally specifying the file mode and whether parent folders
2042
+ * should be created. If a string is passed, it is parsed as an octal integer. If not specified, defaults to `0o777`.
2043
+ */
2044
+ function __promisify__(
2045
+ path: PathLike,
2046
+ options?:
2047
+ | Mode
2048
+ | (MakeDirectoryOptions & {
2049
+ recursive?: false | undefined;
2050
+ })
2051
+ | null,
2052
+ ): Promise<void>;
2053
+ /**
2054
+ * Asynchronous mkdir(2) - create a directory.
2055
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
2056
+ * @param options Either the file mode, or an object optionally specifying the file mode and whether parent folders
2057
+ * should be created. If a string is passed, it is parsed as an octal integer. If not specified, defaults to `0o777`.
2058
+ */
2059
+ function __promisify__(
2060
+ path: PathLike,
2061
+ options?: Mode | MakeDirectoryOptions | null,
2062
+ ): Promise<string | undefined>;
2063
+ }
2064
+ /**
2065
+ * Synchronously creates a directory. Returns `undefined`, or if `recursive` is `true`, the first directory path created.
2066
+ * This is the synchronous version of {@link mkdir}.
2067
+ *
2068
+ * See the POSIX [`mkdir(2)`](http://man7.org/linux/man-pages/man2/mkdir.2.html) documentation for more details.
2069
+ * @since v0.1.21
2070
+ */
2071
+ export function mkdirSync(
2072
+ path: PathLike,
2073
+ options: MakeDirectoryOptions & {
2074
+ recursive: true;
2075
+ },
2076
+ ): string | undefined;
2077
+ /**
2078
+ * Synchronous mkdir(2) - create a directory.
2079
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
2080
+ * @param options Either the file mode, or an object optionally specifying the file mode and whether parent folders
2081
+ * should be created. If a string is passed, it is parsed as an octal integer. If not specified, defaults to `0o777`.
2082
+ */
2083
+ export function mkdirSync(
2084
+ path: PathLike,
2085
+ options?:
2086
+ | Mode
2087
+ | (MakeDirectoryOptions & {
2088
+ recursive?: false | undefined;
2089
+ })
2090
+ | null,
2091
+ ): void;
2092
+ /**
2093
+ * Synchronous mkdir(2) - create a directory.
2094
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
2095
+ * @param options Either the file mode, or an object optionally specifying the file mode and whether parent folders
2096
+ * should be created. If a string is passed, it is parsed as an octal integer. If not specified, defaults to `0o777`.
2097
+ */
2098
+ export function mkdirSync(path: PathLike, options?: Mode | MakeDirectoryOptions | null): string | undefined;
2099
+ /**
2100
+ * Creates a unique temporary directory.
2101
+ *
2102
+ * Generates six random characters to be appended behind a required `prefix` to create a unique temporary directory. Due to platform
2103
+ * inconsistencies, avoid trailing `X` characters in `prefix`. Some platforms,
2104
+ * notably the BSDs, can return more than six random characters, and replace
2105
+ * trailing `X` characters in `prefix` with random characters.
2106
+ *
2107
+ * The created directory path is passed as a string to the callback's second
2108
+ * parameter.
2109
+ *
2110
+ * The optional `options` argument can be a string specifying an encoding, or an
2111
+ * object with an `encoding` property specifying the character encoding to use.
2112
+ *
2113
+ * ```js
2114
+ * import { mkdtemp } from 'node:fs';
2115
+ * import { join } from 'node:path';
2116
+ * import { tmpdir } from 'node:os';
2117
+ *
2118
+ * mkdtemp(join(tmpdir(), 'foo-'), (err, directory) => {
2119
+ * if (err) throw err;
2120
+ * console.log(directory);
2121
+ * // Prints: /tmp/foo-itXde2 or C:\Users\...\AppData\Local\Temp\foo-itXde2
2122
+ * });
2123
+ * ```
2124
+ *
2125
+ * The `fs.mkdtemp()` method will append the six randomly selected characters
2126
+ * directly to the `prefix` string. For instance, given a directory `/tmp`, if the
2127
+ * intention is to create a temporary directory _within_`/tmp`, the `prefix`must end with a trailing platform-specific path separator
2128
+ * (`import { sep } from 'node:path'`).
2129
+ *
2130
+ * ```js
2131
+ * import { tmpdir } from 'node:os';
2132
+ * import { mkdtemp } from 'node:fs';
2133
+ *
2134
+ * // The parent directory for the new temporary directory
2135
+ * const tmpDir = tmpdir();
2136
+ *
2137
+ * // This method is *INCORRECT*:
2138
+ * mkdtemp(tmpDir, (err, directory) => {
2139
+ * if (err) throw err;
2140
+ * console.log(directory);
2141
+ * // Will print something similar to `/tmpabc123`.
2142
+ * // A new temporary directory is created at the file system root
2143
+ * // rather than *within* the /tmp directory.
2144
+ * });
2145
+ *
2146
+ * // This method is *CORRECT*:
2147
+ * import { sep } from 'node:path';
2148
+ * mkdtemp(`${tmpDir}${sep}`, (err, directory) => {
2149
+ * if (err) throw err;
2150
+ * console.log(directory);
2151
+ * // Will print something similar to `/tmp/abc123`.
2152
+ * // A new temporary directory is created within
2153
+ * // the /tmp directory.
2154
+ * });
2155
+ * ```
2156
+ * @since v5.10.0
2157
+ */
2158
+ export function mkdtemp(
2159
+ prefix: string,
2160
+ options: EncodingOption,
2161
+ callback: (err: NodeJS.ErrnoException | null, folder: string) => void,
2162
+ ): void;
2163
+ /**
2164
+ * Asynchronously creates a unique temporary directory.
2165
+ * Generates six random characters to be appended behind a required prefix to create a unique temporary directory.
2166
+ * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
2167
+ */
2168
+ export function mkdtemp(
2169
+ prefix: string,
2170
+ options: BufferEncodingOption,
2171
+ callback: (err: NodeJS.ErrnoException | null, folder: NonSharedBuffer) => void,
2172
+ ): void;
2173
+ /**
2174
+ * Asynchronously creates a unique temporary directory.
2175
+ * Generates six random characters to be appended behind a required prefix to create a unique temporary directory.
2176
+ * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
2177
+ */
2178
+ export function mkdtemp(
2179
+ prefix: string,
2180
+ options: EncodingOption,
2181
+ callback: (err: NodeJS.ErrnoException | null, folder: string | NonSharedBuffer) => void,
2182
+ ): void;
2183
+ /**
2184
+ * Asynchronously creates a unique temporary directory.
2185
+ * Generates six random characters to be appended behind a required prefix to create a unique temporary directory.
2186
+ */
2187
+ export function mkdtemp(
2188
+ prefix: string,
2189
+ callback: (err: NodeJS.ErrnoException | null, folder: string) => void,
2190
+ ): void;
2191
+ export namespace mkdtemp {
2192
+ /**
2193
+ * Asynchronously creates a unique temporary directory.
2194
+ * Generates six random characters to be appended behind a required prefix to create a unique temporary directory.
2195
+ * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
2196
+ */
2197
+ function __promisify__(prefix: string, options?: EncodingOption): Promise<string>;
2198
+ /**
2199
+ * Asynchronously creates a unique temporary directory.
2200
+ * Generates six random characters to be appended behind a required prefix to create a unique temporary directory.
2201
+ * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
2202
+ */
2203
+ function __promisify__(prefix: string, options: BufferEncodingOption): Promise<NonSharedBuffer>;
2204
+ /**
2205
+ * Asynchronously creates a unique temporary directory.
2206
+ * Generates six random characters to be appended behind a required prefix to create a unique temporary directory.
2207
+ * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
2208
+ */
2209
+ function __promisify__(prefix: string, options?: EncodingOption): Promise<string | NonSharedBuffer>;
2210
+ }
2211
+ /**
2212
+ * Returns the created directory path.
2213
+ *
2214
+ * For detailed information, see the documentation of the asynchronous version of
2215
+ * this API: {@link mkdtemp}.
2216
+ *
2217
+ * The optional `options` argument can be a string specifying an encoding, or an
2218
+ * object with an `encoding` property specifying the character encoding to use.
2219
+ * @since v5.10.0
2220
+ */
2221
+ export function mkdtempSync(prefix: string, options?: EncodingOption): string;
2222
+ /**
2223
+ * Synchronously creates a unique temporary directory.
2224
+ * Generates six random characters to be appended behind a required prefix to create a unique temporary directory.
2225
+ * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
2226
+ */
2227
+ export function mkdtempSync(prefix: string, options: BufferEncodingOption): NonSharedBuffer;
2228
+ /**
2229
+ * Synchronously creates a unique temporary directory.
2230
+ * Generates six random characters to be appended behind a required prefix to create a unique temporary directory.
2231
+ * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
2232
+ */
2233
+ export function mkdtempSync(prefix: string, options?: EncodingOption): string | NonSharedBuffer;
2234
+ export interface DisposableTempDir extends Disposable {
2235
+ /**
2236
+ * The path of the created directory.
2237
+ */
2238
+ path: string;
2239
+ /**
2240
+ * A function which removes the created directory.
2241
+ */
2242
+ remove(): void;
2243
+ /**
2244
+ * The same as `remove`.
2245
+ */
2246
+ [Symbol.dispose](): void;
2247
+ }
2248
+ /**
2249
+ * Returns a disposable object whose `path` property holds the created directory
2250
+ * path. When the object is disposed, the directory and its contents will be
2251
+ * removed if it still exists. If the directory cannot be deleted, disposal will
2252
+ * throw an error. The object has a `remove()` method which will perform the same
2253
+ * task.
2254
+ *
2255
+ * <!-- TODO: link MDN docs for disposables once https://github.com/mdn/content/pull/38027 lands -->
2256
+ *
2257
+ * For detailed information, see the documentation of `fs.mkdtemp()`.
2258
+ *
2259
+ * There is no callback-based version of this API because it is designed for use
2260
+ * with the `using` syntax.
2261
+ *
2262
+ * The optional `options` argument can be a string specifying an encoding, or an
2263
+ * object with an `encoding` property specifying the character encoding to use.
2264
+ * @since v24.4.0
2265
+ */
2266
+ export function mkdtempDisposableSync(prefix: string, options?: EncodingOption): DisposableTempDir;
2267
+ /**
2268
+ * 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 `'..'`.
2269
+ *
2270
+ * See the POSIX [`readdir(3)`](http://man7.org/linux/man-pages/man3/readdir.3.html) documentation for more details.
2271
+ *
2272
+ * The optional `options` argument can be a string specifying an encoding, or an
2273
+ * object with an `encoding` property specifying the character encoding to use for
2274
+ * the filenames passed to the callback. If the `encoding` is set to `'buffer'`,
2275
+ * the filenames returned will be passed as `Buffer` objects.
2276
+ *
2277
+ * If `options.withFileTypes` is set to `true`, the `files` array will contain `fs.Dirent` objects.
2278
+ * @since v0.1.8
2279
+ */
2280
+ export function readdir(
2281
+ path: PathLike,
2282
+ options:
2283
+ | {
2284
+ encoding: BufferEncoding | null;
2285
+ withFileTypes?: false | undefined;
2286
+ recursive?: boolean | undefined;
2287
+ }
2288
+ | BufferEncoding
2289
+ | undefined
2290
+ | null,
2291
+ callback: (err: NodeJS.ErrnoException | null, files: string[]) => void,
2292
+ ): void;
2293
+ /**
2294
+ * Asynchronous readdir(3) - read a directory.
2295
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
2296
+ * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
2297
+ */
2298
+ export function readdir(
2299
+ path: PathLike,
2300
+ options:
2301
+ | {
2302
+ encoding: "buffer";
2303
+ withFileTypes?: false | undefined;
2304
+ recursive?: boolean | undefined;
2305
+ }
2306
+ | "buffer",
2307
+ callback: (err: NodeJS.ErrnoException | null, files: NonSharedBuffer[]) => void,
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 The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
2313
+ */
2314
+ export function readdir(
2315
+ path: PathLike,
2316
+ options:
2317
+ | (ObjectEncodingOptions & {
2318
+ withFileTypes?: false | undefined;
2319
+ recursive?: boolean | undefined;
2320
+ })
2321
+ | BufferEncoding
2322
+ | undefined
2323
+ | null,
2324
+ callback: (err: NodeJS.ErrnoException | null, files: string[] | NonSharedBuffer[]) => void,
2325
+ ): void;
2326
+ /**
2327
+ * Asynchronous readdir(3) - read a directory.
2328
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
2329
+ */
2330
+ export function readdir(
2331
+ path: PathLike,
2332
+ callback: (err: NodeJS.ErrnoException | null, files: string[]) => void,
2333
+ ): void;
2334
+ /**
2335
+ * Asynchronous readdir(3) - read a directory.
2336
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
2337
+ * @param options If called with `withFileTypes: true` the result data will be an array of Dirent.
2338
+ */
2339
+ export function readdir(
2340
+ path: PathLike,
2341
+ options: ObjectEncodingOptions & {
2342
+ withFileTypes: true;
2343
+ recursive?: boolean | undefined;
2344
+ },
2345
+ callback: (err: NodeJS.ErrnoException | null, files: Dirent[]) => void,
2346
+ ): void;
2347
+ /**
2348
+ * Asynchronous readdir(3) - read a directory.
2349
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
2350
+ * @param options Must include `withFileTypes: true` and `encoding: 'buffer'`.
2351
+ */
2352
+ export function readdir(
2353
+ path: PathLike,
2354
+ options: {
2355
+ encoding: "buffer";
2356
+ withFileTypes: true;
2357
+ recursive?: boolean | undefined;
2358
+ },
2359
+ callback: (err: NodeJS.ErrnoException | null, files: Dirent<NonSharedBuffer>[]) => void,
2360
+ ): void;
2361
+ export namespace readdir {
2362
+ /**
2363
+ * Asynchronous readdir(3) - read a directory.
2364
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
2365
+ * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
2366
+ */
2367
+ function __promisify__(
2368
+ path: PathLike,
2369
+ options?:
2370
+ | {
2371
+ encoding: BufferEncoding | null;
2372
+ withFileTypes?: false | undefined;
2373
+ recursive?: boolean | undefined;
2374
+ }
2375
+ | BufferEncoding
2376
+ | null,
2377
+ ): Promise<string[]>;
2378
+ /**
2379
+ * Asynchronous readdir(3) - read a directory.
2380
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
2381
+ * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
2382
+ */
2383
+ function __promisify__(
2384
+ path: PathLike,
2385
+ options:
2386
+ | "buffer"
2387
+ | {
2388
+ encoding: "buffer";
2389
+ withFileTypes?: false | undefined;
2390
+ recursive?: boolean | undefined;
2391
+ },
2392
+ ): Promise<NonSharedBuffer[]>;
2393
+ /**
2394
+ * Asynchronous readdir(3) - read a directory.
2395
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
2396
+ * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
2397
+ */
2398
+ function __promisify__(
2399
+ path: PathLike,
2400
+ options?:
2401
+ | (ObjectEncodingOptions & {
2402
+ withFileTypes?: false | undefined;
2403
+ recursive?: boolean | undefined;
2404
+ })
2405
+ | BufferEncoding
2406
+ | null,
2407
+ ): Promise<string[] | NonSharedBuffer[]>;
2408
+ /**
2409
+ * Asynchronous readdir(3) - read a directory.
2410
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
2411
+ * @param options If called with `withFileTypes: true` the result data will be an array of Dirent
2412
+ */
2413
+ function __promisify__(
2414
+ path: PathLike,
2415
+ options: ObjectEncodingOptions & {
2416
+ withFileTypes: true;
2417
+ recursive?: boolean | undefined;
2418
+ },
2419
+ ): Promise<Dirent[]>;
2420
+ /**
2421
+ * Asynchronous readdir(3) - read a directory.
2422
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
2423
+ * @param options Must include `withFileTypes: true` and `encoding: 'buffer'`.
2424
+ */
2425
+ function __promisify__(
2426
+ path: PathLike,
2427
+ options: {
2428
+ encoding: "buffer";
2429
+ withFileTypes: true;
2430
+ recursive?: boolean | undefined;
2431
+ },
2432
+ ): Promise<Dirent<NonSharedBuffer>[]>;
2433
+ }
2434
+ /**
2435
+ * Reads the contents of the directory.
2436
+ *
2437
+ * See the POSIX [`readdir(3)`](http://man7.org/linux/man-pages/man3/readdir.3.html) documentation for more details.
2438
+ *
2439
+ * The optional `options` argument can be a string specifying an encoding, or an
2440
+ * object with an `encoding` property specifying the character encoding to use for
2441
+ * the filenames returned. If the `encoding` is set to `'buffer'`,
2442
+ * the filenames returned will be passed as `Buffer` objects.
2443
+ *
2444
+ * If `options.withFileTypes` is set to `true`, the result will contain `fs.Dirent` objects.
2445
+ * @since v0.1.21
2446
+ */
2447
+ export function readdirSync(
2448
+ path: PathLike,
2449
+ options?:
2450
+ | {
2451
+ encoding: BufferEncoding | null;
2452
+ withFileTypes?: false | undefined;
2453
+ recursive?: boolean | undefined;
2454
+ }
2455
+ | BufferEncoding
2456
+ | null,
2457
+ ): string[];
2458
+ /**
2459
+ * Synchronous readdir(3) - read a directory.
2460
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
2461
+ * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
2462
+ */
2463
+ export function readdirSync(
2464
+ path: PathLike,
2465
+ options:
2466
+ | {
2467
+ encoding: "buffer";
2468
+ withFileTypes?: false | undefined;
2469
+ recursive?: boolean | undefined;
2470
+ }
2471
+ | "buffer",
2472
+ ): NonSharedBuffer[];
2473
+ /**
2474
+ * Synchronous readdir(3) - read a directory.
2475
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
2476
+ * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
2477
+ */
2478
+ export function readdirSync(
2479
+ path: PathLike,
2480
+ options?:
2481
+ | (ObjectEncodingOptions & {
2482
+ withFileTypes?: false | undefined;
2483
+ recursive?: boolean | undefined;
2484
+ })
2485
+ | BufferEncoding
2486
+ | null,
2487
+ ): string[] | NonSharedBuffer[];
2488
+ /**
2489
+ * Synchronous readdir(3) - read a directory.
2490
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
2491
+ * @param options If called with `withFileTypes: true` the result data will be an array of Dirent.
2492
+ */
2493
+ export function readdirSync(
2494
+ path: PathLike,
2495
+ options: ObjectEncodingOptions & {
2496
+ withFileTypes: true;
2497
+ recursive?: boolean | undefined;
2498
+ },
2499
+ ): Dirent[];
2500
+ /**
2501
+ * Synchronous readdir(3) - read a directory.
2502
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
2503
+ * @param options Must include `withFileTypes: true` and `encoding: 'buffer'`.
2504
+ */
2505
+ export function readdirSync(
2506
+ path: PathLike,
2507
+ options: {
2508
+ encoding: "buffer";
2509
+ withFileTypes: true;
2510
+ recursive?: boolean | undefined;
2511
+ },
2512
+ ): Dirent<NonSharedBuffer>[];
2513
+ /**
2514
+ * Closes the file descriptor. No arguments other than a possible exception are
2515
+ * given to the completion callback.
2516
+ *
2517
+ * Calling `fs.close()` on any file descriptor (`fd`) that is currently in use
2518
+ * through any other `fs` operation may lead to undefined behavior.
2519
+ *
2520
+ * See the POSIX [`close(2)`](http://man7.org/linux/man-pages/man2/close.2.html) documentation for more detail.
2521
+ * @since v0.0.2
2522
+ */
2523
+ export function close(fd: number, callback?: NoParamCallback): void;
2524
+ export namespace close {
2525
+ /**
2526
+ * Asynchronous close(2) - close a file descriptor.
2527
+ * @param fd A file descriptor.
2528
+ */
2529
+ function __promisify__(fd: number): Promise<void>;
2530
+ }
2531
+ /**
2532
+ * Closes the file descriptor. Returns `undefined`.
2533
+ *
2534
+ * Calling `fs.closeSync()` on any file descriptor (`fd`) that is currently in use
2535
+ * through any other `fs` operation may lead to undefined behavior.
2536
+ *
2537
+ * See the POSIX [`close(2)`](http://man7.org/linux/man-pages/man2/close.2.html) documentation for more detail.
2538
+ * @since v0.1.21
2539
+ */
2540
+ export function closeSync(fd: number): void;
2541
+ /**
2542
+ * Asynchronous file open. See the POSIX [`open(2)`](http://man7.org/linux/man-pages/man2/open.2.html) documentation for more details.
2543
+ *
2544
+ * `mode` sets the file mode (permission and sticky bits), but only if the file was
2545
+ * created. On Windows, only the write permission can be manipulated; see {@link chmod}.
2546
+ *
2547
+ * The callback gets two arguments `(err, fd)`.
2548
+ *
2549
+ * Some characters (`< > : " / \ | ? *`) are reserved under Windows as documented
2550
+ * by [Naming Files, Paths, and Namespaces](https://docs.microsoft.com/en-us/windows/desktop/FileIO/naming-a-file). Under NTFS, if the filename contains
2551
+ * a colon, Node.js will open a file system stream, as described by [this MSDN page](https://docs.microsoft.com/en-us/windows/desktop/FileIO/using-streams).
2552
+ *
2553
+ * Functions based on `fs.open()` exhibit this behavior as well:`fs.writeFile()`, `fs.readFile()`, etc.
2554
+ * @since v0.0.2
2555
+ * @param [flags='r'] See `support of file system `flags``.
2556
+ * @param [mode=0o666]
2557
+ */
2558
+ export function open(
2559
+ path: PathLike,
2560
+ flags: OpenMode | undefined,
2561
+ mode: Mode | undefined | null,
2562
+ callback: (err: NodeJS.ErrnoException | null, fd: number) => void,
2563
+ ): void;
2564
+ /**
2565
+ * Asynchronous open(2) - open and possibly create a file. If the file is created, its mode will be `0o666`.
2566
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
2567
+ * @param [flags='r'] See `support of file system `flags``.
2568
+ */
2569
+ export function open(
2570
+ path: PathLike,
2571
+ flags: OpenMode | undefined,
2572
+ callback: (err: NodeJS.ErrnoException | null, fd: number) => void,
2573
+ ): void;
2574
+ /**
2575
+ * Asynchronous open(2) - open and possibly create a file. If the file is created, its mode will be `0o666`.
2576
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
2577
+ */
2578
+ export function open(path: PathLike, callback: (err: NodeJS.ErrnoException | null, fd: number) => void): void;
2579
+ export namespace open {
2580
+ /**
2581
+ * Asynchronous open(2) - open and possibly create a file.
2582
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
2583
+ * @param mode A file mode. If a string is passed, it is parsed as an octal integer. If not supplied, defaults to `0o666`.
2584
+ */
2585
+ function __promisify__(path: PathLike, flags: OpenMode, mode?: Mode | null): Promise<number>;
2586
+ }
2587
+ /**
2588
+ * Returns an integer representing the file descriptor.
2589
+ *
2590
+ * For detailed information, see the documentation of the asynchronous version of
2591
+ * this API: {@link open}.
2592
+ * @since v0.1.21
2593
+ * @param [flags='r']
2594
+ * @param [mode=0o666]
2595
+ */
2596
+ export function openSync(path: PathLike, flags: OpenMode, mode?: Mode | null): number;
2597
+ /**
2598
+ * Change the file system timestamps of the object referenced by `path`.
2599
+ *
2600
+ * The `atime` and `mtime` arguments follow these rules:
2601
+ *
2602
+ * * Values can be either numbers representing Unix epoch time in seconds, `Date`s, or a numeric string like `'123456789.0'`.
2603
+ * * If the value can not be converted to a number, or is `NaN`, `Infinity`, or `-Infinity`, an `Error` will be thrown.
2604
+ * @since v0.4.2
2605
+ */
2606
+ export function utimes(path: PathLike, atime: TimeLike, mtime: TimeLike, callback: NoParamCallback): void;
2607
+ export namespace utimes {
2608
+ /**
2609
+ * Asynchronously change file timestamps of the file referenced by the supplied path.
2610
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
2611
+ * @param atime The last access time. If a string is provided, it will be coerced to number.
2612
+ * @param mtime The last modified time. If a string is provided, it will be coerced to number.
2613
+ */
2614
+ function __promisify__(path: PathLike, atime: TimeLike, mtime: TimeLike): Promise<void>;
2615
+ }
2616
+ /**
2617
+ * Returns `undefined`.
2618
+ *
2619
+ * For detailed information, see the documentation of the asynchronous version of
2620
+ * this API: {@link utimes}.
2621
+ * @since v0.4.2
2622
+ */
2623
+ export function utimesSync(path: PathLike, atime: TimeLike, mtime: TimeLike): void;
2624
+ /**
2625
+ * Change the file system timestamps of the object referenced by the supplied file
2626
+ * descriptor. See {@link utimes}.
2627
+ * @since v0.4.2
2628
+ */
2629
+ export function futimes(fd: number, atime: TimeLike, mtime: TimeLike, callback: NoParamCallback): void;
2630
+ export namespace futimes {
2631
+ /**
2632
+ * Asynchronously change file timestamps of the file referenced by the supplied file descriptor.
2633
+ * @param fd A file descriptor.
2634
+ * @param atime The last access time. If a string is provided, it will be coerced to number.
2635
+ * @param mtime The last modified time. If a string is provided, it will be coerced to number.
2636
+ */
2637
+ function __promisify__(fd: number, atime: TimeLike, mtime: TimeLike): Promise<void>;
2638
+ }
2639
+ /**
2640
+ * Synchronous version of {@link futimes}. Returns `undefined`.
2641
+ * @since v0.4.2
2642
+ */
2643
+ export function futimesSync(fd: number, atime: TimeLike, mtime: TimeLike): void;
2644
+ /**
2645
+ * Request that all data for the open file descriptor is flushed to the storage
2646
+ * device. The specific implementation is operating system and device specific.
2647
+ * Refer to the POSIX [`fsync(2)`](http://man7.org/linux/man-pages/man2/fsync.2.html) documentation for more detail. No arguments other
2648
+ * than a possible exception are given to the completion callback.
2649
+ * @since v0.1.96
2650
+ */
2651
+ export function fsync(fd: number, callback: NoParamCallback): void;
2652
+ export namespace fsync {
2653
+ /**
2654
+ * Asynchronous fsync(2) - synchronize a file's in-core state with the underlying storage device.
2655
+ * @param fd A file descriptor.
2656
+ */
2657
+ function __promisify__(fd: number): Promise<void>;
2658
+ }
2659
+ /**
2660
+ * Request that all data for the open file descriptor is flushed to the storage
2661
+ * device. The specific implementation is operating system and device specific.
2662
+ * Refer to the POSIX [`fsync(2)`](http://man7.org/linux/man-pages/man2/fsync.2.html) documentation for more detail. Returns `undefined`.
2663
+ * @since v0.1.96
2664
+ */
2665
+ export function fsyncSync(fd: number): void;
2666
+ export interface WriteOptions {
2667
+ /**
2668
+ * @default 0
2669
+ */
2670
+ offset?: number | undefined;
2671
+ /**
2672
+ * @default `buffer.byteLength - offset`
2673
+ */
2674
+ length?: number | undefined;
2675
+ /**
2676
+ * @default null
2677
+ */
2678
+ position?: number | null | undefined;
2679
+ }
2680
+ /**
2681
+ * Write `buffer` to the file specified by `fd`.
2682
+ *
2683
+ * `offset` determines the part of the buffer to be written, and `length` is
2684
+ * an integer specifying the number of bytes to write.
2685
+ *
2686
+ * `position` refers to the offset from the beginning of the file where this data
2687
+ * should be written. If `typeof position !== 'number'`, the data will be written
2688
+ * at the current position. See [`pwrite(2)`](http://man7.org/linux/man-pages/man2/pwrite.2.html).
2689
+ *
2690
+ * The callback will be given three arguments `(err, bytesWritten, buffer)` where `bytesWritten` specifies how many _bytes_ were written from `buffer`.
2691
+ *
2692
+ * If this method is invoked as its `util.promisify()` ed version, it returns
2693
+ * a promise for an `Object` with `bytesWritten` and `buffer` properties.
2694
+ *
2695
+ * It is unsafe to use `fs.write()` multiple times on the same file without waiting
2696
+ * for the callback. For this scenario, {@link createWriteStream} is
2697
+ * recommended.
2698
+ *
2699
+ * On Linux, positional writes don't work when the file is opened in append mode.
2700
+ * The kernel ignores the position argument and always appends the data to
2701
+ * the end of the file.
2702
+ * @since v0.0.2
2703
+ * @param [offset=0]
2704
+ * @param [length=buffer.byteLength - offset]
2705
+ * @param [position='null']
2706
+ */
2707
+ export function write<TBuffer extends NodeJS.ArrayBufferView>(
2708
+ fd: number,
2709
+ buffer: TBuffer,
2710
+ offset: number | undefined | null,
2711
+ length: number | undefined | null,
2712
+ position: number | undefined | null,
2713
+ callback: (err: NodeJS.ErrnoException | null, written: number, buffer: TBuffer) => void,
2714
+ ): void;
2715
+ /**
2716
+ * Asynchronously writes `buffer` to the file referenced by the supplied file descriptor.
2717
+ * @param fd A file descriptor.
2718
+ * @param offset The part of the buffer to be written. If not supplied, defaults to `0`.
2719
+ * @param length The number of bytes to write. If not supplied, defaults to `buffer.length - offset`.
2720
+ */
2721
+ export function write<TBuffer extends NodeJS.ArrayBufferView>(
2722
+ fd: number,
2723
+ buffer: TBuffer,
2724
+ offset: number | undefined | null,
2725
+ length: number | undefined | null,
2726
+ callback: (err: NodeJS.ErrnoException | null, written: number, buffer: TBuffer) => void,
2727
+ ): void;
2728
+ /**
2729
+ * Asynchronously writes `buffer` to the file referenced by the supplied file descriptor.
2730
+ * @param fd A file descriptor.
2731
+ * @param offset The part of the buffer to be written. If not supplied, defaults to `0`.
2732
+ */
2733
+ export function write<TBuffer extends NodeJS.ArrayBufferView>(
2734
+ fd: number,
2735
+ buffer: TBuffer,
2736
+ offset: number | undefined | null,
2737
+ callback: (err: NodeJS.ErrnoException | null, written: number, buffer: TBuffer) => void,
2738
+ ): void;
2739
+ /**
2740
+ * Asynchronously writes `buffer` to the file referenced by the supplied file descriptor.
2741
+ * @param fd A file descriptor.
2742
+ */
2743
+ export function write<TBuffer extends NodeJS.ArrayBufferView>(
2744
+ fd: number,
2745
+ buffer: TBuffer,
2746
+ callback: (err: NodeJS.ErrnoException | null, written: number, buffer: TBuffer) => void,
2747
+ ): void;
2748
+ /**
2749
+ * Asynchronously writes `buffer` to the file referenced by the supplied file descriptor.
2750
+ * @param fd A file descriptor.
2751
+ * @param options An object with the following properties:
2752
+ * * `offset` The part of the buffer to be written. If not supplied, defaults to `0`.
2753
+ * * `length` The number of bytes to write. If not supplied, defaults to `buffer.length - offset`.
2754
+ * * `position` The offset from the beginning of the file where this data should be written. If not supplied, defaults to the current position.
2755
+ */
2756
+ export function write<TBuffer extends NodeJS.ArrayBufferView>(
2757
+ fd: number,
2758
+ buffer: TBuffer,
2759
+ options: WriteOptions,
2760
+ callback: (err: NodeJS.ErrnoException | null, written: number, buffer: TBuffer) => void,
2761
+ ): void;
2762
+ /**
2763
+ * Asynchronously writes `string` to the file referenced by the supplied file descriptor.
2764
+ * @param fd A file descriptor.
2765
+ * @param string A string to write.
2766
+ * @param position The offset from the beginning of the file where this data should be written. If not supplied, defaults to the current position.
2767
+ * @param encoding The expected string encoding.
2768
+ */
2769
+ export function write(
2770
+ fd: number,
2771
+ string: string,
2772
+ position: number | undefined | null,
2773
+ encoding: BufferEncoding | undefined | null,
2774
+ callback: (err: NodeJS.ErrnoException | null, written: number, str: string) => void,
2775
+ ): void;
2776
+ /**
2777
+ * Asynchronously writes `string` to the file referenced by the supplied file descriptor.
2778
+ * @param fd A file descriptor.
2779
+ * @param string A string to write.
2780
+ * @param position The offset from the beginning of the file where this data should be written. If not supplied, defaults to the current position.
2781
+ */
2782
+ export function write(
2783
+ fd: number,
2784
+ string: string,
2785
+ position: number | undefined | null,
2786
+ callback: (err: NodeJS.ErrnoException | null, written: number, str: string) => void,
2787
+ ): void;
2788
+ /**
2789
+ * Asynchronously writes `string` to the file referenced by the supplied file descriptor.
2790
+ * @param fd A file descriptor.
2791
+ * @param string A string to write.
2792
+ */
2793
+ export function write(
2794
+ fd: number,
2795
+ string: string,
2796
+ callback: (err: NodeJS.ErrnoException | null, written: number, str: string) => void,
2797
+ ): void;
2798
+ export namespace write {
2799
+ /**
2800
+ * Asynchronously writes `buffer` to the file referenced by the supplied file descriptor.
2801
+ * @param fd A file descriptor.
2802
+ * @param offset The part of the buffer to be written. If not supplied, defaults to `0`.
2803
+ * @param length The number of bytes to write. If not supplied, defaults to `buffer.length - offset`.
2804
+ * @param position The offset from the beginning of the file where this data should be written. If not supplied, defaults to the current position.
2805
+ */
2806
+ function __promisify__<TBuffer extends NodeJS.ArrayBufferView>(
2807
+ fd: number,
2808
+ buffer?: TBuffer,
2809
+ offset?: number,
2810
+ length?: number,
2811
+ position?: number | null,
2812
+ ): Promise<{
2813
+ bytesWritten: number;
2814
+ buffer: TBuffer;
2815
+ }>;
2816
+ /**
2817
+ * Asynchronously writes `buffer` to the file referenced by the supplied file descriptor.
2818
+ * @param fd A file descriptor.
2819
+ * @param options An object with the following properties:
2820
+ * * `offset` The part of the buffer to be written. If not supplied, defaults to `0`.
2821
+ * * `length` The number of bytes to write. If not supplied, defaults to `buffer.length - offset`.
2822
+ * * `position` The offset from the beginning of the file where this data should be written. If not supplied, defaults to the current position.
2823
+ */
2824
+ function __promisify__<TBuffer extends NodeJS.ArrayBufferView>(
2825
+ fd: number,
2826
+ buffer?: TBuffer,
2827
+ options?: WriteOptions,
2828
+ ): Promise<{
2829
+ bytesWritten: number;
2830
+ buffer: TBuffer;
2831
+ }>;
2832
+ /**
2833
+ * Asynchronously writes `string` to the file referenced by the supplied file descriptor.
2834
+ * @param fd A file descriptor.
2835
+ * @param string A string to write.
2836
+ * @param position The offset from the beginning of the file where this data should be written. If not supplied, defaults to the current position.
2837
+ * @param encoding The expected string encoding.
2838
+ */
2839
+ function __promisify__(
2840
+ fd: number,
2841
+ string: string,
2842
+ position?: number | null,
2843
+ encoding?: BufferEncoding | null,
2844
+ ): Promise<{
2845
+ bytesWritten: number;
2846
+ buffer: string;
2847
+ }>;
2848
+ }
2849
+ /**
2850
+ * For detailed information, see the documentation of the asynchronous version of
2851
+ * this API: {@link write}.
2852
+ * @since v0.1.21
2853
+ * @param [offset=0]
2854
+ * @param [length=buffer.byteLength - offset]
2855
+ * @param [position='null']
2856
+ * @return The number of bytes written.
2857
+ */
2858
+ export function writeSync(
2859
+ fd: number,
2860
+ buffer: NodeJS.ArrayBufferView,
2861
+ offset?: number | null,
2862
+ length?: number | null,
2863
+ position?: number | null,
2864
+ ): number;
2865
+ /**
2866
+ * Synchronously writes `string` to the file referenced by the supplied file descriptor, returning the number of bytes written.
2867
+ * @param fd A file descriptor.
2868
+ * @param string A string to write.
2869
+ * @param position The offset from the beginning of the file where this data should be written. If not supplied, defaults to the current position.
2870
+ * @param encoding The expected string encoding.
2871
+ */
2872
+ export function writeSync(
2873
+ fd: number,
2874
+ string: string,
2875
+ position?: number | null,
2876
+ encoding?: BufferEncoding | null,
2877
+ ): number;
2878
+ export type ReadPosition = number | bigint;
2879
+ export interface ReadOptions {
2880
+ /**
2881
+ * @default 0
2882
+ */
2883
+ offset?: number | undefined;
2884
+ /**
2885
+ * @default `length of buffer`
2886
+ */
2887
+ length?: number | undefined;
2888
+ /**
2889
+ * @default null
2890
+ */
2891
+ position?: ReadPosition | null | undefined;
2892
+ }
2893
+ export interface ReadOptionsWithBuffer<T extends NodeJS.ArrayBufferView> extends ReadOptions {
2894
+ buffer?: T | undefined;
2895
+ }
2896
+ /** @deprecated Use `ReadOptions` instead. */
2897
+ // TODO: remove in future major
2898
+ export interface ReadSyncOptions extends ReadOptions {}
2899
+ /** @deprecated Use `ReadOptionsWithBuffer` instead. */
2900
+ // TODO: remove in future major
2901
+ export interface ReadAsyncOptions<T extends NodeJS.ArrayBufferView> extends ReadOptionsWithBuffer<T> {}
2902
+ /**
2903
+ * Read data from the file specified by `fd`.
2904
+ *
2905
+ * The callback is given the three arguments, `(err, bytesRead, buffer)`.
2906
+ *
2907
+ * If the file is not modified concurrently, the end-of-file is reached when the
2908
+ * number of bytes read is zero.
2909
+ *
2910
+ * If this method is invoked as its `util.promisify()` ed version, it returns
2911
+ * a promise for an `Object` with `bytesRead` and `buffer` properties.
2912
+ * @since v0.0.2
2913
+ * @param buffer The buffer that the data will be written to.
2914
+ * @param offset The position in `buffer` to write the data to.
2915
+ * @param length The number of bytes to read.
2916
+ * @param position Specifies where to begin reading from in the file. If `position` is `null` or `-1 `, data will be read from the current file position, and the file position will be updated. If
2917
+ * `position` is an integer, the file position will be unchanged.
2918
+ */
2919
+ export function read<TBuffer extends NodeJS.ArrayBufferView>(
2920
+ fd: number,
2921
+ buffer: TBuffer,
2922
+ offset: number,
2923
+ length: number,
2924
+ position: ReadPosition | null,
2925
+ callback: (err: NodeJS.ErrnoException | null, bytesRead: number, buffer: TBuffer) => void,
2926
+ ): void;
2927
+ /**
2928
+ * Similar to the above `fs.read` function, this version takes an optional `options` object.
2929
+ * If not otherwise specified in an `options` object,
2930
+ * `buffer` defaults to `Buffer.alloc(16384)`,
2931
+ * `offset` defaults to `0`,
2932
+ * `length` defaults to `buffer.byteLength`, `- offset` as of Node 17.6.0
2933
+ * `position` defaults to `null`
2934
+ * @since v12.17.0, 13.11.0
2935
+ */
2936
+ export function read<TBuffer extends NodeJS.ArrayBufferView = NonSharedBuffer>(
2937
+ fd: number,
2938
+ options: ReadOptionsWithBuffer<TBuffer>,
2939
+ callback: (err: NodeJS.ErrnoException | null, bytesRead: number, buffer: TBuffer) => void,
2940
+ ): void;
2941
+ export function read<TBuffer extends NodeJS.ArrayBufferView>(
2942
+ fd: number,
2943
+ buffer: TBuffer,
2944
+ options: ReadOptions,
2945
+ callback: (err: NodeJS.ErrnoException | null, bytesRead: number, buffer: TBuffer) => void,
2946
+ ): void;
2947
+ export function read<TBuffer extends NodeJS.ArrayBufferView>(
2948
+ fd: number,
2949
+ buffer: TBuffer,
2950
+ callback: (err: NodeJS.ErrnoException | null, bytesRead: number, buffer: TBuffer) => void,
2951
+ ): void;
2952
+ export function read(
2953
+ fd: number,
2954
+ callback: (err: NodeJS.ErrnoException | null, bytesRead: number, buffer: NonSharedBuffer) => void,
2955
+ ): void;
2956
+ export namespace read {
2957
+ /**
2958
+ * @param fd A file descriptor.
2959
+ * @param buffer The buffer that the data will be written to.
2960
+ * @param offset The offset in the buffer at which to start writing.
2961
+ * @param length The number of bytes to read.
2962
+ * @param position The offset from the beginning of the file from which data should be read. If `null`, data will be read from the current position.
2963
+ */
2964
+ function __promisify__<TBuffer extends NodeJS.ArrayBufferView>(
2965
+ fd: number,
2966
+ buffer: TBuffer,
2967
+ offset: number,
2968
+ length: number,
2969
+ position: ReadPosition | null,
2970
+ ): Promise<{
2971
+ bytesRead: number;
2972
+ buffer: TBuffer;
2973
+ }>;
2974
+ function __promisify__<TBuffer extends NodeJS.ArrayBufferView = NonSharedBuffer>(
2975
+ fd: number,
2976
+ options: ReadOptionsWithBuffer<TBuffer>,
2977
+ ): Promise<{
2978
+ bytesRead: number;
2979
+ buffer: TBuffer;
2980
+ }>;
2981
+ function __promisify__(fd: number): Promise<{
2982
+ bytesRead: number;
2983
+ buffer: NonSharedBuffer;
2984
+ }>;
2985
+ }
2986
+ /**
2987
+ * Returns the number of `bytesRead`.
2988
+ *
2989
+ * For detailed information, see the documentation of the asynchronous version of
2990
+ * this API: {@link read}.
2991
+ * @since v0.1.21
2992
+ * @param [position='null']
2993
+ */
2994
+ export function readSync(
2995
+ fd: number,
2996
+ buffer: NodeJS.ArrayBufferView,
2997
+ offset: number,
2998
+ length: number,
2999
+ position: ReadPosition | null,
3000
+ ): number;
3001
+ /**
3002
+ * Similar to the above `fs.readSync` function, this version takes an optional `options` object.
3003
+ * If no `options` object is specified, it will default with the above values.
3004
+ */
3005
+ export function readSync(fd: number, buffer: NodeJS.ArrayBufferView, opts?: ReadOptions): number;
3006
+ export interface ReadFileOptions extends Abortable {
3007
+ encoding?: BufferEncoding | null | undefined;
3008
+ flag?: OpenMode | undefined;
3009
+ }
3010
+ export interface ReadFileOptionsWithStringEncoding extends ReadFileOptions {
3011
+ encoding: BufferEncoding;
3012
+ }
3013
+ export interface ReadFileOptionsWithBufferEncoding extends ReadFileOptions {
3014
+ encoding?: null | undefined;
3015
+ }
3016
+ export interface ReadFileOptionsWithBuffer<T extends NodeJS.ArrayBufferView>
3017
+ extends ReadFileOptionsWithBufferEncoding
3018
+ {
3019
+ buffer: T | ((size: number) => T);
3020
+ }
3021
+ /**
3022
+ * Asynchronously reads the entire contents of a file.
3023
+ *
3024
+ * ```js
3025
+ * import { readFile } from 'node:fs';
3026
+ *
3027
+ * readFile('/etc/passwd', (err, data) => {
3028
+ * if (err) throw err;
3029
+ * console.log(data);
3030
+ * });
3031
+ * ```
3032
+ *
3033
+ * The callback is passed two arguments `(err, data)`, where `data` is the
3034
+ * contents of the file.
3035
+ *
3036
+ * If no encoding is specified, then the raw buffer is returned.
3037
+ *
3038
+ * If `buffer` is provided and no encoding is specified, the returned `Buffer` is
3039
+ * a view over the supplied buffer containing only the bytes read. If the
3040
+ * supplied buffer is too small to contain the entire file, the callback is
3041
+ * called with an error.
3042
+ *
3043
+ * If `options` is a string, then it specifies the encoding:
3044
+ *
3045
+ * ```js
3046
+ * import { readFile } from 'node:fs';
3047
+ *
3048
+ * readFile('/etc/passwd', 'utf8', callback);
3049
+ * ```
3050
+ *
3051
+ * When the path is a directory, the behavior of `fs.readFile()` and
3052
+ * `fs.readFileSync()` is platform-specific. On macOS, Linux, and Windows, an
3053
+ * error will be returned. On FreeBSD, a representation of the directory's contents
3054
+ * will be returned.
3055
+ *
3056
+ * ```js
3057
+ * import { readFile } from 'node:fs';
3058
+ *
3059
+ * // macOS, Linux, and Windows
3060
+ * readFile('<directory>', (err, data) => {
3061
+ * // => [Error: EISDIR: illegal operation on a directory, read <directory>]
3062
+ * });
3063
+ *
3064
+ * // FreeBSD
3065
+ * readFile('<directory>', (err, data) => {
3066
+ * // => null, <data>
3067
+ * });
3068
+ * ```
3069
+ *
3070
+ * It is possible to abort an ongoing request using an `AbortSignal`. If a
3071
+ * request is aborted the callback is called with an `AbortError`:
3072
+ *
3073
+ * ```js
3074
+ * import { readFile } from 'node:fs';
3075
+ *
3076
+ * const controller = new AbortController();
3077
+ * const signal = controller.signal;
3078
+ * readFile(fileInfo[0].name, { signal }, (err, buf) => {
3079
+ * // ...
3080
+ * });
3081
+ * // When you want to abort the request
3082
+ * controller.abort();
3083
+ * ```
3084
+ *
3085
+ * The `fs.readFile()` function buffers the entire file. To minimize memory costs,
3086
+ * when possible prefer streaming via `fs.createReadStream()`.
3087
+ *
3088
+ * Aborting an ongoing request does not abort individual operating
3089
+ * system requests but rather the internal buffering `fs.readFile` performs.
3090
+ *
3091
+ * An example using the `buffer` option with a pre-allocated buffer:
3092
+ *
3093
+ * ```js
3094
+ * import { Buffer } from 'node:buffer';
3095
+ * import { readFile } from 'node:fs';
3096
+ *
3097
+ * const buf = Buffer.alloc(16384);
3098
+ * readFile('/path/to/file', { buffer: buf }, (err, data) => {
3099
+ * if (err) throw err;
3100
+ * console.log(data); // A view over `buf` containing only the bytes read
3101
+ * });
3102
+ * ```
3103
+ *
3104
+ * An example using the `buffer` option with a function returning a buffer:
3105
+ *
3106
+ * ```js
3107
+ * import { Buffer } from 'node:buffer';
3108
+ * import { readFile } from 'node:fs';
3109
+ *
3110
+ * readFile('/path/to/file', {
3111
+ * buffer: (size) => Buffer.alloc(size),
3112
+ * }, (err, data) => {
3113
+ * if (err) throw err;
3114
+ * console.log(data);
3115
+ * });
3116
+ * ```
3117
+ * @since v0.1.29
3118
+ * @param path filename or file descriptor
3119
+ */
3120
+ export function readFile<T extends NodeJS.ArrayBufferView>(
3121
+ path: PathOrFileDescriptor,
3122
+ options: ReadFileOptionsWithBuffer<T>,
3123
+ callback: (err: NodeJS.ErrnoException | null, data: BufferView<T>) => void,
3124
+ ): void;
3125
+ export function readFile(
3126
+ path: PathOrFileDescriptor,
3127
+ options: ReadFileOptionsWithBufferEncoding | null | undefined,
3128
+ callback: (err: NodeJS.ErrnoException | null, data: NonSharedBuffer) => void,
3129
+ ): void;
3130
+ export function readFile(
3131
+ path: PathOrFileDescriptor,
3132
+ options: ReadFileOptionsWithStringEncoding | BufferEncoding,
3133
+ callback: (err: NodeJS.ErrnoException | null, data: string) => void,
3134
+ ): void;
3135
+ export function readFile(
3136
+ path: PathOrFileDescriptor,
3137
+ options: ReadFileOptions | BufferEncoding | null | undefined,
3138
+ callback: (err: NodeJS.ErrnoException | null, data: string | NonSharedBuffer) => void,
3139
+ ): void;
3140
+ export function readFile(
3141
+ path: PathOrFileDescriptor,
3142
+ callback: (err: NodeJS.ErrnoException | null, data: NonSharedBuffer) => void,
3143
+ ): void;
3144
+ export namespace readFile {
3145
+ /**
3146
+ * Asynchronously reads the entire contents of a file.
3147
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
3148
+ * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
3149
+ * @param options An object that may contain an optional flag.
3150
+ * If a flag is not provided, it defaults to `'r'`.
3151
+ */
3152
+ function __promisify__(
3153
+ path: PathOrFileDescriptor,
3154
+ options?: {
3155
+ encoding?: null | undefined;
3156
+ flag?: string | undefined;
3157
+ } | null,
3158
+ ): Promise<NonSharedBuffer>;
3159
+ /**
3160
+ * Asynchronously reads the entire contents of a file.
3161
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
3162
+ * URL support is _experimental_.
3163
+ * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
3164
+ * @param options Either the encoding for the result, or an object that contains the encoding and an optional flag.
3165
+ * If a flag is not provided, it defaults to `'r'`.
3166
+ */
3167
+ function __promisify__(
3168
+ path: PathOrFileDescriptor,
3169
+ options:
3170
+ | {
3171
+ encoding: BufferEncoding;
3172
+ flag?: string | undefined;
3173
+ }
3174
+ | BufferEncoding,
3175
+ ): Promise<string>;
3176
+ /**
3177
+ * Asynchronously reads the entire contents of a file.
3178
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
3179
+ * URL support is _experimental_.
3180
+ * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
3181
+ * @param options Either the encoding for the result, or an object that contains the encoding and an optional flag.
3182
+ * If a flag is not provided, it defaults to `'r'`.
3183
+ */
3184
+ function __promisify__(
3185
+ path: PathOrFileDescriptor,
3186
+ options?:
3187
+ | (ObjectEncodingOptions & {
3188
+ flag?: string | undefined;
3189
+ })
3190
+ | BufferEncoding
3191
+ | null,
3192
+ ): Promise<string | NonSharedBuffer>;
3193
+ }
3194
+ export interface ReadFileSyncOptions {
3195
+ encoding?: BufferEncoding | null | undefined;
3196
+ flag?: OpenMode | undefined;
3197
+ }
3198
+ export interface ReadFileSyncOptionsWithStringEncoding extends ReadFileSyncOptions {
3199
+ encoding: BufferEncoding;
3200
+ }
3201
+ export interface ReadFileSyncOptionsWithBufferEncoding extends ReadFileSyncOptions {
3202
+ encoding?: null | undefined;
3203
+ }
3204
+ export interface ReadFileSyncOptionsWithBuffer<T extends NodeJS.ArrayBufferView>
3205
+ extends ReadFileSyncOptionsWithBufferEncoding
3206
+ {
3207
+ buffer: T | ((size: number) => T);
3208
+ }
3209
+ /**
3210
+ * Returns the contents of the `path`.
3211
+ *
3212
+ * For detailed information, see the documentation of the asynchronous version of
3213
+ * this API: `fs.readFile()`.
3214
+ *
3215
+ * If the `encoding` option is specified then this function returns a
3216
+ * string. Otherwise it returns a buffer.
3217
+ *
3218
+ * If `buffer` is provided and no encoding is specified, the returned {Buffer} is
3219
+ * a view over the supplied buffer containing only the bytes read. If the
3220
+ * supplied buffer is too small to contain the entire file, an error will be
3221
+ * thrown.
3222
+ *
3223
+ * Similar to `fs.readFile()`, when the path is a directory, the behavior of
3224
+ * `fs.readFileSync()` is platform-specific.
3225
+ *
3226
+ * ```js
3227
+ * import { readFileSync } from 'node:fs';
3228
+ *
3229
+ * // macOS, Linux, and Windows
3230
+ * readFileSync('<directory>');
3231
+ * // => [Error: EISDIR: illegal operation on a directory, read <directory>]
3232
+ *
3233
+ * // FreeBSD
3234
+ * readFileSync('<directory>'); // => <data>
3235
+ * ```
3236
+ * @since v0.1.8
3237
+ * @param path filename or file descriptor
3238
+ */
3239
+ export function readFileSync<T extends NodeJS.ArrayBufferView>(
3240
+ path: PathOrFileDescriptor,
3241
+ options: ReadFileSyncOptionsWithBuffer<T>,
3242
+ ): BufferView<T>;
3243
+ export function readFileSync(
3244
+ path: PathOrFileDescriptor,
3245
+ options?: ReadFileSyncOptionsWithBufferEncoding | null,
3246
+ ): NonSharedBuffer;
3247
+ export function readFileSync(
3248
+ path: PathOrFileDescriptor,
3249
+ options: ReadFileSyncOptionsWithStringEncoding | BufferEncoding,
3250
+ ): string;
3251
+ export function readFileSync(path: PathOrFileDescriptor, options: ReadFileSyncOptions): string | NonSharedBuffer;
3252
+ export type WriteFileOptions =
3253
+ | (
3254
+ & ObjectEncodingOptions
3255
+ & Abortable
3256
+ & {
3257
+ mode?: Mode | undefined;
3258
+ flag?: string | undefined;
3259
+ flush?: boolean | undefined;
3260
+ }
3261
+ )
3262
+ | BufferEncoding
3263
+ | null;
3264
+ /**
3265
+ * When `file` is a filename, asynchronously writes data to the file, replacing the
3266
+ * file if it already exists. `data` can be a string or a buffer.
3267
+ *
3268
+ * When `file` is a file descriptor, the behavior is similar to calling `fs.write()` directly (which is recommended). See the notes below on using
3269
+ * a file descriptor.
3270
+ *
3271
+ * The `encoding` option is ignored if `data` is a buffer.
3272
+ *
3273
+ * The `mode` option only affects the newly created file. See {@link open} for more details.
3274
+ *
3275
+ * ```js
3276
+ * import { writeFile } from 'node:fs';
3277
+ * import { Buffer } from 'node:buffer';
3278
+ *
3279
+ * const data = new Uint8Array(Buffer.from('Hello Node.js'));
3280
+ * writeFile('message.txt', data, (err) => {
3281
+ * if (err) throw err;
3282
+ * console.log('The file has been saved!');
3283
+ * });
3284
+ * ```
3285
+ *
3286
+ * If `options` is a string, then it specifies the encoding:
3287
+ *
3288
+ * ```js
3289
+ * import { writeFile } from 'node:fs';
3290
+ *
3291
+ * writeFile('message.txt', 'Hello Node.js', 'utf8', callback);
3292
+ * ```
3293
+ *
3294
+ * It is unsafe to use `fs.writeFile()` multiple times on the same file without
3295
+ * waiting for the callback. For this scenario, {@link createWriteStream} is
3296
+ * recommended.
3297
+ *
3298
+ * Similarly to `fs.readFile` \- `fs.writeFile` is a convenience method that
3299
+ * performs multiple `write` calls internally to write the buffer passed to it.
3300
+ * For performance sensitive code consider using {@link createWriteStream}.
3301
+ *
3302
+ * It is possible to use an `AbortSignal` to cancel an `fs.writeFile()`.
3303
+ * Cancelation is "best effort", and some amount of data is likely still
3304
+ * to be written.
3305
+ *
3306
+ * ```js
3307
+ * import { writeFile } from 'node:fs';
3308
+ * import { Buffer } from 'node:buffer';
3309
+ *
3310
+ * const controller = new AbortController();
3311
+ * const { signal } = controller;
3312
+ * const data = new Uint8Array(Buffer.from('Hello Node.js'));
3313
+ * writeFile('message.txt', data, { signal }, (err) => {
3314
+ * // When a request is aborted - the callback is called with an AbortError
3315
+ * });
3316
+ * // When the request should be aborted
3317
+ * controller.abort();
3318
+ * ```
3319
+ *
3320
+ * Aborting an ongoing request does not abort individual operating
3321
+ * system requests but rather the internal buffering `fs.writeFile` performs.
3322
+ * @since v0.1.29
3323
+ * @param file filename or file descriptor
3324
+ */
3325
+ export function writeFile(
3326
+ file: PathOrFileDescriptor,
3327
+ data: string | NodeJS.ArrayBufferView,
3328
+ options: WriteFileOptions,
3329
+ callback: NoParamCallback,
3330
+ ): void;
3331
+ /**
3332
+ * Asynchronously writes data to a file, replacing the file if it already exists.
3333
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
3334
+ * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
3335
+ * @param data The data to write. If something other than a Buffer or Uint8Array is provided, the value is coerced to a string.
3336
+ */
3337
+ export function writeFile(
3338
+ path: PathOrFileDescriptor,
3339
+ data: string | NodeJS.ArrayBufferView,
3340
+ callback: NoParamCallback,
3341
+ ): void;
3342
+ export namespace writeFile {
3343
+ /**
3344
+ * Asynchronously writes data to a file, replacing the file if it already exists.
3345
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
3346
+ * URL support is _experimental_.
3347
+ * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
3348
+ * @param data The data to write. If something other than a Buffer or Uint8Array is provided, the value is coerced to a string.
3349
+ * @param options Either the encoding for the file, or an object optionally specifying the encoding, file mode, and flag.
3350
+ * If `encoding` is not supplied, the default of `'utf8'` is used.
3351
+ * If `mode` is not supplied, the default of `0o666` is used.
3352
+ * If `mode` is a string, it is parsed as an octal integer.
3353
+ * If `flag` is not supplied, the default of `'w'` is used.
3354
+ */
3355
+ function __promisify__(
3356
+ path: PathOrFileDescriptor,
3357
+ data: string | NodeJS.ArrayBufferView,
3358
+ options?: WriteFileOptions,
3359
+ ): Promise<void>;
3360
+ }
3361
+ /**
3362
+ * Returns `undefined`.
3363
+ *
3364
+ * The `mode` option only affects the newly created file. See {@link open} for more details.
3365
+ *
3366
+ * For detailed information, see the documentation of the asynchronous version of
3367
+ * this API: {@link writeFile}.
3368
+ * @since v0.1.29
3369
+ * @param file filename or file descriptor
3370
+ */
3371
+ export function writeFileSync(
3372
+ file: PathOrFileDescriptor,
3373
+ data: string | NodeJS.ArrayBufferView,
3374
+ options?: WriteFileOptions,
3375
+ ): void;
3376
+ /**
3377
+ * Asynchronously append data to a file, creating the file if it does not yet
3378
+ * exist. `data` can be a string or a `Buffer`.
3379
+ *
3380
+ * The `mode` option only affects the newly created file. See {@link open} for more details.
3381
+ *
3382
+ * ```js
3383
+ * import { appendFile } from 'node:fs';
3384
+ *
3385
+ * appendFile('message.txt', 'data to append', (err) => {
3386
+ * if (err) throw err;
3387
+ * console.log('The "data to append" was appended to file!');
3388
+ * });
3389
+ * ```
3390
+ *
3391
+ * If `options` is a string, then it specifies the encoding:
3392
+ *
3393
+ * ```js
3394
+ * import { appendFile } from 'node:fs';
3395
+ *
3396
+ * appendFile('message.txt', 'data to append', 'utf8', callback);
3397
+ * ```
3398
+ *
3399
+ * The `path` may be specified as a numeric file descriptor that has been opened
3400
+ * for appending (using `fs.open()` or `fs.openSync()`). The file descriptor will
3401
+ * not be closed automatically.
3402
+ *
3403
+ * ```js
3404
+ * import { open, close, appendFile } from 'node:fs';
3405
+ *
3406
+ * function closeFd(fd) {
3407
+ * close(fd, (err) => {
3408
+ * if (err) throw err;
3409
+ * });
3410
+ * }
3411
+ *
3412
+ * open('message.txt', 'a', (err, fd) => {
3413
+ * if (err) throw err;
3414
+ *
3415
+ * try {
3416
+ * appendFile(fd, 'data to append', 'utf8', (err) => {
3417
+ * closeFd(fd);
3418
+ * if (err) throw err;
3419
+ * });
3420
+ * } catch (err) {
3421
+ * closeFd(fd);
3422
+ * throw err;
3423
+ * }
3424
+ * });
3425
+ * ```
3426
+ * @since v0.6.7
3427
+ * @param path filename or file descriptor
3428
+ */
3429
+ export function appendFile(
3430
+ path: PathOrFileDescriptor,
3431
+ data: string | Uint8Array,
3432
+ options: WriteFileOptions,
3433
+ callback: NoParamCallback,
3434
+ ): void;
3435
+ /**
3436
+ * Asynchronously append data to a file, creating the file if it does not exist.
3437
+ * @param file A path to a file. If a URL is provided, it must use the `file:` protocol.
3438
+ * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
3439
+ * @param data The data to write. If something other than a Buffer or Uint8Array is provided, the value is coerced to a string.
3440
+ */
3441
+ export function appendFile(file: PathOrFileDescriptor, data: string | Uint8Array, callback: NoParamCallback): void;
3442
+ export namespace appendFile {
3443
+ /**
3444
+ * Asynchronously append data to a file, creating the file if it does not exist.
3445
+ * @param file A path to a file. If a URL is provided, it must use the `file:` protocol.
3446
+ * URL support is _experimental_.
3447
+ * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
3448
+ * @param data The data to write. If something other than a Buffer or Uint8Array is provided, the value is coerced to a string.
3449
+ * @param options Either the encoding for the file, or an object optionally specifying the encoding, file mode, and flag.
3450
+ * If `encoding` is not supplied, the default of `'utf8'` is used.
3451
+ * If `mode` is not supplied, the default of `0o666` is used.
3452
+ * If `mode` is a string, it is parsed as an octal integer.
3453
+ * If `flag` is not supplied, the default of `'a'` is used.
3454
+ */
3455
+ function __promisify__(
3456
+ file: PathOrFileDescriptor,
3457
+ data: string | Uint8Array,
3458
+ options?: WriteFileOptions,
3459
+ ): Promise<void>;
3460
+ }
3461
+ /**
3462
+ * Synchronously append data to a file, creating the file if it does not yet
3463
+ * exist. `data` can be a string or a `Buffer`.
3464
+ *
3465
+ * The `mode` option only affects the newly created file. See {@link open} for more details.
3466
+ *
3467
+ * ```js
3468
+ * import { appendFileSync } from 'node:fs';
3469
+ *
3470
+ * try {
3471
+ * appendFileSync('message.txt', 'data to append');
3472
+ * console.log('The "data to append" was appended to file!');
3473
+ * } catch (err) {
3474
+ * // Handle the error
3475
+ * }
3476
+ * ```
3477
+ *
3478
+ * If `options` is a string, then it specifies the encoding:
3479
+ *
3480
+ * ```js
3481
+ * import { appendFileSync } from 'node:fs';
3482
+ *
3483
+ * appendFileSync('message.txt', 'data to append', 'utf8');
3484
+ * ```
3485
+ *
3486
+ * The `path` may be specified as a numeric file descriptor that has been opened
3487
+ * for appending (using `fs.open()` or `fs.openSync()`). The file descriptor will
3488
+ * not be closed automatically.
3489
+ *
3490
+ * ```js
3491
+ * import { openSync, closeSync, appendFileSync } from 'node:fs';
3492
+ *
3493
+ * let fd;
3494
+ *
3495
+ * try {
3496
+ * fd = openSync('message.txt', 'a');
3497
+ * appendFileSync(fd, 'data to append', 'utf8');
3498
+ * } catch (err) {
3499
+ * // Handle the error
3500
+ * } finally {
3501
+ * if (fd !== undefined)
3502
+ * closeSync(fd);
3503
+ * }
3504
+ * ```
3505
+ * @since v0.6.7
3506
+ * @param path filename or file descriptor
3507
+ */
3508
+ export function appendFileSync(
3509
+ path: PathOrFileDescriptor,
3510
+ data: string | Uint8Array,
3511
+ options?: WriteFileOptions,
3512
+ ): void;
3513
+ /**
3514
+ * Watch for changes on `filename`. The callback `listener` will be called each
3515
+ * time the file is accessed.
3516
+ *
3517
+ * 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
+ * whether the process should continue to run as long as files are being watched.
3519
+ * The `options` object may specify an `interval` property indicating how often the
3520
+ * target should be polled in milliseconds.
3521
+ *
3522
+ * The `listener` gets two arguments the current stat object and the previous
3523
+ * stat object:
3524
+ *
3525
+ * ```js
3526
+ * import { watchFile } from 'node:fs';
3527
+ *
3528
+ * watchFile('message.text', (curr, prev) => {
3529
+ * console.log(`the current mtime is: ${curr.mtime}`);
3530
+ * console.log(`the previous mtime was: ${prev.mtime}`);
3531
+ * });
3532
+ * ```
3533
+ *
3534
+ * These stat objects are instances of `fs.Stat`. If the `bigint` option is `true`,
3535
+ * the numeric values in these objects are specified as `BigInt`s.
3536
+ *
3537
+ * To be notified when the file was modified, not just accessed, it is necessary
3538
+ * to compare `curr.mtimeMs` and `prev.mtimeMs`.
3539
+ *
3540
+ * When an `fs.watchFile` operation results in an `ENOENT` error, it
3541
+ * will invoke the listener once, with all the fields zeroed (or, for dates, the
3542
+ * Unix Epoch). If the file is created later on, the listener will be called
3543
+ * again, with the latest stat objects. This is a change in functionality since
3544
+ * v0.10.
3545
+ *
3546
+ * 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
+ *
3548
+ * When a file being watched by `fs.watchFile()` disappears and reappears,
3549
+ * then the contents of `previous` in the second callback event (the file's
3550
+ * reappearance) will be the same as the contents of `previous` in the first
3551
+ * callback event (its disappearance).
3552
+ *
3553
+ * This happens when:
3554
+ *
3555
+ * * the file is deleted, followed by a restore
3556
+ * * the file is renamed and then renamed a second time back to its original name
3557
+ * @since v0.1.31
3558
+ */
3559
+ export interface WatchFileOptions {
3560
+ bigint?: boolean | undefined;
3561
+ persistent?: boolean | undefined;
3562
+ interval?: number | undefined;
3563
+ }
3564
+ /**
3565
+ * Watch for changes on `filename`. The callback `listener` will be called each
3566
+ * time the file is accessed.
3567
+ *
3568
+ * The `options` argument may be omitted. If provided, it should be an object. The `options` object may contain a boolean named `persistent` that indicates
3569
+ * whether the process should continue to run as long as files are being watched.
3570
+ * The `options` object may specify an `interval` property indicating how often the
3571
+ * target should be polled in milliseconds.
3572
+ *
3573
+ * The `listener` gets two arguments the current stat object and the previous
3574
+ * stat object:
3575
+ *
3576
+ * ```js
3577
+ * import { watchFile } from 'node:fs';
3578
+ *
3579
+ * watchFile('message.text', (curr, prev) => {
3580
+ * console.log(`the current mtime is: ${curr.mtime}`);
3581
+ * console.log(`the previous mtime was: ${prev.mtime}`);
3582
+ * });
3583
+ * ```
3584
+ *
3585
+ * These stat objects are instances of `fs.Stat`. If the `bigint` option is `true`,
3586
+ * the numeric values in these objects are specified as `BigInt`s.
3587
+ *
3588
+ * To be notified when the file was modified, not just accessed, it is necessary
3589
+ * to compare `curr.mtimeMs` and `prev.mtimeMs`.
3590
+ *
3591
+ * When an `fs.watchFile` operation results in an `ENOENT` error, it
3592
+ * will invoke the listener once, with all the fields zeroed (or, for dates, the
3593
+ * Unix Epoch). If the file is created later on, the listener will be called
3594
+ * again, with the latest stat objects. This is a change in functionality since
3595
+ * v0.10.
3596
+ *
3597
+ * 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.
3598
+ *
3599
+ * When a file being watched by `fs.watchFile()` disappears and reappears,
3600
+ * then the contents of `previous` in the second callback event (the file's
3601
+ * reappearance) will be the same as the contents of `previous` in the first
3602
+ * callback event (its disappearance).
3603
+ *
3604
+ * This happens when:
3605
+ *
3606
+ * * the file is deleted, followed by a restore
3607
+ * * the file is renamed and then renamed a second time back to its original name
3608
+ * @since v0.1.31
3609
+ */
3610
+ export function watchFile(
3611
+ filename: PathLike,
3612
+ options:
3613
+ | (WatchFileOptions & {
3614
+ bigint?: false | undefined;
3615
+ })
3616
+ | undefined,
3617
+ listener: StatsListener,
3618
+ ): StatWatcher;
3619
+ export function watchFile(
3620
+ filename: PathLike,
3621
+ options:
3622
+ | (WatchFileOptions & {
3623
+ bigint: true;
3624
+ })
3625
+ | undefined,
3626
+ listener: BigIntStatsListener,
3627
+ ): StatWatcher;
3628
+ /**
3629
+ * Watch for changes on `filename`. The callback `listener` will be called each time the file is accessed.
3630
+ * @param filename A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
3631
+ */
3632
+ export function watchFile(filename: PathLike, listener: StatsListener): StatWatcher;
3633
+ /**
3634
+ * Stop watching for changes on `filename`. If `listener` is specified, only that
3635
+ * particular listener is removed. Otherwise, _all_ listeners are removed,
3636
+ * effectively stopping watching of `filename`.
3637
+ *
3638
+ * Calling `fs.unwatchFile()` with a filename that is not being watched is a
3639
+ * no-op, not an error.
3640
+ *
3641
+ * 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.
3642
+ * @since v0.1.31
3643
+ * @param listener Optional, a listener previously attached using `fs.watchFile()`
3644
+ */
3645
+ export function unwatchFile(filename: PathLike, listener?: StatsListener): void;
3646
+ export function unwatchFile(filename: PathLike, listener?: BigIntStatsListener): void;
3647
+ type WatchIgnorePredicate = string | RegExp | ((filename: string) => boolean);
3648
+ export interface WatchOptions extends Abortable {
3649
+ encoding?: BufferEncoding | "buffer" | undefined;
3650
+ persistent?: boolean | undefined;
3651
+ recursive?: boolean | undefined;
3652
+ ignore?: WatchIgnorePredicate | readonly WatchIgnorePredicate[] | undefined;
3653
+ }
3654
+ export interface WatchOptionsWithBufferEncoding extends WatchOptions {
3655
+ encoding: "buffer";
3656
+ }
3657
+ export interface WatchOptionsWithStringEncoding extends WatchOptions {
3658
+ encoding?: BufferEncoding | undefined;
3659
+ }
3660
+ export type WatchEventType = "rename" | "change";
3661
+ export type WatchListener<T> = (event: WatchEventType, filename: T | null) => void;
3662
+ export type StatsListener = (curr: Stats, prev: Stats) => void;
3663
+ export type BigIntStatsListener = (curr: BigIntStats, prev: BigIntStats) => void;
3664
+ /**
3665
+ * Watch for changes on `filename`, where `filename` is either a file or a
3666
+ * directory.
3667
+ *
3668
+ * The second argument is optional. If `options` is provided as a string, it
3669
+ * specifies the `encoding`. Otherwise `options` should be passed as an object.
3670
+ *
3671
+ * The listener callback gets two arguments `(eventType, filename)`. `eventType`is either `'rename'` or `'change'`, and `filename` is the name of the file
3672
+ * which triggered the event.
3673
+ *
3674
+ * On most platforms, `'rename'` is emitted whenever a filename appears or
3675
+ * disappears in the directory.
3676
+ *
3677
+ * 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`.
3678
+ *
3679
+ * If a `signal` is passed, aborting the corresponding AbortController will close
3680
+ * the returned `fs.FSWatcher`.
3681
+ * @since v0.5.10
3682
+ * @param listener
3683
+ */
3684
+ export function watch(
3685
+ filename: PathLike,
3686
+ options?: WatchOptionsWithStringEncoding | BufferEncoding | null,
3687
+ listener?: WatchListener<string>,
3688
+ ): FSWatcher;
3689
+ export function watch(
3690
+ filename: PathLike,
3691
+ options: WatchOptionsWithBufferEncoding | "buffer",
3692
+ listener: WatchListener<NonSharedBuffer>,
3693
+ ): FSWatcher;
3694
+ export function watch(
3695
+ filename: PathLike,
3696
+ options: WatchOptions | BufferEncoding | "buffer" | null,
3697
+ listener: WatchListener<string | NonSharedBuffer>,
3698
+ ): FSWatcher;
3699
+ export function watch(filename: PathLike, listener: WatchListener<string>): FSWatcher;
3700
+ /**
3701
+ * Test whether or not the given path exists by checking with the file system.
3702
+ * Then call the `callback` argument with either true or false:
3703
+ *
3704
+ * ```js
3705
+ * import { exists } from 'node:fs';
3706
+ *
3707
+ * exists('/etc/passwd', (e) => {
3708
+ * console.log(e ? 'it exists' : 'no passwd!');
3709
+ * });
3710
+ * ```
3711
+ *
3712
+ * **The parameters for this callback are not consistent with other Node.js**
3713
+ * **callbacks.** Normally, the first parameter to a Node.js callback is an `err` parameter, optionally followed by other parameters. The `fs.exists()` callback
3714
+ * has only one boolean parameter. This is one reason `fs.access()` is recommended
3715
+ * instead of `fs.exists()`.
3716
+ *
3717
+ * Using `fs.exists()` to check for the existence of a file before calling `fs.open()`, `fs.readFile()`, or `fs.writeFile()` is not recommended. Doing
3718
+ * so introduces a race condition, since other processes may change the file's
3719
+ * state between the two calls. Instead, user code should open/read/write the
3720
+ * file directly and handle the error raised if the file does not exist.
3721
+ *
3722
+ * **write (NOT RECOMMENDED)**
3723
+ *
3724
+ * ```js
3725
+ * import { exists, open, close } from 'node:fs';
3726
+ *
3727
+ * exists('myfile', (e) => {
3728
+ * if (e) {
3729
+ * console.error('myfile already exists');
3730
+ * } else {
3731
+ * open('myfile', 'wx', (err, fd) => {
3732
+ * if (err) throw err;
3733
+ *
3734
+ * try {
3735
+ * writeMyData(fd);
3736
+ * } finally {
3737
+ * close(fd, (err) => {
3738
+ * if (err) throw err;
3739
+ * });
3740
+ * }
3741
+ * });
3742
+ * }
3743
+ * });
3744
+ * ```
3745
+ *
3746
+ * **write (RECOMMENDED)**
3747
+ *
3748
+ * ```js
3749
+ * import { open, close } from 'node:fs';
3750
+ * open('myfile', 'wx', (err, fd) => {
3751
+ * if (err) {
3752
+ * if (err.code === 'EEXIST') {
3753
+ * console.error('myfile already exists');
3754
+ * return;
3755
+ * }
3756
+ *
3757
+ * throw err;
3758
+ * }
3759
+ *
3760
+ * try {
3761
+ * writeMyData(fd);
3762
+ * } finally {
3763
+ * close(fd, (err) => {
3764
+ * if (err) throw err;
3765
+ * });
3766
+ * }
3767
+ * });
3768
+ * ```
3769
+ *
3770
+ * **read (NOT RECOMMENDED)**
3771
+ *
3772
+ * ```js
3773
+ * import { open, close, exists } from 'node:fs';
3774
+ *
3775
+ * exists('myfile', (e) => {
3776
+ * if (e) {
3777
+ * open('myfile', 'r', (err, fd) => {
3778
+ * if (err) throw err;
3779
+ *
3780
+ * try {
3781
+ * readMyData(fd);
3782
+ * } finally {
3783
+ * close(fd, (err) => {
3784
+ * if (err) throw err;
3785
+ * });
3786
+ * }
3787
+ * });
3788
+ * } else {
3789
+ * console.error('myfile does not exist');
3790
+ * }
3791
+ * });
3792
+ * ```
3793
+ *
3794
+ * **read (RECOMMENDED)**
3795
+ *
3796
+ * ```js
3797
+ * import { open, close } from 'node:fs';
3798
+ *
3799
+ * open('myfile', 'r', (err, fd) => {
3800
+ * if (err) {
3801
+ * if (err.code === 'ENOENT') {
3802
+ * console.error('myfile does not exist');
3803
+ * return;
3804
+ * }
3805
+ *
3806
+ * throw err;
3807
+ * }
3808
+ *
3809
+ * try {
3810
+ * readMyData(fd);
3811
+ * } finally {
3812
+ * close(fd, (err) => {
3813
+ * if (err) throw err;
3814
+ * });
3815
+ * }
3816
+ * });
3817
+ * ```
3818
+ *
3819
+ * The "not recommended" examples above check for existence and then use the
3820
+ * file; the "recommended" examples are better because they use the file directly
3821
+ * and handle the error, if any.
3822
+ *
3823
+ * In general, check for the existence of a file only if the file won't be
3824
+ * used directly, for example when its existence is a signal from another
3825
+ * process.
3826
+ * @since v0.0.2
3827
+ * @deprecated Since v1.0.0 - Use {@link stat} or {@link access} instead.
3828
+ */
3829
+ export function exists(path: PathLike, callback: (exists: boolean) => void): void;
3830
+ /** @deprecated */
3831
+ export namespace exists {
3832
+ /**
3833
+ * @param path A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
3834
+ * URL support is _experimental_.
3835
+ */
3836
+ function __promisify__(path: PathLike): Promise<boolean>;
3837
+ }
3838
+ /**
3839
+ * Returns `true` if the path exists, `false` otherwise.
3840
+ *
3841
+ * For detailed information, see the documentation of the asynchronous version of
3842
+ * this API: {@link exists}.
3843
+ *
3844
+ * `fs.exists()` is deprecated, but `fs.existsSync()` is not. The `callback` parameter to `fs.exists()` accepts parameters that are inconsistent with other
3845
+ * Node.js callbacks. `fs.existsSync()` does not use a callback.
3846
+ *
3847
+ * ```js
3848
+ * import { existsSync } from 'node:fs';
3849
+ *
3850
+ * if (existsSync('/etc/passwd'))
3851
+ * console.log('The path exists.');
3852
+ * ```
3853
+ * @since v0.1.21
3854
+ */
3855
+ export function existsSync(path: PathLike): boolean;
3856
+ export namespace constants {
3857
+ // File Access Constants
3858
+ /** Constant for fs.access(). File is visible to the calling process. */
3859
+ const F_OK: number;
3860
+ /** Constant for fs.access(). File can be read by the calling process. */
3861
+ const R_OK: number;
3862
+ /** Constant for fs.access(). File can be written by the calling process. */
3863
+ const W_OK: number;
3864
+ /** Constant for fs.access(). File can be executed by the calling process. */
3865
+ const X_OK: number;
3866
+ // File Copy Constants
3867
+ /** Constant for fs.copyFile. Flag indicating the destination file should not be overwritten if it already exists. */
3868
+ const COPYFILE_EXCL: number;
3869
+ /**
3870
+ * Constant for fs.copyFile. copy operation will attempt to create a copy-on-write reflink.
3871
+ * If the underlying platform does not support copy-on-write, then a fallback copy mechanism is used.
3872
+ */
3873
+ const COPYFILE_FICLONE: number;
3874
+ /**
3875
+ * Constant for fs.copyFile. Copy operation will attempt to create a copy-on-write reflink.
3876
+ * If the underlying platform does not support copy-on-write, then the operation will fail with an error.
3877
+ */
3878
+ const COPYFILE_FICLONE_FORCE: number;
3879
+ // File Open Constants
3880
+ /** Constant for fs.open(). Flag indicating to open a file for read-only access. */
3881
+ const O_RDONLY: number;
3882
+ /** Constant for fs.open(). Flag indicating to open a file for write-only access. */
3883
+ const O_WRONLY: number;
3884
+ /** Constant for fs.open(). Flag indicating to open a file for read-write access. */
3885
+ const O_RDWR: number;
3886
+ /** Constant for fs.open(). Flag indicating to create the file if it does not already exist. */
3887
+ const O_CREAT: number;
3888
+ /** Constant for fs.open(). Flag indicating that opening a file should fail if the O_CREAT flag is set and the file already exists. */
3889
+ const O_EXCL: number;
3890
+ /**
3891
+ * Constant for fs.open(). Flag indicating that if path identifies a terminal device,
3892
+ * opening the path shall not cause that terminal to become the controlling terminal for the process
3893
+ * (if the process does not already have one).
3894
+ */
3895
+ const O_NOCTTY: number;
3896
+ /** Constant for fs.open(). Flag indicating that if the file exists and is a regular file, and the file is opened successfully for write access, its length shall be truncated to zero. */
3897
+ const O_TRUNC: number;
3898
+ /** Constant for fs.open(). Flag indicating that data will be appended to the end of the file. */
3899
+ const O_APPEND: number;
3900
+ /** Constant for fs.open(). Flag indicating that the open should fail if the path is not a directory. */
3901
+ const O_DIRECTORY: number;
3902
+ /**
3903
+ * constant for fs.open().
3904
+ * Flag indicating reading accesses to the file system will no longer result in
3905
+ * an update to the atime information associated with the file.
3906
+ * This flag is available on Linux operating systems only.
3907
+ */
3908
+ const O_NOATIME: number;
3909
+ /** Constant for fs.open(). Flag indicating that the open should fail if the path is a symbolic link. */
3910
+ const O_NOFOLLOW: number;
3911
+ /** Constant for fs.open(). Flag indicating that the file is opened for synchronous I/O. */
3912
+ const O_SYNC: number;
3913
+ /** Constant for fs.open(). Flag indicating that the file is opened for synchronous I/O with write operations waiting for data integrity. */
3914
+ const O_DSYNC: number;
3915
+ /** Constant for fs.open(). Flag indicating to open the symbolic link itself rather than the resource it is pointing to. */
3916
+ const O_SYMLINK: number;
3917
+ /** Constant for fs.open(). When set, an attempt will be made to minimize caching effects of file I/O. */
3918
+ const O_DIRECT: number;
3919
+ /** Constant for fs.open(). Flag indicating to open the file in nonblocking mode when possible. */
3920
+ const O_NONBLOCK: number;
3921
+ // File Type Constants
3922
+ /** Constant for fs.Stats mode property for determining a file's type. Bit mask used to extract the file type code. */
3923
+ const S_IFMT: number;
3924
+ /** Constant for fs.Stats mode property for determining a file's type. File type constant for a regular file. */
3925
+ const S_IFREG: number;
3926
+ /** Constant for fs.Stats mode property for determining a file's type. File type constant for a directory. */
3927
+ const S_IFDIR: number;
3928
+ /** Constant for fs.Stats mode property for determining a file's type. File type constant for a character-oriented device file. */
3929
+ const S_IFCHR: number;
3930
+ /** Constant for fs.Stats mode property for determining a file's type. File type constant for a block-oriented device file. */
3931
+ const S_IFBLK: number;
3932
+ /** Constant for fs.Stats mode property for determining a file's type. File type constant for a FIFO/pipe. */
3933
+ const S_IFIFO: number;
3934
+ /** Constant for fs.Stats mode property for determining a file's type. File type constant for a symbolic link. */
3935
+ const S_IFLNK: number;
3936
+ /** Constant for fs.Stats mode property for determining a file's type. File type constant for a socket. */
3937
+ const S_IFSOCK: number;
3938
+ // File Mode Constants
3939
+ /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating readable, writable and executable by owner. */
3940
+ const S_IRWXU: number;
3941
+ /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating readable by owner. */
3942
+ const S_IRUSR: number;
3943
+ /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating writable by owner. */
3944
+ const S_IWUSR: number;
3945
+ /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating executable by owner. */
3946
+ const S_IXUSR: number;
3947
+ /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating readable, writable and executable by group. */
3948
+ const S_IRWXG: number;
3949
+ /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating readable by group. */
3950
+ const S_IRGRP: number;
3951
+ /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating writable by group. */
3952
+ const S_IWGRP: number;
3953
+ /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating executable by group. */
3954
+ const S_IXGRP: number;
3955
+ /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating readable, writable and executable by others. */
3956
+ const S_IRWXO: number;
3957
+ /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating readable by others. */
3958
+ const S_IROTH: number;
3959
+ /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating writable by others. */
3960
+ const S_IWOTH: number;
3961
+ /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating executable by others. */
3962
+ const S_IXOTH: number;
3963
+ /**
3964
+ * When set, a memory file mapping is used to access the file. This flag
3965
+ * is available on Windows operating systems only. On other operating systems,
3966
+ * this flag is ignored.
3967
+ */
3968
+ const UV_FS_O_FILEMAP: number;
3969
+ }
3970
+ /**
3971
+ * Tests a user's permissions for the file or directory specified by `path`.
3972
+ * The `mode` argument is an optional integer that specifies the accessibility
3973
+ * 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`
3974
+ * (e.g.`fs.constants.W_OK | fs.constants.R_OK`). Check `File access constants` for
3975
+ * possible values of `mode`.
3976
+ *
3977
+ * The final argument, `callback`, is a callback function that is invoked with
3978
+ * a possible error argument. If any of the accessibility checks fail, the error
3979
+ * argument will be an `Error` object. The following examples check if `package.json` exists, and if it is readable or writable.
3980
+ *
3981
+ * ```js
3982
+ * import { access, constants } from 'node:fs';
3983
+ *
3984
+ * const file = 'package.json';
3985
+ *
3986
+ * // Check if the file exists in the current directory.
3987
+ * access(file, constants.F_OK, (err) => {
3988
+ * console.log(`${file} ${err ? 'does not exist' : 'exists'}`);
3989
+ * });
3990
+ *
3991
+ * // Check if the file is readable.
3992
+ * access(file, constants.R_OK, (err) => {
3993
+ * console.log(`${file} ${err ? 'is not readable' : 'is readable'}`);
3994
+ * });
3995
+ *
3996
+ * // Check if the file is writable.
3997
+ * access(file, constants.W_OK, (err) => {
3998
+ * console.log(`${file} ${err ? 'is not writable' : 'is writable'}`);
3999
+ * });
4000
+ *
4001
+ * // Check if the file is readable and writable.
4002
+ * access(file, constants.R_OK | constants.W_OK, (err) => {
4003
+ * console.log(`${file} ${err ? 'is not' : 'is'} readable and writable`);
4004
+ * });
4005
+ * ```
4006
+ *
4007
+ * Do not use `fs.access()` to check for the accessibility of a file before calling `fs.open()`, `fs.readFile()`, or `fs.writeFile()`. Doing
4008
+ * so introduces a race condition, since other processes may change the file's
4009
+ * state between the two calls. Instead, user code should open/read/write the
4010
+ * file directly and handle the error raised if the file is not accessible.
4011
+ *
4012
+ * **write (NOT RECOMMENDED)**
4013
+ *
4014
+ * ```js
4015
+ * import { access, open, close } from 'node:fs';
4016
+ *
4017
+ * access('myfile', (err) => {
4018
+ * if (!err) {
4019
+ * console.error('myfile already exists');
4020
+ * return;
4021
+ * }
4022
+ *
4023
+ * open('myfile', 'wx', (err, fd) => {
4024
+ * if (err) throw err;
4025
+ *
4026
+ * try {
4027
+ * writeMyData(fd);
4028
+ * } finally {
4029
+ * close(fd, (err) => {
4030
+ * if (err) throw err;
4031
+ * });
4032
+ * }
4033
+ * });
4034
+ * });
4035
+ * ```
4036
+ *
4037
+ * **write (RECOMMENDED)**
4038
+ *
4039
+ * ```js
4040
+ * import { open, close } from 'node:fs';
4041
+ *
4042
+ * open('myfile', 'wx', (err, fd) => {
4043
+ * if (err) {
4044
+ * if (err.code === 'EEXIST') {
4045
+ * console.error('myfile already exists');
4046
+ * return;
4047
+ * }
4048
+ *
4049
+ * throw err;
4050
+ * }
4051
+ *
4052
+ * try {
4053
+ * writeMyData(fd);
4054
+ * } finally {
4055
+ * close(fd, (err) => {
4056
+ * if (err) throw err;
4057
+ * });
4058
+ * }
4059
+ * });
4060
+ * ```
4061
+ *
4062
+ * **read (NOT RECOMMENDED)**
4063
+ *
4064
+ * ```js
4065
+ * import { access, open, close } from 'node:fs';
4066
+ * access('myfile', (err) => {
4067
+ * if (err) {
4068
+ * if (err.code === 'ENOENT') {
4069
+ * console.error('myfile does not exist');
4070
+ * return;
4071
+ * }
4072
+ *
4073
+ * throw err;
4074
+ * }
4075
+ *
4076
+ * open('myfile', 'r', (err, fd) => {
4077
+ * if (err) throw err;
4078
+ *
4079
+ * try {
4080
+ * readMyData(fd);
4081
+ * } finally {
4082
+ * close(fd, (err) => {
4083
+ * if (err) throw err;
4084
+ * });
4085
+ * }
4086
+ * });
4087
+ * });
4088
+ * ```
4089
+ *
4090
+ * **read (RECOMMENDED)**
4091
+ *
4092
+ * ```js
4093
+ * import { open, close } from 'node:fs';
4094
+ *
4095
+ * open('myfile', 'r', (err, fd) => {
4096
+ * if (err) {
4097
+ * if (err.code === 'ENOENT') {
4098
+ * console.error('myfile does not exist');
4099
+ * return;
4100
+ * }
4101
+ *
4102
+ * throw err;
4103
+ * }
4104
+ *
4105
+ * try {
4106
+ * readMyData(fd);
4107
+ * } finally {
4108
+ * close(fd, (err) => {
4109
+ * if (err) throw err;
4110
+ * });
4111
+ * }
4112
+ * });
4113
+ * ```
4114
+ *
4115
+ * The "not recommended" examples above check for accessibility and then use the
4116
+ * file; the "recommended" examples are better because they use the file directly
4117
+ * and handle the error, if any.
4118
+ *
4119
+ * In general, check for the accessibility of a file only if the file will not be
4120
+ * used directly, for example when its accessibility is a signal from another
4121
+ * process.
4122
+ *
4123
+ * On Windows, access-control policies (ACLs) on a directory may limit access to
4124
+ * a file or directory. The `fs.access()` function, however, does not check the
4125
+ * ACL and therefore may report that a path is accessible even if the ACL restricts
4126
+ * the user from reading or writing to it.
4127
+ * @since v0.11.15
4128
+ * @param [mode=fs.constants.F_OK]
4129
+ */
4130
+ export function access(path: PathLike, mode: number | undefined, callback: NoParamCallback): void;
4131
+ /**
4132
+ * Asynchronously tests a user's permissions for the file specified by path.
4133
+ * @param path A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
4134
+ */
4135
+ export function access(path: PathLike, callback: NoParamCallback): void;
4136
+ export namespace access {
4137
+ /**
4138
+ * Asynchronously tests a user's permissions for the file specified by path.
4139
+ * @param path A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
4140
+ * URL support is _experimental_.
4141
+ */
4142
+ function __promisify__(path: PathLike, mode?: number): Promise<void>;
4143
+ }
4144
+ /**
4145
+ * Synchronously tests a user's permissions for the file or directory specified
4146
+ * by `path`. The `mode` argument is an optional integer that specifies the
4147
+ * 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
4148
+ * `fs.constants.X_OK` (e.g.`fs.constants.W_OK | fs.constants.R_OK`). Check `File access constants` for
4149
+ * possible values of `mode`.
4150
+ *
4151
+ * If any of the accessibility checks fail, an `Error` will be thrown. Otherwise,
4152
+ * the method will return `undefined`.
4153
+ *
4154
+ * ```js
4155
+ * import { accessSync, constants } from 'node:fs';
4156
+ *
4157
+ * try {
4158
+ * accessSync('etc/passwd', constants.R_OK | constants.W_OK);
4159
+ * console.log('can read/write');
4160
+ * } catch (err) {
4161
+ * console.error('no access!');
4162
+ * }
4163
+ * ```
4164
+ * @since v0.11.15
4165
+ * @param [mode=fs.constants.F_OK]
4166
+ */
4167
+ export function accessSync(path: PathLike, mode?: number): void;
4168
+ interface StreamOptions {
4169
+ flags?: string | undefined;
4170
+ encoding?: BufferEncoding | undefined;
4171
+ fd?: number | promises.FileHandle | undefined;
4172
+ mode?: number | undefined;
4173
+ autoClose?: boolean | undefined;
4174
+ emitClose?: boolean | undefined;
4175
+ start?: number | undefined;
4176
+ signal?: AbortSignal | null | undefined;
4177
+ highWaterMark?: number | undefined;
4178
+ }
4179
+ interface FSImplementation {
4180
+ open?: (...args: any[]) => any;
4181
+ close?: (...args: any[]) => any;
4182
+ }
4183
+ interface CreateReadStreamFSImplementation extends FSImplementation {
4184
+ read: (...args: any[]) => any;
4185
+ }
4186
+ interface CreateWriteStreamFSImplementation extends FSImplementation {
4187
+ write: (...args: any[]) => any;
4188
+ writev?: (...args: any[]) => any;
4189
+ }
4190
+ interface ReadStreamOptions extends StreamOptions {
4191
+ fs?: CreateReadStreamFSImplementation | null | undefined;
4192
+ end?: number | undefined;
4193
+ }
4194
+ interface WriteStreamOptions extends StreamOptions {
4195
+ fs?: CreateWriteStreamFSImplementation | null | undefined;
4196
+ flush?: boolean | undefined;
4197
+ }
4198
+ /**
4199
+ * `options` can include `start` and `end` values to read a range of bytes from
4200
+ * the file instead of the entire file. Both `start` and `end` are inclusive and
4201
+ * start counting at 0, allowed values are in the
4202
+ * \[0, [`Number.MAX_SAFE_INTEGER`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER)\] range. If `fd` is specified and `start` is
4203
+ * omitted or `undefined`, `fs.createReadStream()` reads sequentially from the
4204
+ * current file position. The `encoding` can be any one of those accepted by `Buffer`.
4205
+ *
4206
+ * If `fd` is specified, `ReadStream` will ignore the `path` argument and will use
4207
+ * the specified file descriptor. This means that no `'open'` event will be
4208
+ * emitted. `fd` should be blocking; non-blocking `fd`s should be passed to `net.Socket`.
4209
+ *
4210
+ * If `fd` points to a character device that only supports blocking reads
4211
+ * (such as keyboard or sound card), read operations do not finish until data is
4212
+ * available. This can prevent the process from exiting and the stream from
4213
+ * closing naturally.
4214
+ *
4215
+ * By default, the stream will emit a `'close'` event after it has been
4216
+ * destroyed. Set the `emitClose` option to `false` to change this behavior.
4217
+ *
4218
+ * By providing the `fs` option, it is possible to override the corresponding `fs` implementations for `open`, `read`, and `close`. When providing the `fs` option,
4219
+ * 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
4220
+ * also required.
4221
+ *
4222
+ * ```js
4223
+ * import { createReadStream } from 'node:fs';
4224
+ *
4225
+ * // Create a stream from some character device.
4226
+ * const stream = createReadStream('/dev/input/event0');
4227
+ * setTimeout(() => {
4228
+ * stream.close(); // This may not close the stream.
4229
+ * // Artificially marking end-of-stream, as if the underlying resource had
4230
+ * // indicated end-of-file by itself, allows the stream to close.
4231
+ * // This does not cancel pending read operations, and if there is such an
4232
+ * // operation, the process may still not be able to exit successfully
4233
+ * // until it finishes.
4234
+ * stream.push(null);
4235
+ * stream.read(0);
4236
+ * }, 100);
4237
+ * ```
4238
+ *
4239
+ * If `autoClose` is false, then the file descriptor won't be closed, even if
4240
+ * there's an error. It is the application's responsibility to close it and make
4241
+ * sure there's no file descriptor leak. If `autoClose` is set to true (default
4242
+ * behavior), on `'error'` or `'end'` the file descriptor will be closed
4243
+ * automatically.
4244
+ *
4245
+ * `mode` sets the file mode (permission and sticky bits), but only if the
4246
+ * file was created.
4247
+ *
4248
+ * An example to read the last 10 bytes of a file which is 100 bytes long:
4249
+ *
4250
+ * ```js
4251
+ * import { createReadStream } from 'node:fs';
4252
+ *
4253
+ * createReadStream('sample.txt', { start: 90, end: 99 });
4254
+ * ```
4255
+ *
4256
+ * If `options` is a string, then it specifies the encoding.
4257
+ * @since v0.1.31
4258
+ */
4259
+ export function createReadStream(path: PathLike, options?: BufferEncoding | ReadStreamOptions): ReadStream;
4260
+ /**
4261
+ * `options` may also include a `start` option to allow writing data at some
4262
+ * position past the beginning of the file, allowed values are in the
4263
+ * \[0, [`Number.MAX_SAFE_INTEGER`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER)\] range. Modifying a file rather than
4264
+ * replacing it may require the `flags` option to be set to `r+` rather than the
4265
+ * default `w`. The `encoding` can be any one of those accepted by `Buffer`.
4266
+ *
4267
+ * If `autoClose` is set to true (default behavior) on `'error'` or `'finish'` the file descriptor will be closed automatically. If `autoClose` is false,
4268
+ * then the file descriptor won't be closed, even if there's an error.
4269
+ * It is the application's responsibility to close it and make sure there's no
4270
+ * file descriptor leak.
4271
+ *
4272
+ * By default, the stream will emit a `'close'` event after it has been
4273
+ * destroyed. Set the `emitClose` option to `false` to change this behavior.
4274
+ *
4275
+ * 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
4276
+ * performance as some optimizations (`_writev()`)
4277
+ * 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
4278
+ * for `open` is also required. If `autoClose` is `true`, an override for `close` is also required.
4279
+ *
4280
+ * 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
4281
+ * emitted. `fd` should be blocking; non-blocking `fd`s
4282
+ * should be passed to `net.Socket`.
4283
+ *
4284
+ * If `options` is a string, then it specifies the encoding.
4285
+ * @since v0.1.31
4286
+ */
4287
+ export function createWriteStream(path: PathLike, options?: BufferEncoding | WriteStreamOptions): WriteStream;
4288
+ /**
4289
+ * Forces all currently queued I/O operations associated with the file to the
4290
+ * operating system's synchronized I/O completion state. Refer to the POSIX [`fdatasync(2)`](http://man7.org/linux/man-pages/man2/fdatasync.2.html) documentation for details. No arguments other
4291
+ * than a possible
4292
+ * exception are given to the completion callback.
4293
+ * @since v0.1.96
4294
+ */
4295
+ export function fdatasync(fd: number, callback: NoParamCallback): void;
4296
+ export namespace fdatasync {
4297
+ /**
4298
+ * Asynchronous fdatasync(2) - synchronize a file's in-core state with storage device.
4299
+ * @param fd A file descriptor.
4300
+ */
4301
+ function __promisify__(fd: number): Promise<void>;
4302
+ }
4303
+ /**
4304
+ * Forces all currently queued I/O operations associated with the file to the
4305
+ * operating system's synchronized I/O completion state. Refer to the POSIX [`fdatasync(2)`](http://man7.org/linux/man-pages/man2/fdatasync.2.html) documentation for details. Returns `undefined`.
4306
+ * @since v0.1.96
4307
+ */
4308
+ export function fdatasyncSync(fd: number): void;
4309
+ /**
4310
+ * Asynchronously copies `src` to `dest`. By default, `dest` is overwritten if it
4311
+ * already exists. No arguments other than a possible exception are given to the
4312
+ * callback function. Node.js makes no guarantees about the atomicity of the copy
4313
+ * operation. If an error occurs after the destination file has been opened for
4314
+ * writing, Node.js will attempt to remove the destination.
4315
+ *
4316
+ * `mode` is an optional integer that specifies the behavior
4317
+ * of the copy operation. It is possible to create a mask consisting of the bitwise
4318
+ * OR of two or more values (e.g.`fs.constants.COPYFILE_EXCL | fs.constants.COPYFILE_FICLONE`).
4319
+ *
4320
+ * * `fs.constants.COPYFILE_EXCL`: The copy operation will fail if `dest` already
4321
+ * exists.
4322
+ * * `fs.constants.COPYFILE_FICLONE`: The copy operation will attempt to create a
4323
+ * copy-on-write reflink. If the platform does not support copy-on-write, then a
4324
+ * fallback copy mechanism is used.
4325
+ * * `fs.constants.COPYFILE_FICLONE_FORCE`: The copy operation will attempt to
4326
+ * create a copy-on-write reflink. If the platform does not support
4327
+ * copy-on-write, then the operation will fail.
4328
+ *
4329
+ * ```js
4330
+ * import { copyFile, constants } from 'node:fs';
4331
+ *
4332
+ * function callback(err) {
4333
+ * if (err) throw err;
4334
+ * console.log('source.txt was copied to destination.txt');
4335
+ * }
4336
+ *
4337
+ * // destination.txt will be created or overwritten by default.
4338
+ * copyFile('source.txt', 'destination.txt', callback);
4339
+ *
4340
+ * // By using COPYFILE_EXCL, the operation will fail if destination.txt exists.
4341
+ * copyFile('source.txt', 'destination.txt', constants.COPYFILE_EXCL, callback);
4342
+ * ```
4343
+ * @since v8.5.0
4344
+ * @param src source filename to copy
4345
+ * @param dest destination filename of the copy operation
4346
+ * @param [mode=0] modifiers for copy operation.
4347
+ */
4348
+ export function copyFile(src: PathLike, dest: PathLike, callback: NoParamCallback): void;
4349
+ export function copyFile(src: PathLike, dest: PathLike, mode: number, callback: NoParamCallback): void;
4350
+ export namespace copyFile {
4351
+ function __promisify__(src: PathLike, dst: PathLike, mode?: number): Promise<void>;
4352
+ }
4353
+ /**
4354
+ * Synchronously copies `src` to `dest`. By default, `dest` is overwritten if it
4355
+ * already exists. Returns `undefined`. Node.js makes no guarantees about the
4356
+ * atomicity of the copy operation. If an error occurs after the destination file
4357
+ * has been opened for writing, Node.js will attempt to remove the destination.
4358
+ *
4359
+ * `mode` is an optional integer that specifies the behavior
4360
+ * of the copy operation. It is possible to create a mask consisting of the bitwise
4361
+ * OR of two or more values (e.g.`fs.constants.COPYFILE_EXCL | fs.constants.COPYFILE_FICLONE`).
4362
+ *
4363
+ * * `fs.constants.COPYFILE_EXCL`: The copy operation will fail if `dest` already
4364
+ * exists.
4365
+ * * `fs.constants.COPYFILE_FICLONE`: The copy operation will attempt to create a
4366
+ * copy-on-write reflink. If the platform does not support copy-on-write, then a
4367
+ * fallback copy mechanism is used.
4368
+ * * `fs.constants.COPYFILE_FICLONE_FORCE`: The copy operation will attempt to
4369
+ * create a copy-on-write reflink. If the platform does not support
4370
+ * copy-on-write, then the operation will fail.
4371
+ *
4372
+ * ```js
4373
+ * import { copyFileSync, constants } from 'node:fs';
4374
+ *
4375
+ * // destination.txt will be created or overwritten by default.
4376
+ * copyFileSync('source.txt', 'destination.txt');
4377
+ * console.log('source.txt was copied to destination.txt');
4378
+ *
4379
+ * // By using COPYFILE_EXCL, the operation will fail if destination.txt exists.
4380
+ * copyFileSync('source.txt', 'destination.txt', constants.COPYFILE_EXCL);
4381
+ * ```
4382
+ * @since v8.5.0
4383
+ * @param src source filename to copy
4384
+ * @param dest destination filename of the copy operation
4385
+ * @param [mode=0] modifiers for copy operation.
4386
+ */
4387
+ export function copyFileSync(src: PathLike, dest: PathLike, mode?: number): void;
4388
+ /**
4389
+ * Write an array of `ArrayBufferView`s to the file specified by `fd` using `writev()`.
4390
+ *
4391
+ * `position` is the offset from the beginning of the file where this data
4392
+ * should be written. If `typeof position !== 'number'`, the data will be written
4393
+ * at the current position.
4394
+ *
4395
+ * The callback will be given three arguments: `err`, `bytesWritten`, and `buffers`. `bytesWritten` is how many bytes were written from `buffers`.
4396
+ *
4397
+ * If this method is `util.promisify()` ed, it returns a promise for an `Object` with `bytesWritten` and `buffers` properties.
4398
+ *
4399
+ * It is unsafe to use `fs.writev()` multiple times on the same file without
4400
+ * waiting for the callback. For this scenario, use {@link createWriteStream}.
4401
+ *
4402
+ * On Linux, positional writes don't work when the file is opened in append mode.
4403
+ * The kernel ignores the position argument and always appends the data to
4404
+ * the end of the file.
4405
+ * @since v12.9.0
4406
+ * @param [position='null']
4407
+ */
4408
+ export function writev<TBuffers extends readonly NodeJS.ArrayBufferView[]>(
4409
+ fd: number,
4410
+ buffers: TBuffers,
4411
+ cb: (err: NodeJS.ErrnoException | null, bytesWritten: number, buffers: TBuffers) => void,
4412
+ ): void;
4413
+ export function writev<TBuffers extends readonly NodeJS.ArrayBufferView[]>(
4414
+ fd: number,
4415
+ buffers: TBuffers,
4416
+ position: number | null,
4417
+ cb: (err: NodeJS.ErrnoException | null, bytesWritten: number, buffers: TBuffers) => void,
4418
+ ): void;
4419
+ // Providing a default type parameter doesn't provide true BC for userland consumers, but at least suppresses TS2314
4420
+ // TODO: remove default in future major version
4421
+ export interface WriteVResult<T extends readonly NodeJS.ArrayBufferView[] = NodeJS.ArrayBufferView[]> {
4422
+ bytesWritten: number;
4423
+ buffers: T;
4424
+ }
4425
+ export namespace writev {
4426
+ function __promisify__<TBuffers extends readonly NodeJS.ArrayBufferView[]>(
4427
+ fd: number,
4428
+ buffers: TBuffers,
4429
+ position?: number,
4430
+ ): Promise<WriteVResult<TBuffers>>;
4431
+ }
4432
+ /**
4433
+ * For detailed information, see the documentation of the asynchronous version of
4434
+ * this API: {@link writev}.
4435
+ * @since v12.9.0
4436
+ * @param [position='null']
4437
+ * @return The number of bytes written.
4438
+ */
4439
+ export function writevSync(fd: number, buffers: readonly NodeJS.ArrayBufferView[], position?: number): number;
4440
+ /**
4441
+ * Read from a file specified by `fd` and write to an array of `ArrayBufferView`s
4442
+ * using `readv()`.
4443
+ *
4444
+ * `position` is the offset from the beginning of the file from where data
4445
+ * should be read. If `typeof position !== 'number'`, the data will be read
4446
+ * from the current position.
4447
+ *
4448
+ * The callback will be given three arguments: `err`, `bytesRead`, and `buffers`. `bytesRead` is how many bytes were read from the file.
4449
+ *
4450
+ * If this method is invoked as its `util.promisify()` ed version, it returns
4451
+ * a promise for an `Object` with `bytesRead` and `buffers` properties.
4452
+ * @since v13.13.0, v12.17.0
4453
+ * @param [position='null']
4454
+ */
4455
+ export function readv<TBuffers extends readonly NodeJS.ArrayBufferView[]>(
4456
+ fd: number,
4457
+ buffers: TBuffers,
4458
+ cb: (err: NodeJS.ErrnoException | null, bytesRead: number, buffers: TBuffers) => void,
4459
+ ): void;
4460
+ export function readv<TBuffers extends readonly NodeJS.ArrayBufferView[]>(
4461
+ fd: number,
4462
+ buffers: TBuffers,
4463
+ position: number | null,
4464
+ cb: (err: NodeJS.ErrnoException | null, bytesRead: number, buffers: TBuffers) => void,
4465
+ ): void;
4466
+ // Providing a default type parameter doesn't provide true BC for userland consumers, but at least suppresses TS2314
4467
+ // TODO: remove default in future major version
4468
+ export interface ReadVResult<T extends readonly NodeJS.ArrayBufferView[] = NodeJS.ArrayBufferView[]> {
4469
+ bytesRead: number;
4470
+ buffers: T;
4471
+ }
4472
+ export namespace readv {
4473
+ function __promisify__<TBuffers extends readonly NodeJS.ArrayBufferView[]>(
4474
+ fd: number,
4475
+ buffers: TBuffers,
4476
+ position?: number,
4477
+ ): Promise<ReadVResult<TBuffers>>;
4478
+ }
4479
+ /**
4480
+ * For detailed information, see the documentation of the asynchronous version of
4481
+ * this API: {@link readv}.
4482
+ * @since v13.13.0, v12.17.0
4483
+ * @param [position='null']
4484
+ * @return The number of bytes read.
4485
+ */
4486
+ export function readvSync(fd: number, buffers: readonly NodeJS.ArrayBufferView[], position?: number): number;
4487
+
4488
+ export interface OpenAsBlobOptions {
4489
+ /**
4490
+ * An optional mime type for the blob.
4491
+ *
4492
+ * @default 'undefined'
4493
+ */
4494
+ type?: string | undefined;
4495
+ }
4496
+
4497
+ /**
4498
+ * Returns a `Blob` whose data is backed by the given file.
4499
+ *
4500
+ * The file must not be modified after the `Blob` is created. Any modifications
4501
+ * will cause reading the `Blob` data to fail with a `DOMException` error.
4502
+ * Synchronous stat operations on the file when the `Blob` is created, and before
4503
+ * each read in order to detect whether the file data has been modified on disk.
4504
+ *
4505
+ * ```js
4506
+ * import { openAsBlob } from 'node:fs';
4507
+ *
4508
+ * const blob = await openAsBlob('the.file.txt');
4509
+ * const ab = await blob.arrayBuffer();
4510
+ * blob.stream();
4511
+ * ```
4512
+ * @since v19.8.0
4513
+ */
4514
+ export function openAsBlob(path: PathLike, options?: OpenAsBlobOptions): Promise<Blob>;
4515
+
4516
+ export interface OpenDirOptions {
4517
+ /**
4518
+ * @default 'utf8'
4519
+ */
4520
+ encoding?: BufferEncoding | undefined;
4521
+ /**
4522
+ * Number of directory entries that are buffered
4523
+ * internally when reading from the directory. Higher values lead to better
4524
+ * performance but higher memory usage.
4525
+ * @default 32
4526
+ */
4527
+ bufferSize?: number | undefined;
4528
+ /**
4529
+ * @default false
4530
+ */
4531
+ recursive?: boolean | undefined;
4532
+ }
4533
+ /**
4534
+ * Synchronously open a directory. See [`opendir(3)`](http://man7.org/linux/man-pages/man3/opendir.3.html).
4535
+ *
4536
+ * Creates an `fs.Dir`, which contains all further functions for reading from
4537
+ * and cleaning up the directory.
4538
+ *
4539
+ * The `encoding` option sets the encoding for the `path` while opening the
4540
+ * directory and subsequent read operations.
4541
+ * @since v12.12.0
4542
+ */
4543
+ export function opendirSync(path: PathLike, options?: OpenDirOptions): Dir;
4544
+ /**
4545
+ * Asynchronously open a directory. See the POSIX [`opendir(3)`](http://man7.org/linux/man-pages/man3/opendir.3.html) documentation for
4546
+ * more details.
4547
+ *
4548
+ * Creates an `fs.Dir`, which contains all further functions for reading from
4549
+ * and cleaning up the directory.
4550
+ *
4551
+ * The `encoding` option sets the encoding for the `path` while opening the
4552
+ * directory and subsequent read operations.
4553
+ * @since v12.12.0
4554
+ */
4555
+ export function opendir(path: PathLike, cb: (err: NodeJS.ErrnoException | null, dir: Dir) => void): void;
4556
+ export function opendir(
4557
+ path: PathLike,
4558
+ options: OpenDirOptions,
4559
+ cb: (err: NodeJS.ErrnoException | null, dir: Dir) => void,
4560
+ ): void;
4561
+ export namespace opendir {
4562
+ function __promisify__(path: PathLike, options?: OpenDirOptions): Promise<Dir>;
4563
+ }
4564
+ export interface BigIntStats extends StatsBase<bigint> {
4565
+ atimeNs: bigint;
4566
+ mtimeNs: bigint;
4567
+ ctimeNs: bigint;
4568
+ birthtimeNs: bigint;
4569
+ }
4570
+ export interface BigIntOptions {
4571
+ bigint: true;
4572
+ }
4573
+ export interface StatOptions {
4574
+ bigint?: boolean | undefined;
4575
+ throwIfNoEntry?: boolean | undefined;
4576
+ }
4577
+ export interface StatSyncOptions extends StatOptions {}
4578
+ interface CopyOptionsBase {
4579
+ /**
4580
+ * Dereference symlinks
4581
+ * @default false
4582
+ */
4583
+ dereference?: boolean | undefined;
4584
+ /**
4585
+ * When `force` is `false`, and the destination
4586
+ * exists, throw an error.
4587
+ * @default false
4588
+ */
4589
+ errorOnExist?: boolean | undefined;
4590
+ /**
4591
+ * Overwrite existing file or directory. _The copy
4592
+ * operation will ignore errors if you set this to false and the destination
4593
+ * exists. Use the `errorOnExist` option to change this behavior.
4594
+ * @default true
4595
+ */
4596
+ force?: boolean | undefined;
4597
+ /**
4598
+ * Modifiers for copy operation. See `mode` flag of {@link copyFileSync()}
4599
+ */
4600
+ mode?: number | undefined;
4601
+ /**
4602
+ * When `true` timestamps from `src` will
4603
+ * be preserved.
4604
+ * @default false
4605
+ */
4606
+ preserveTimestamps?: boolean | undefined;
4607
+ /**
4608
+ * Copy directories recursively.
4609
+ * @default false
4610
+ */
4611
+ recursive?: boolean | undefined;
4612
+ /**
4613
+ * When true, path resolution for symlinks will be skipped
4614
+ * @default false
4615
+ */
4616
+ verbatimSymlinks?: boolean | undefined;
4617
+ }
4618
+ export interface CopyOptions extends CopyOptionsBase {
4619
+ /**
4620
+ * Function to filter copied files/directories. Return
4621
+ * `true` to copy the item, `false` to ignore it.
4622
+ */
4623
+ filter?: ((source: string, destination: string) => boolean | Promise<boolean>) | undefined;
4624
+ }
4625
+ export interface CopySyncOptions extends CopyOptionsBase {
4626
+ /**
4627
+ * Function to filter copied files/directories. Return
4628
+ * `true` to copy the item, `false` to ignore it.
4629
+ */
4630
+ filter?: ((source: string, destination: string) => boolean) | undefined;
4631
+ }
4632
+ /**
4633
+ * Asynchronously copies the entire directory structure from `src` to `dest`,
4634
+ * including subdirectories and files.
4635
+ *
4636
+ * When copying a directory to another directory, globs are not supported and
4637
+ * behavior is similar to `cp dir1/ dir2/`.
4638
+ * @since v16.7.0
4639
+ * @experimental
4640
+ * @param src source path to copy.
4641
+ * @param dest destination path to copy to.
4642
+ */
4643
+ export function cp(
4644
+ source: string | URL,
4645
+ destination: string | URL,
4646
+ callback: (err: NodeJS.ErrnoException | null) => void,
4647
+ ): void;
4648
+ export function cp(
4649
+ source: string | URL,
4650
+ destination: string | URL,
4651
+ opts: CopyOptions,
4652
+ callback: (err: NodeJS.ErrnoException | null) => void,
4653
+ ): void;
4654
+ /**
4655
+ * Synchronously copies the entire directory structure from `src` to `dest`,
4656
+ * including subdirectories and files.
4657
+ *
4658
+ * When copying a directory to another directory, globs are not supported and
4659
+ * behavior is similar to `cp dir1/ dir2/`.
4660
+ * @since v16.7.0
4661
+ * @experimental
4662
+ * @param src source path to copy.
4663
+ * @param dest destination path to copy to.
4664
+ */
4665
+ export function cpSync(source: string | URL, destination: string | URL, opts?: CopySyncOptions): void;
4666
+
4667
+ // TODO: collapse
4668
+ interface _GlobOptions<T extends Dirent | string> {
4669
+ /**
4670
+ * Current working directory.
4671
+ * @default process.cwd()
4672
+ */
4673
+ cwd?: string | URL | undefined;
4674
+ /**
4675
+ * Function to filter out files/directories or a
4676
+ * list of glob patterns to be excluded. If a function is provided, return
4677
+ * `true` to exclude the item, `false` to include it.
4678
+ * If a string array is provided, each string should be a glob pattern that
4679
+ * specifies paths to exclude. Note: Negation patterns (e.g., '!foo.js') are
4680
+ * not supported.
4681
+ * @default undefined
4682
+ */
4683
+ exclude?: ((fileName: T) => boolean) | readonly string[] | undefined;
4684
+ /**
4685
+ * When `true`, symbolic links to directories are
4686
+ * followed while expanding `**` patterns.
4687
+ * @default false
4688
+ */
4689
+ followSymlinks?: boolean | undefined;
4690
+ /**
4691
+ * `true` if the glob should return paths as `Dirent`s, `false` otherwise.
4692
+ * @default false
4693
+ * @since v22.2.0
4694
+ */
4695
+ withFileTypes?: boolean | undefined;
4696
+ }
4697
+ export interface GlobOptions extends _GlobOptions<Dirent | string> {}
4698
+ export interface GlobOptionsWithFileTypes extends _GlobOptions<Dirent> {
4699
+ withFileTypes: true;
4700
+ }
4701
+ export interface GlobOptionsWithoutFileTypes extends _GlobOptions<string> {
4702
+ withFileTypes?: false | undefined;
4703
+ }
4704
+
4705
+ /**
4706
+ * Retrieves the files matching the specified pattern.
4707
+ *
4708
+ * When `followSymlinks` is enabled, detected symbolic link cycles are not
4709
+ * traversed recursively.
4710
+ *
4711
+ * ```js
4712
+ * import { glob } from 'node:fs';
4713
+ *
4714
+ * glob('*.js', (err, matches) => {
4715
+ * if (err) throw err;
4716
+ * console.log(matches);
4717
+ * });
4718
+ * ```
4719
+ * @since v22.0.0
4720
+ */
4721
+ export function glob(
4722
+ pattern: string | readonly string[],
4723
+ callback: (err: NodeJS.ErrnoException | null, matches: string[]) => void,
4724
+ ): void;
4725
+ export function glob(
4726
+ pattern: string | readonly string[],
4727
+ options: GlobOptionsWithFileTypes,
4728
+ callback: (
4729
+ err: NodeJS.ErrnoException | null,
4730
+ matches: Dirent[],
4731
+ ) => void,
4732
+ ): void;
4733
+ export function glob(
4734
+ pattern: string | readonly string[],
4735
+ options: GlobOptionsWithoutFileTypes,
4736
+ callback: (
4737
+ err: NodeJS.ErrnoException | null,
4738
+ matches: string[],
4739
+ ) => void,
4740
+ ): void;
4741
+ export function glob(
4742
+ pattern: string | readonly string[],
4743
+ options: GlobOptions,
4744
+ callback: (
4745
+ err: NodeJS.ErrnoException | null,
4746
+ matches: Dirent[] | string[],
4747
+ ) => void,
4748
+ ): void;
4749
+ /**
4750
+ * When `followSymlinks` is enabled, detected symbolic link cycles are not
4751
+ * traversed recursively.
4752
+ *
4753
+ * ```js
4754
+ * import { globSync } from 'node:fs';
4755
+ *
4756
+ * console.log(globSync('*.js'));
4757
+ * ```
4758
+ * @since v22.0.0
4759
+ * @returns paths of files that match the pattern.
4760
+ */
4761
+ export function globSync(pattern: string | readonly string[]): string[];
4762
+ export function globSync(
4763
+ pattern: string | readonly string[],
4764
+ options: GlobOptionsWithFileTypes,
4765
+ ): Dirent[];
4766
+ export function globSync(
4767
+ pattern: string | readonly string[],
4768
+ options: GlobOptionsWithoutFileTypes,
4769
+ ): string[];
4770
+ export function globSync(
4771
+ pattern: string | readonly string[],
4772
+ options: GlobOptions,
4773
+ ): Dirent[] | string[];
4774
+ }
4775
+ declare module "node:fs" {
4776
+ export * from "fs";
4777
+ }