@volter/tabnode 0.2.14-volter.88

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 (429) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +78 -0
  3. package/THIRD-PARTY-NOTICES.md +12 -0
  4. package/dist/__sw__.js +526 -0
  5. package/dist/assets/runtime-worker-4MKaHFVb.js +75221 -0
  6. package/dist/assets/runtime-worker-4MKaHFVb.js.map +1 -0
  7. package/dist/code-transforms.d.ts +21 -0
  8. package/dist/code-transforms.d.ts.map +1 -0
  9. package/dist/config/cdn.d.ts +12 -0
  10. package/dist/config/cdn.d.ts.map +1 -0
  11. package/dist/create-runtime.d.ts +22 -0
  12. package/dist/create-runtime.d.ts.map +1 -0
  13. package/dist/host-globals.d.ts +62 -0
  14. package/dist/host-globals.d.ts.map +1 -0
  15. package/dist/index.cjs +36021 -0
  16. package/dist/index.cjs.map +1 -0
  17. package/dist/index.d.ts +127 -0
  18. package/dist/index.d.ts.map +1 -0
  19. package/dist/index.mjs +36020 -0
  20. package/dist/index.mjs.map +1 -0
  21. package/dist/node-internals.d.ts +68 -0
  22. package/dist/node-internals.d.ts.map +1 -0
  23. package/dist/node-lib/binding/blob.d.ts +12 -0
  24. package/dist/node-lib/binding/blob.d.ts.map +1 -0
  25. package/dist/node-lib/binding/buffer.d.ts +144 -0
  26. package/dist/node-lib/binding/buffer.d.ts.map +1 -0
  27. package/dist/node-lib/binding/cares_wrap.d.ts +14 -0
  28. package/dist/node-lib/binding/cares_wrap.d.ts.map +1 -0
  29. package/dist/node-lib/binding/fds.d.ts +30 -0
  30. package/dist/node-lib/binding/fds.d.ts.map +1 -0
  31. package/dist/node-lib/binding/fs.d.ts +157 -0
  32. package/dist/node-lib/binding/fs.d.ts.map +1 -0
  33. package/dist/node-lib/binding/handles.d.ts +81 -0
  34. package/dist/node-lib/binding/handles.d.ts.map +1 -0
  35. package/dist/node-lib/binding/http_parser.d.ts +122 -0
  36. package/dist/node-lib/binding/http_parser.d.ts.map +1 -0
  37. package/dist/node-lib/binding/index.d.ts +3 -0
  38. package/dist/node-lib/binding/index.d.ts.map +1 -0
  39. package/dist/node-lib/binding/llhttp-wasm.d.ts +22 -0
  40. package/dist/node-lib/binding/llhttp-wasm.d.ts.map +1 -0
  41. package/dist/node-lib/binding/misc.d.ts +123 -0
  42. package/dist/node-lib/binding/misc.d.ts.map +1 -0
  43. package/dist/node-lib/binding/pipe_wrap.d.ts +84 -0
  44. package/dist/node-lib/binding/pipe_wrap.d.ts.map +1 -0
  45. package/dist/node-lib/binding/process_wrap.d.ts +173 -0
  46. package/dist/node-lib/binding/process_wrap.d.ts.map +1 -0
  47. package/dist/node-lib/binding/spawn_sync.d.ts +30 -0
  48. package/dist/node-lib/binding/spawn_sync.d.ts.map +1 -0
  49. package/dist/node-lib/binding/stream_wrap.d.ts +191 -0
  50. package/dist/node-lib/binding/stream_wrap.d.ts.map +1 -0
  51. package/dist/node-lib/binding/stubs.d.ts +23 -0
  52. package/dist/node-lib/binding/stubs.d.ts.map +1 -0
  53. package/dist/node-lib/binding/tcp_wrap.d.ts +98 -0
  54. package/dist/node-lib/binding/tcp_wrap.d.ts.map +1 -0
  55. package/dist/node-lib/binding/tty_wrap.d.ts +36 -0
  56. package/dist/node-lib/binding/tty_wrap.d.ts.map +1 -0
  57. package/dist/node-lib/binding/util.d.ts +126 -0
  58. package/dist/node-lib/binding/util.d.ts.map +1 -0
  59. package/dist/node-lib/binding/uv.d.ts +32 -0
  60. package/dist/node-lib/binding/uv.d.ts.map +1 -0
  61. package/dist/node-lib/binding/zlib-pako.d.ts +22 -0
  62. package/dist/node-lib/binding/zlib-pako.d.ts.map +1 -0
  63. package/dist/node-lib/binding/zlib.d.ts +38 -0
  64. package/dist/node-lib/binding/zlib.d.ts.map +1 -0
  65. package/dist/node-lib/buffer-module.d.ts +51 -0
  66. package/dist/node-lib/buffer-module.d.ts.map +1 -0
  67. package/dist/node-lib/child-process-module.d.ts +26 -0
  68. package/dist/node-lib/child-process-module.d.ts.map +1 -0
  69. package/dist/node-lib/events-module.d.ts +58 -0
  70. package/dist/node-lib/events-module.d.ts.map +1 -0
  71. package/dist/node-lib/fs-module.d.ts +5 -0
  72. package/dist/node-lib/fs-module.d.ts.map +1 -0
  73. package/dist/node-lib/http-bridge.d.ts +43 -0
  74. package/dist/node-lib/http-bridge.d.ts.map +1 -0
  75. package/dist/node-lib/http-module.d.ts +35 -0
  76. package/dist/node-lib/http-module.d.ts.map +1 -0
  77. package/dist/node-lib/internals/addresses.d.ts +40 -0
  78. package/dist/node-lib/internals/addresses.d.ts.map +1 -0
  79. package/dist/node-lib/internals/buffer-and-streams.d.ts +96 -0
  80. package/dist/node-lib/internals/buffer-and-streams.d.ts.map +1 -0
  81. package/dist/node-lib/internals/child-process.d.ts +27 -0
  82. package/dist/node-lib/internals/child-process.d.ts.map +1 -0
  83. package/dist/node-lib/internals/events-util.d.ts +83 -0
  84. package/dist/node-lib/internals/events-util.d.ts.map +1 -0
  85. package/dist/node-lib/internals/index.d.ts +2 -0
  86. package/dist/node-lib/internals/index.d.ts.map +1 -0
  87. package/dist/node-lib/internals/modules.d.ts +67 -0
  88. package/dist/node-lib/internals/modules.d.ts.map +1 -0
  89. package/dist/node-lib/internals/readline-access.d.ts +2 -0
  90. package/dist/node-lib/internals/readline-access.d.ts.map +1 -0
  91. package/dist/node-lib/internals/runtime.d.ts +150 -0
  92. package/dist/node-lib/internals/runtime.d.ts.map +1 -0
  93. package/dist/node-lib/internals/util.d.ts +33 -0
  94. package/dist/node-lib/internals/util.d.ts.map +1 -0
  95. package/dist/node-lib/lazy.d.ts +31 -0
  96. package/dist/node-lib/lazy.d.ts.map +1 -0
  97. package/dist/node-lib/load.d.ts +27 -0
  98. package/dist/node-lib/load.d.ts.map +1 -0
  99. package/dist/node-lib/module-hooks.d.ts +89 -0
  100. package/dist/node-lib/module-hooks.d.ts.map +1 -0
  101. package/dist/node-lib/net-module.d.ts +181 -0
  102. package/dist/node-lib/net-module.d.ts.map +1 -0
  103. package/dist/node-lib/node-versions.d.ts +27 -0
  104. package/dist/node-lib/node-versions.d.ts.map +1 -0
  105. package/dist/node-lib/public-modules.d.ts +2 -0
  106. package/dist/node-lib/public-modules.d.ts.map +1 -0
  107. package/dist/node-lib/require-hook.d.ts +15 -0
  108. package/dist/node-lib/require-hook.d.ts.map +1 -0
  109. package/dist/node-lib/small-modules.d.ts +16 -0
  110. package/dist/node-lib/small-modules.d.ts.map +1 -0
  111. package/dist/node-lib/sources.d.ts +4 -0
  112. package/dist/node-lib/sources.d.ts.map +1 -0
  113. package/dist/node-lib/stream-module.d.ts +77 -0
  114. package/dist/node-lib/stream-module.d.ts.map +1 -0
  115. package/dist/node-lib/timers.d.ts +19 -0
  116. package/dist/node-lib/timers.d.ts.map +1 -0
  117. package/dist/node-lib/util-module.d.ts +76 -0
  118. package/dist/node-lib/util-module.d.ts.map +1 -0
  119. package/dist/node-resolution.d.ts +50 -0
  120. package/dist/node-resolution.d.ts.map +1 -0
  121. package/dist/node-resolver.d.ts +7 -0
  122. package/dist/node-resolver.d.ts.map +1 -0
  123. package/dist/npm/index.d.ts +73 -0
  124. package/dist/npm/index.d.ts.map +1 -0
  125. package/dist/npm/registry.d.ts +111 -0
  126. package/dist/npm/registry.d.ts.map +1 -0
  127. package/dist/npm/resolver.d.ts +79 -0
  128. package/dist/npm/resolver.d.ts.map +1 -0
  129. package/dist/npm/tarball.d.ts +28 -0
  130. package/dist/npm/tarball.d.ts.map +1 -0
  131. package/dist/process-tokens.d.ts +77 -0
  132. package/dist/process-tokens.d.ts.map +1 -0
  133. package/dist/punycode-source.d.ts +3 -0
  134. package/dist/punycode-source.d.ts.map +1 -0
  135. package/dist/runtime-interface.d.ts +74 -0
  136. package/dist/runtime-interface.d.ts.map +1 -0
  137. package/dist/runtime.d.ts +144 -0
  138. package/dist/runtime.d.ts.map +1 -0
  139. package/dist/server-bridge.d.ts +147 -0
  140. package/dist/server-bridge.d.ts.map +1 -0
  141. package/dist/shims/async_hooks.d.ts +50 -0
  142. package/dist/shims/async_hooks.d.ts.map +1 -0
  143. package/dist/shims/child_process.d.ts +104 -0
  144. package/dist/shims/child_process.d.ts.map +1 -0
  145. package/dist/shims/cluster.d.ts +52 -0
  146. package/dist/shims/cluster.d.ts.map +1 -0
  147. package/dist/shims/command-line.d.ts +43 -0
  148. package/dist/shims/command-line.d.ts.map +1 -0
  149. package/dist/shims/constants.d.ts +222 -0
  150. package/dist/shims/constants.d.ts.map +1 -0
  151. package/dist/shims/crypto-constants.d.ts +12 -0
  152. package/dist/shims/crypto-constants.d.ts.map +1 -0
  153. package/dist/shims/crypto.d.ts +144 -0
  154. package/dist/shims/crypto.d.ts.map +1 -0
  155. package/dist/shims/dgram.d.ts +34 -0
  156. package/dist/shims/dgram.d.ts.map +1 -0
  157. package/dist/shims/dns.d.ts +91 -0
  158. package/dist/shims/dns.d.ts.map +1 -0
  159. package/dist/shims/domain.d.ts +25 -0
  160. package/dist/shims/domain.d.ts.map +1 -0
  161. package/dist/shims/esbuild.d.ts +205 -0
  162. package/dist/shims/esbuild.d.ts.map +1 -0
  163. package/dist/shims/fs.d.ts +25 -0
  164. package/dist/shims/fs.d.ts.map +1 -0
  165. package/dist/shims/http2.d.ts +81 -0
  166. package/dist/shims/http2.d.ts.map +1 -0
  167. package/dist/shims/inspector.d.ts +25 -0
  168. package/dist/shims/inspector.d.ts.map +1 -0
  169. package/dist/shims/module.d.ts +22 -0
  170. package/dist/shims/module.d.ts.map +1 -0
  171. package/dist/shims/os.d.ts +159 -0
  172. package/dist/shims/os.d.ts.map +1 -0
  173. package/dist/shims/path.d.ts +52 -0
  174. package/dist/shims/path.d.ts.map +1 -0
  175. package/dist/shims/perf_hooks.d.ts +50 -0
  176. package/dist/shims/perf_hooks.d.ts.map +1 -0
  177. package/dist/shims/process.d.ts +226 -0
  178. package/dist/shims/process.d.ts.map +1 -0
  179. package/dist/shims/rollup.d.ts +71 -0
  180. package/dist/shims/rollup.d.ts.map +1 -0
  181. package/dist/shims/string_decoder.d.ts +41 -0
  182. package/dist/shims/string_decoder.d.ts.map +1 -0
  183. package/dist/shims/sync-child.d.ts +64 -0
  184. package/dist/shims/sync-child.d.ts.map +1 -0
  185. package/dist/shims/tls.d.ts +53 -0
  186. package/dist/shims/tls.d.ts.map +1 -0
  187. package/dist/shims/url.d.ts +84 -0
  188. package/dist/shims/url.d.ts.map +1 -0
  189. package/dist/shims/v8.d.ts +73 -0
  190. package/dist/shims/v8.d.ts.map +1 -0
  191. package/dist/shims/vfs-adapter.d.ts +126 -0
  192. package/dist/shims/vfs-adapter.d.ts.map +1 -0
  193. package/dist/shims/vm.d.ts +52 -0
  194. package/dist/shims/vm.d.ts.map +1 -0
  195. package/dist/shims/wasi.d.ts +78 -0
  196. package/dist/shims/wasi.d.ts.map +1 -0
  197. package/dist/shims/worker_threads.d.ts +66 -0
  198. package/dist/shims/worker_threads.d.ts.map +1 -0
  199. package/dist/shims/zlib-constants.d.ts +66 -0
  200. package/dist/shims/zlib-constants.d.ts.map +1 -0
  201. package/dist/shims/zlib.d.ts +102 -0
  202. package/dist/shims/zlib.d.ts.map +1 -0
  203. package/dist/transform.d.ts +24 -0
  204. package/dist/transform.d.ts.map +1 -0
  205. package/dist/types/package-json.d.ts +18 -0
  206. package/dist/types/package-json.d.ts.map +1 -0
  207. package/dist/utils/binary-encoding.d.ts +13 -0
  208. package/dist/utils/binary-encoding.d.ts.map +1 -0
  209. package/dist/utils/glob.d.ts +19 -0
  210. package/dist/utils/glob.d.ts.map +1 -0
  211. package/dist/utils/hash.d.ts +6 -0
  212. package/dist/utils/hash.d.ts.map +1 -0
  213. package/dist/virtual-fs.d.ts +259 -0
  214. package/dist/virtual-fs.d.ts.map +1 -0
  215. package/dist/vite-plugin.cjs +50 -0
  216. package/dist/vite-plugin.cjs.map +1 -0
  217. package/dist/vite-plugin.d.ts +36 -0
  218. package/dist/vite-plugin.d.ts.map +1 -0
  219. package/dist/vite-plugin.mjs +31 -0
  220. package/dist/vite-plugin.mjs.map +1 -0
  221. package/dist/worker/runtime-worker.d.ts +8 -0
  222. package/dist/worker/runtime-worker.d.ts.map +1 -0
  223. package/dist/worker-runtime.d.ts +50 -0
  224. package/dist/worker-runtime.d.ts.map +1 -0
  225. package/package.json +88 -0
  226. package/src/code-transforms.ts +560 -0
  227. package/src/config/cdn.ts +13 -0
  228. package/src/create-runtime.ts +89 -0
  229. package/src/host-globals.ts +121 -0
  230. package/src/index.ts +235 -0
  231. package/src/node-internals.ts +283 -0
  232. package/src/node-lib/LICENSE +47 -0
  233. package/src/node-lib/_http_agent.js +547 -0
  234. package/src/node-lib/_http_client.js +996 -0
  235. package/src/node-lib/_http_common.js +269 -0
  236. package/src/node-lib/_http_incoming.js +453 -0
  237. package/src/node-lib/_http_outgoing.js +1262 -0
  238. package/src/node-lib/_http_server.js +1230 -0
  239. package/src/node-lib/assert/strict.js +3 -0
  240. package/src/node-lib/assert.js +844 -0
  241. package/src/node-lib/binding/blob.ts +35 -0
  242. package/src/node-lib/binding/buffer.ts +465 -0
  243. package/src/node-lib/binding/cares_wrap.ts +57 -0
  244. package/src/node-lib/binding/fds.ts +80 -0
  245. package/src/node-lib/binding/fs.ts +857 -0
  246. package/src/node-lib/binding/handles.ts +187 -0
  247. package/src/node-lib/binding/http_parser.ts +536 -0
  248. package/src/node-lib/binding/index.ts +77 -0
  249. package/src/node-lib/binding/llhttp-wasm.ts +670 -0
  250. package/src/node-lib/binding/misc.ts +252 -0
  251. package/src/node-lib/binding/pipe_wrap.ts +166 -0
  252. package/src/node-lib/binding/process_wrap.ts +371 -0
  253. package/src/node-lib/binding/spawn_sync.ts +141 -0
  254. package/src/node-lib/binding/stream_wrap.ts +413 -0
  255. package/src/node-lib/binding/stubs.ts +19 -0
  256. package/src/node-lib/binding/tcp_wrap.ts +254 -0
  257. package/src/node-lib/binding/tty_wrap.ts +56 -0
  258. package/src/node-lib/binding/util.ts +274 -0
  259. package/src/node-lib/binding/uv.ts +102 -0
  260. package/src/node-lib/binding/zlib-pako.ts +50 -0
  261. package/src/node-lib/binding/zlib.ts +259 -0
  262. package/src/node-lib/buffer-module.ts +70 -0
  263. package/src/node-lib/buffer.js +1373 -0
  264. package/src/node-lib/child-process-module.ts +58 -0
  265. package/src/node-lib/child_process.js +1046 -0
  266. package/src/node-lib/constants.js +41 -0
  267. package/src/node-lib/diagnostics_channel.js +438 -0
  268. package/src/node-lib/events-module.ts +80 -0
  269. package/src/node-lib/events.js +1223 -0
  270. package/src/node-lib/fs-module.ts +43 -0
  271. package/src/node-lib/fs.js +3377 -0
  272. package/src/node-lib/http-bridge.ts +299 -0
  273. package/src/node-lib/http-module.ts +53 -0
  274. package/src/node-lib/http.js +198 -0
  275. package/src/node-lib/https.js +429 -0
  276. package/src/node-lib/internal/assert/assertion_error.js +417 -0
  277. package/src/node-lib/internal/assert/calltracker.js +153 -0
  278. package/src/node-lib/internal/assert/myers_diff.js +177 -0
  279. package/src/node-lib/internal/assert/utils.js +278 -0
  280. package/src/node-lib/internal/buffer.js +1120 -0
  281. package/src/node-lib/internal/child_process/serialization.js +169 -0
  282. package/src/node-lib/internal/child_process.js +1135 -0
  283. package/src/node-lib/internal/constants.js +56 -0
  284. package/src/node-lib/internal/deps/minimatch/index.js +1628 -0
  285. package/src/node-lib/internal/errors.js +1912 -0
  286. package/src/node-lib/internal/events/abort_listener.js +54 -0
  287. package/src/node-lib/internal/events/symbols.js +11 -0
  288. package/src/node-lib/internal/fixed_queue.js +119 -0
  289. package/src/node-lib/internal/freelist.js +30 -0
  290. package/src/node-lib/internal/fs/cp/cp-sync.js +242 -0
  291. package/src/node-lib/internal/fs/cp/cp.js +382 -0
  292. package/src/node-lib/internal/fs/dir.js +369 -0
  293. package/src/node-lib/internal/fs/glob.js +763 -0
  294. package/src/node-lib/internal/fs/promises.js +1312 -0
  295. package/src/node-lib/internal/fs/read/context.js +129 -0
  296. package/src/node-lib/internal/fs/recursive_watch.js +275 -0
  297. package/src/node-lib/internal/fs/rimraf.js +311 -0
  298. package/src/node-lib/internal/fs/streams.js +571 -0
  299. package/src/node-lib/internal/fs/sync_write_stream.js +49 -0
  300. package/src/node-lib/internal/fs/utils.js +987 -0
  301. package/src/node-lib/internal/fs/watchers.js +418 -0
  302. package/src/node-lib/internal/http.js +62 -0
  303. package/src/node-lib/internal/mime.js +389 -0
  304. package/src/node-lib/internal/modules/customization_hooks.js +406 -0
  305. package/src/node-lib/internal/net.js +95 -0
  306. package/src/node-lib/internal/querystring.js +119 -0
  307. package/src/node-lib/internal/readline/callbacks.js +132 -0
  308. package/src/node-lib/internal/readline/emitKeypressEvents.js +99 -0
  309. package/src/node-lib/internal/readline/interface.js +1418 -0
  310. package/src/node-lib/internal/readline/promises.js +144 -0
  311. package/src/node-lib/internal/readline/utils.js +405 -0
  312. package/src/node-lib/internal/socket_list.js +108 -0
  313. package/src/node-lib/internal/stream_base_commons.js +280 -0
  314. package/src/node-lib/internal/streams/add-abort-signal.js +60 -0
  315. package/src/node-lib/internal/streams/compose.js +257 -0
  316. package/src/node-lib/internal/streams/destroy.js +361 -0
  317. package/src/node-lib/internal/streams/duplex.js +203 -0
  318. package/src/node-lib/internal/streams/duplexify.js +379 -0
  319. package/src/node-lib/internal/streams/duplexpair.js +62 -0
  320. package/src/node-lib/internal/streams/end-of-stream.js +331 -0
  321. package/src/node-lib/internal/streams/from.js +208 -0
  322. package/src/node-lib/internal/streams/lazy_transform.js +57 -0
  323. package/src/node-lib/internal/streams/legacy.js +125 -0
  324. package/src/node-lib/internal/streams/operators.js +436 -0
  325. package/src/node-lib/internal/streams/passthrough.js +47 -0
  326. package/src/node-lib/internal/streams/pipeline.js +465 -0
  327. package/src/node-lib/internal/streams/readable.js +1762 -0
  328. package/src/node-lib/internal/streams/state.js +51 -0
  329. package/src/node-lib/internal/streams/transform.js +204 -0
  330. package/src/node-lib/internal/streams/utils.js +363 -0
  331. package/src/node-lib/internal/streams/writable.js +1163 -0
  332. package/src/node-lib/internal/tty.js +260 -0
  333. package/src/node-lib/internal/util/colors.js +40 -0
  334. package/src/node-lib/internal/util/comparisons.js +1028 -0
  335. package/src/node-lib/internal/util/debuglog.js +524 -0
  336. package/src/node-lib/internal/util/inspect.js +2535 -0
  337. package/src/node-lib/internal/util/parse_args/parse_args.js +412 -0
  338. package/src/node-lib/internal/util/parse_args/utils.js +197 -0
  339. package/src/node-lib/internal/util.js +1003 -0
  340. package/src/node-lib/internal/validators.js +654 -0
  341. package/src/node-lib/internals/addresses.ts +159 -0
  342. package/src/node-lib/internals/buffer-and-streams.ts +224 -0
  343. package/src/node-lib/internals/child-process.ts +64 -0
  344. package/src/node-lib/internals/events-util.ts +105 -0
  345. package/src/node-lib/internals/index.ts +66 -0
  346. package/src/node-lib/internals/modules.ts +117 -0
  347. package/src/node-lib/internals/readline-access.ts +16 -0
  348. package/src/node-lib/internals/runtime.ts +277 -0
  349. package/src/node-lib/internals/util.ts +98 -0
  350. package/src/node-lib/lazy.ts +158 -0
  351. package/src/node-lib/load.ts +390 -0
  352. package/src/node-lib/module-hooks.ts +281 -0
  353. package/src/node-lib/net-module.ts +248 -0
  354. package/src/node-lib/net.js +2540 -0
  355. package/src/node-lib/node-versions.ts +34 -0
  356. package/src/node-lib/os.js +356 -0
  357. package/src/node-lib/path.js +1694 -0
  358. package/src/node-lib/primordials.js +743 -0
  359. package/src/node-lib/public-modules.ts +109 -0
  360. package/src/node-lib/punycode.js +455 -0
  361. package/src/node-lib/querystring.js +484 -0
  362. package/src/node-lib/readline/promises.js +73 -0
  363. package/src/node-lib/readline.js +523 -0
  364. package/src/node-lib/require-hook.ts +27 -0
  365. package/src/node-lib/small-modules.ts +35 -0
  366. package/src/node-lib/sources.ts +200 -0
  367. package/src/node-lib/stream/promises.js +44 -0
  368. package/src/node-lib/stream-module.ts +101 -0
  369. package/src/node-lib/stream.js +152 -0
  370. package/src/node-lib/timers.ts +33 -0
  371. package/src/node-lib/tty.js +168 -0
  372. package/src/node-lib/util-module.ts +104 -0
  373. package/src/node-lib/util.js +689 -0
  374. package/src/node-lib/wasi.js +179 -0
  375. package/src/node-lib/zlib.js +1036 -0
  376. package/src/node-resolution.ts +241 -0
  377. package/src/node-resolver.ts +33 -0
  378. package/src/npm/index.ts +425 -0
  379. package/src/npm/registry.ts +235 -0
  380. package/src/npm/resolver.ts +589 -0
  381. package/src/npm/tarball.ts +246 -0
  382. package/src/process-tokens.ts +156 -0
  383. package/src/punycode-source.ts +6 -0
  384. package/src/runtime-interface.ts +85 -0
  385. package/src/runtime.ts +3073 -0
  386. package/src/server-bridge.ts +971 -0
  387. package/src/shims/async_hooks.ts +181 -0
  388. package/src/shims/child_process.ts +1591 -0
  389. package/src/shims/cluster.ts +79 -0
  390. package/src/shims/command-line.ts +79 -0
  391. package/src/shims/constants.ts +68 -0
  392. package/src/shims/crypto-constants.ts +11 -0
  393. package/src/shims/crypto.ts +1061 -0
  394. package/src/shims/dgram.ts +47 -0
  395. package/src/shims/dns.ts +185 -0
  396. package/src/shims/domain.ts +58 -0
  397. package/src/shims/esbuild.ts +1638 -0
  398. package/src/shims/fs.ts +82 -0
  399. package/src/shims/http2.ts +96 -0
  400. package/src/shims/inspector.ts +30 -0
  401. package/src/shims/module.ts +86 -0
  402. package/src/shims/os.ts +195 -0
  403. package/src/shims/path.ts +246 -0
  404. package/src/shims/perf_hooks.ts +92 -0
  405. package/src/shims/process.ts +804 -0
  406. package/src/shims/rollup.ts +149 -0
  407. package/src/shims/string_decoder.ts +396 -0
  408. package/src/shims/sync-child.ts +469 -0
  409. package/src/shims/tls.ts +94 -0
  410. package/src/shims/url.ts +217 -0
  411. package/src/shims/v8.ts +113 -0
  412. package/src/shims/vfs-adapter.ts +408 -0
  413. package/src/shims/vm.ts +132 -0
  414. package/src/shims/wasi.ts +1440 -0
  415. package/src/shims/worker_threads.ts +114 -0
  416. package/src/shims/zlib-constants.ts +65 -0
  417. package/src/shims/zlib.ts +228 -0
  418. package/src/transform.ts +324 -0
  419. package/src/types/external.d.ts +55 -0
  420. package/src/types/package-json.ts +17 -0
  421. package/src/types/pako-zlib.d.ts +30 -0
  422. package/src/types/sha.js.d.ts +14 -0
  423. package/src/utils/binary-encoding.ts +43 -0
  424. package/src/utils/glob.ts +54 -0
  425. package/src/utils/hash.ts +12 -0
  426. package/src/virtual-fs.ts +1048 -0
  427. package/src/vite-plugin.ts +76 -0
  428. package/src/worker/runtime-worker.ts +128 -0
  429. package/src/worker-runtime.ts +145 -0
@@ -0,0 +1,3377 @@
1
+ // Copyright Joyent, Inc. and other Node contributors.
2
+ //
3
+ // Permission is hereby granted, free of charge, to any person obtaining a
4
+ // copy of this software and associated documentation files (the
5
+ // "Software"), to deal in the Software without restriction, including
6
+ // without limitation the rights to use, copy, modify, merge, publish,
7
+ // distribute, sublicense, and/or sell copies of the Software, and to permit
8
+ // persons to whom the Software is furnished to do so, subject to the
9
+ // following conditions:
10
+ //
11
+ // The above copyright notice and this permission notice shall be included
12
+ // in all copies or substantial portions of the Software.
13
+ //
14
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15
+ // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17
+ // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18
+ // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19
+ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20
+ // USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ // Maintainers, keep in mind that ES1-style octal literals (`0666`) are not
23
+ // allowed in strict mode. Use ES6-style octal literals instead (`0o666`).
24
+
25
+ 'use strict';
26
+
27
+ const {
28
+ ArrayPrototypePush,
29
+ BigIntPrototypeToString,
30
+ Boolean,
31
+ MathMax,
32
+ Number,
33
+ ObjectDefineProperties,
34
+ ObjectDefineProperty,
35
+ Promise,
36
+ PromiseResolve,
37
+ ReflectApply,
38
+ SafeMap,
39
+ SafeSet,
40
+ StringPrototypeCharCodeAt,
41
+ StringPrototypeIndexOf,
42
+ StringPrototypeSlice,
43
+ uncurryThis,
44
+ } = primordials;
45
+
46
+ const { fs: constants } = internalBinding('constants');
47
+ const {
48
+ S_IFIFO,
49
+ S_IFLNK,
50
+ S_IFMT,
51
+ S_IFREG,
52
+ S_IFSOCK,
53
+ F_OK,
54
+ R_OK,
55
+ W_OK,
56
+ X_OK,
57
+ O_WRONLY,
58
+ O_SYMLINK,
59
+ } = constants;
60
+
61
+ const pathModule = require('path');
62
+ const { isAbsolute } = pathModule;
63
+ const { isArrayBufferView } = require('internal/util/types');
64
+
65
+ const binding = internalBinding('fs');
66
+
67
+ const { createBlobFromFilePath } = require('internal/blob');
68
+
69
+ const { Buffer } = require('buffer');
70
+ const { isBuffer: BufferIsBuffer } = Buffer;
71
+ const BufferToString = uncurryThis(Buffer.prototype.toString);
72
+ const {
73
+ AbortError,
74
+ aggregateTwoErrors,
75
+ codes: {
76
+ ERR_ACCESS_DENIED,
77
+ ERR_FS_FILE_TOO_LARGE,
78
+ ERR_INVALID_ARG_VALUE,
79
+ },
80
+ } = require('internal/errors');
81
+
82
+ const {
83
+ FSReqCallback,
84
+ statValues,
85
+ } = binding;
86
+ const { toPathIfFileURL } = require('internal/url');
87
+ const {
88
+ customPromisifyArgs: kCustomPromisifyArgsSymbol,
89
+ getLazy,
90
+ kEmptyObject,
91
+ promisify: {
92
+ custom: kCustomPromisifiedSymbol,
93
+ },
94
+ SideEffectFreeRegExpPrototypeExec,
95
+ defineLazyProperties,
96
+ isWindows,
97
+ isMacOS,
98
+ } = require('internal/util');
99
+ const {
100
+ constants: {
101
+ kIoMaxLength,
102
+ kMaxUserId,
103
+ },
104
+ copyObject,
105
+ Dirent,
106
+ emitRecursiveRmdirWarning,
107
+ getDirent,
108
+ getDirents,
109
+ getOptions,
110
+ getValidatedFd,
111
+ getValidatedPath,
112
+ handleErrorFromBinding,
113
+ preprocessSymlinkDestination,
114
+ Stats,
115
+ getStatFsFromBinding,
116
+ getStatsFromBinding,
117
+ realpathCacheKey,
118
+ stringToFlags,
119
+ stringToSymlinkType,
120
+ toUnixTimestamp,
121
+ validateBufferArray,
122
+ validateCpOptions,
123
+ validateOffsetLengthRead,
124
+ validateOffsetLengthWrite,
125
+ validatePath,
126
+ validatePosition,
127
+ validateRmOptions,
128
+ validateRmOptionsSync,
129
+ validateRmdirOptions,
130
+ validateStringAfterArrayBufferView,
131
+ warnOnNonPortableTemplate,
132
+ } = require('internal/fs/utils');
133
+ const {
134
+ CHAR_FORWARD_SLASH,
135
+ CHAR_BACKWARD_SLASH,
136
+ } = require('internal/constants');
137
+ const {
138
+ isInt32,
139
+ parseFileMode,
140
+ validateBoolean,
141
+ validateBuffer,
142
+ validateEncoding,
143
+ validateFunction,
144
+ validateInteger,
145
+ validateObject,
146
+ validateString,
147
+ kValidateObjectAllowNullable,
148
+ } = require('internal/validators');
149
+
150
+ const permission = require('internal/process/permission');
151
+
152
+ let truncateWarn = true;
153
+ let fs;
154
+
155
+ // Lazy loaded
156
+ let cpFn;
157
+ let cpSyncFn;
158
+ let promises = null;
159
+ let ReadStream;
160
+ let WriteStream;
161
+ let rimraf;
162
+ let rimrafSync;
163
+ let kResistStopPropagation;
164
+ let ReadFileContext;
165
+
166
+ // These have to be separate because of how graceful-fs happens to do it's
167
+ // monkeypatching.
168
+ let FileReadStream;
169
+ let FileWriteStream;
170
+
171
+ function showTruncateDeprecation() {
172
+ if (truncateWarn) {
173
+ process.emitWarning(
174
+ 'Using fs.truncate with a file descriptor is deprecated. Please use ' +
175
+ 'fs.ftruncate with a file descriptor instead.',
176
+ 'DeprecationWarning', 'DEP0081');
177
+ truncateWarn = false;
178
+ }
179
+ }
180
+
181
+ // Ensure that callbacks run in the global context. Only use this function
182
+ // for callbacks that are passed to the binding layer, callbacks that are
183
+ // invoked from JS already run in the proper scope.
184
+ function makeCallback(cb) {
185
+ validateFunction(cb, 'cb');
186
+
187
+ return (...args) => ReflectApply(cb, this, args);
188
+ }
189
+
190
+ // Special case of `makeCallback()` that is specific to async `*stat()` calls as
191
+ // an optimization, since the data passed back to the callback needs to be
192
+ // transformed anyway.
193
+ function makeStatsCallback(cb) {
194
+ validateFunction(cb, 'cb');
195
+
196
+ return (err, stats) => {
197
+ if (err) return cb(err);
198
+ cb(err, getStatsFromBinding(stats));
199
+ };
200
+ }
201
+
202
+ const isFd = isInt32;
203
+
204
+ function isFileType(stats, fileType) {
205
+ // Use stats array directly to avoid creating an fs.Stats instance just for
206
+ // our internal use.
207
+ let mode = stats[1];
208
+ if (typeof mode === 'bigint')
209
+ mode = Number(mode);
210
+ return (mode & S_IFMT) === fileType;
211
+ }
212
+
213
+ /**
214
+ * Tests a user's permissions for the file or directory
215
+ * specified by `path`.
216
+ * @param {string | Buffer | URL} path
217
+ * @param {number} [mode]
218
+ * @param {(err?: Error) => any} callback
219
+ * @returns {void}
220
+ */
221
+ function access(path, mode, callback) {
222
+ if (typeof mode === 'function') {
223
+ callback = mode;
224
+ mode = F_OK;
225
+ }
226
+
227
+ path = getValidatedPath(path);
228
+ callback = makeCallback(callback);
229
+
230
+ const req = new FSReqCallback();
231
+ req.oncomplete = callback;
232
+ binding.access(path, mode, req);
233
+ }
234
+
235
+ /**
236
+ * Synchronously tests a user's permissions for the file or
237
+ * directory specified by `path`.
238
+ * @param {string | Buffer | URL} path
239
+ * @param {number} [mode]
240
+ * @returns {void}
241
+ */
242
+ function accessSync(path, mode) {
243
+ binding.access(getValidatedPath(path), mode);
244
+ }
245
+
246
+ /**
247
+ * Tests whether or not the given path exists.
248
+ * @param {string | Buffer | URL} path
249
+ * @param {(exists?: boolean) => any} callback
250
+ * @returns {void}
251
+ */
252
+ function exists(path, callback) {
253
+ validateFunction(callback, 'cb');
254
+
255
+ function suppressedCallback(err) {
256
+ callback(!err);
257
+ }
258
+
259
+ try {
260
+ fs.access(path, F_OK, suppressedCallback);
261
+ } catch {
262
+ return callback(false);
263
+ }
264
+ }
265
+
266
+ ObjectDefineProperty(exists, kCustomPromisifiedSymbol, {
267
+ __proto__: null,
268
+ value: function exists(path) { // eslint-disable-line func-name-matching
269
+ return new Promise((resolve) => fs.exists(path, resolve));
270
+ },
271
+ });
272
+
273
+ // fs.existsSync never throws, it only returns true or false.
274
+ // Since fs.existsSync never throws, users have established
275
+ // the expectation that passing invalid arguments to it, even like
276
+ // fs.existsSync(), would only get a false in return, so we cannot signal
277
+ // validation errors to users properly out of compatibility concerns.
278
+ // TODO(joyeecheung): deprecate the never-throw-on-invalid-arguments behavior
279
+ /**
280
+ * Synchronously tests whether or not the given path exists.
281
+ * @param {string | Buffer | URL} path
282
+ * @returns {boolean}
283
+ */
284
+ function existsSync(path) {
285
+ try {
286
+ path = getValidatedPath(path);
287
+ } catch {
288
+ return false;
289
+ }
290
+
291
+ return binding.existsSync(path);
292
+ }
293
+
294
+ function readFileAfterOpen(err, fd) {
295
+ const context = this.context;
296
+
297
+ if (err) {
298
+ context.callback(err);
299
+ return;
300
+ }
301
+
302
+ context.fd = fd;
303
+
304
+ const req = new FSReqCallback();
305
+ req.oncomplete = readFileAfterStat;
306
+ req.context = context;
307
+ binding.fstat(fd, false, req);
308
+ }
309
+
310
+ function readFileAfterStat(err, stats) {
311
+ const context = this.context;
312
+
313
+ if (err)
314
+ return context.close(err);
315
+
316
+ // TODO(BridgeAR): Check if allocating a smaller chunk is better performance
317
+ // wise, similar to the promise based version (less peak memory and chunked
318
+ // stringify operations vs multiple C++/JS boundary crossings).
319
+ const size = context.size = isFileType(stats, S_IFREG) ? stats[8] : 0;
320
+
321
+ if (size > kIoMaxLength) {
322
+ err = new ERR_FS_FILE_TOO_LARGE(size);
323
+ return context.close(err);
324
+ }
325
+
326
+ try {
327
+ if (size === 0) {
328
+ // TODO(BridgeAR): If an encoding is set, use the StringDecoder to concat
329
+ // the result and reuse the buffer instead of allocating a new one.
330
+ context.buffers = [];
331
+ } else {
332
+ context.buffer = Buffer.allocUnsafeSlow(size);
333
+ }
334
+ } catch (err) {
335
+ return context.close(err);
336
+ }
337
+ context.read();
338
+ }
339
+
340
+ function checkAborted(signal, callback) {
341
+ if (signal?.aborted) {
342
+ callback(new AbortError(undefined, { cause: signal.reason }));
343
+ return true;
344
+ }
345
+ return false;
346
+ }
347
+
348
+ /**
349
+ * Asynchronously reads the entire contents of a file.
350
+ * @param {string | Buffer | URL | number} path
351
+ * @param {{
352
+ * encoding?: string | null;
353
+ * flag?: string;
354
+ * signal?: AbortSignal;
355
+ * } | string} [options]
356
+ * @param {(
357
+ * err?: Error,
358
+ * data?: string | Buffer
359
+ * ) => any} callback
360
+ * @returns {void}
361
+ */
362
+ function readFile(path, options, callback) {
363
+ callback ||= options;
364
+ validateFunction(callback, 'cb');
365
+ options = getOptions(options, { flag: 'r' });
366
+ ReadFileContext ??= require('internal/fs/read/context');
367
+ const context = new ReadFileContext(callback, options.encoding);
368
+ context.isUserFd = isFd(path); // File descriptor ownership
369
+
370
+ if (options.signal) {
371
+ context.signal = options.signal;
372
+ }
373
+ if (context.isUserFd) {
374
+ process.nextTick(function tick(context) {
375
+ ReflectApply(readFileAfterOpen, { context }, [null, path]);
376
+ }, context);
377
+ return;
378
+ }
379
+
380
+ if (checkAborted(options.signal, callback))
381
+ return;
382
+
383
+ const flagsNumber = stringToFlags(options.flag, 'options.flag');
384
+ const req = new FSReqCallback();
385
+ req.context = context;
386
+ req.oncomplete = readFileAfterOpen;
387
+ binding.open(getValidatedPath(path), flagsNumber, 0o666, req);
388
+ }
389
+
390
+ function tryStatSync(fd, isUserFd) {
391
+ const stats = binding.fstat(fd, false, undefined, true /* shouldNotThrow */);
392
+ if (stats === undefined && !isUserFd) {
393
+ fs.closeSync(fd);
394
+ }
395
+ return stats;
396
+ }
397
+
398
+ function tryCreateBuffer(size, fd, isUserFd) {
399
+ let threw = true;
400
+ let buffer;
401
+ try {
402
+ if (size > kIoMaxLength) {
403
+ throw new ERR_FS_FILE_TOO_LARGE(size);
404
+ }
405
+ buffer = Buffer.allocUnsafe(size);
406
+ threw = false;
407
+ } finally {
408
+ if (threw && !isUserFd) fs.closeSync(fd);
409
+ }
410
+ return buffer;
411
+ }
412
+
413
+ function tryReadSync(fd, isUserFd, buffer, pos, len) {
414
+ let threw = true;
415
+ let bytesRead;
416
+ try {
417
+ bytesRead = fs.readSync(fd, buffer, pos, len);
418
+ threw = false;
419
+ } finally {
420
+ if (threw && !isUserFd) fs.closeSync(fd);
421
+ }
422
+ return bytesRead;
423
+ }
424
+
425
+ /**
426
+ * Synchronously reads the entire contents of a file.
427
+ * @param {string | Buffer | URL | number} path
428
+ * @param {{
429
+ * encoding?: string | null;
430
+ * flag?: string;
431
+ * }} [options]
432
+ * @returns {string | Buffer}
433
+ */
434
+ function readFileSync(path, options) {
435
+ options = getOptions(options, { flag: 'r' });
436
+
437
+ if (options.encoding === 'utf8' || options.encoding === 'utf-8') {
438
+ if (!isInt32(path)) {
439
+ path = getValidatedPath(path);
440
+ }
441
+ return binding.readFileUtf8(path, stringToFlags(options.flag));
442
+ }
443
+
444
+ const isUserFd = isFd(path); // File descriptor ownership
445
+ const fd = isUserFd ? path : fs.openSync(path, options.flag, 0o666);
446
+
447
+ const stats = tryStatSync(fd, isUserFd);
448
+ const size = isFileType(stats, S_IFREG) ? stats[8] : 0;
449
+ let pos = 0;
450
+ let buffer; // Single buffer with file data
451
+ let buffers; // List for when size is unknown
452
+
453
+ if (size === 0) {
454
+ buffers = [];
455
+ } else {
456
+ buffer = tryCreateBuffer(size, fd, isUserFd);
457
+ }
458
+
459
+ let bytesRead;
460
+
461
+ if (size !== 0) {
462
+ do {
463
+ bytesRead = tryReadSync(fd, isUserFd, buffer, pos, size - pos);
464
+ pos += bytesRead;
465
+ } while (bytesRead !== 0 && pos < size);
466
+ } else {
467
+ do {
468
+ // The kernel lies about many files.
469
+ // Go ahead and try to read some bytes.
470
+ buffer = Buffer.allocUnsafe(8192);
471
+ bytesRead = tryReadSync(fd, isUserFd, buffer, 0, 8192);
472
+ if (bytesRead !== 0) {
473
+ ArrayPrototypePush(buffers, buffer.slice(0, bytesRead));
474
+ }
475
+ pos += bytesRead;
476
+ } while (bytesRead !== 0);
477
+ }
478
+
479
+ if (!isUserFd)
480
+ fs.closeSync(fd);
481
+
482
+ if (size === 0) {
483
+ // Data was collected into the buffers list.
484
+ buffer = Buffer.concat(buffers, pos);
485
+ } else if (pos < size) {
486
+ buffer = buffer.slice(0, pos);
487
+ }
488
+
489
+ if (options.encoding) buffer = buffer.toString(options.encoding);
490
+ return buffer;
491
+ }
492
+
493
+ function defaultCloseCallback(err) {
494
+ if (err != null) throw err;
495
+ }
496
+
497
+ /**
498
+ * Closes the file descriptor.
499
+ * @param {number} fd
500
+ * @param {(err?: Error) => any} [callback]
501
+ * @returns {void}
502
+ */
503
+ function close(fd, callback = defaultCloseCallback) {
504
+ if (callback !== defaultCloseCallback)
505
+ callback = makeCallback(callback);
506
+
507
+ const req = new FSReqCallback();
508
+ req.oncomplete = callback;
509
+ binding.close(fd, req);
510
+ }
511
+
512
+ /**
513
+ * Synchronously closes the file descriptor.
514
+ * @param {number} fd
515
+ * @returns {void}
516
+ */
517
+ function closeSync(fd) {
518
+ binding.close(fd);
519
+ }
520
+
521
+ /**
522
+ * Asynchronously opens a file.
523
+ * @param {string | Buffer | URL} path
524
+ * @param {string | number} [flags]
525
+ * @param {string | number} [mode]
526
+ * @param {(
527
+ * err?: Error,
528
+ * fd?: number
529
+ * ) => any} callback
530
+ * @returns {void}
531
+ */
532
+ function open(path, flags, mode, callback) {
533
+ path = getValidatedPath(path);
534
+ if (arguments.length < 3) {
535
+ callback = flags;
536
+ flags = 'r';
537
+ mode = 0o666;
538
+ } else if (typeof mode === 'function') {
539
+ callback = mode;
540
+ mode = 0o666;
541
+ } else {
542
+ mode = parseFileMode(mode, 'mode', 0o666);
543
+ }
544
+ const flagsNumber = stringToFlags(flags);
545
+ callback = makeCallback(callback);
546
+
547
+ const req = new FSReqCallback();
548
+ req.oncomplete = callback;
549
+
550
+ binding.open(path, flagsNumber, mode, req);
551
+ }
552
+
553
+ /**
554
+ * Synchronously opens a file.
555
+ * @param {string | Buffer | URL} path
556
+ * @param {string | number} [flags]
557
+ * @param {string | number} [mode]
558
+ * @returns {number}
559
+ */
560
+ function openSync(path, flags, mode) {
561
+ return binding.open(
562
+ getValidatedPath(path),
563
+ stringToFlags(flags),
564
+ parseFileMode(mode, 'mode', 0o666),
565
+ );
566
+ }
567
+
568
+ /**
569
+ * @param {string | Buffer | URL } path
570
+ * @param {{
571
+ * type?: string;
572
+ * }} [options]
573
+ * @returns {Promise<Blob>}
574
+ */
575
+ function openAsBlob(path, options = kEmptyObject) {
576
+ validateObject(options, 'options');
577
+ const type = options.type || '';
578
+ validateString(type, 'options.type');
579
+ // The underlying implementation here returns the Blob synchronously for now.
580
+ // To give ourselves flexibility to maybe return the Blob asynchronously,
581
+ // this API returns a Promise.
582
+ path = getValidatedPath(path);
583
+ return PromiseResolve(createBlobFromFilePath(path, { type }));
584
+ }
585
+
586
+ /**
587
+ * Reads file from the specified `fd` (file descriptor).
588
+ * @param {number} fd
589
+ * @param {Buffer | TypedArray | DataView} buffer
590
+ * @param {number | {
591
+ * offset?: number;
592
+ * length?: number;
593
+ * position?: number | bigint | null;
594
+ * }} [offsetOrOptions]
595
+ * @param {number} length
596
+ * @param {number | bigint | null} position
597
+ * @param {(
598
+ * err?: Error,
599
+ * bytesRead?: number,
600
+ * buffer?: Buffer
601
+ * ) => any} callback
602
+ * @returns {void}
603
+ */
604
+ function read(fd, buffer, offsetOrOptions, length, position, callback) {
605
+ fd = getValidatedFd(fd);
606
+
607
+ let offset = offsetOrOptions;
608
+ let params = null;
609
+ if (arguments.length <= 4) {
610
+ if (arguments.length === 4) {
611
+ // This is fs.read(fd, buffer, options, callback)
612
+ validateObject(offsetOrOptions, 'options', kValidateObjectAllowNullable);
613
+ callback = length;
614
+ params = offsetOrOptions;
615
+ } else if (arguments.length === 3) {
616
+ // This is fs.read(fd, bufferOrParams, callback)
617
+ if (!isArrayBufferView(buffer)) {
618
+ // This is fs.read(fd, params, callback)
619
+ params = buffer;
620
+ ({ buffer = Buffer.alloc(16384) } = params ?? kEmptyObject);
621
+ }
622
+ callback = offsetOrOptions;
623
+ } else {
624
+ // This is fs.read(fd, callback)
625
+ callback = buffer;
626
+ buffer = Buffer.alloc(16384);
627
+ }
628
+
629
+ if (params !== undefined) {
630
+ validateObject(params, 'options', kValidateObjectAllowNullable);
631
+ }
632
+ ({
633
+ offset = 0,
634
+ length = buffer?.byteLength - offset,
635
+ position = null,
636
+ } = params ?? kEmptyObject);
637
+ }
638
+
639
+ validateBuffer(buffer);
640
+ validateFunction(callback, 'cb');
641
+
642
+ if (offset == null) {
643
+ offset = 0;
644
+ } else {
645
+ validateInteger(offset, 'offset', 0);
646
+ }
647
+
648
+ length |= 0;
649
+
650
+ if (length === 0) {
651
+ return process.nextTick(function tick() {
652
+ callback(null, 0, buffer);
653
+ });
654
+ }
655
+
656
+ if (buffer.byteLength === 0) {
657
+ throw new ERR_INVALID_ARG_VALUE('buffer', buffer,
658
+ 'is empty and cannot be written');
659
+ }
660
+
661
+ validateOffsetLengthRead(offset, length, buffer.byteLength);
662
+
663
+ if (position == null) {
664
+ position = -1;
665
+ } else {
666
+ validatePosition(position, 'position', length);
667
+ }
668
+
669
+ function wrapper(err, bytesRead) {
670
+ // Retain a reference to buffer so that it can't be GC'ed too soon.
671
+ callback(err, bytesRead || 0, buffer);
672
+ }
673
+
674
+ const req = new FSReqCallback();
675
+ req.oncomplete = wrapper;
676
+
677
+ binding.read(fd, buffer, offset, length, position, req);
678
+ }
679
+
680
+ ObjectDefineProperty(read, kCustomPromisifyArgsSymbol,
681
+ { __proto__: null, value: ['bytesRead', 'buffer'], enumerable: false });
682
+
683
+ /**
684
+ * Synchronously reads the file from the
685
+ * specified `fd` (file descriptor).
686
+ * @param {number} fd
687
+ * @param {Buffer | TypedArray | DataView} buffer
688
+ * @param {number | {
689
+ * offset?: number;
690
+ * length?: number;
691
+ * position?: number | bigint | null;
692
+ * }} [offsetOrOptions]
693
+ * @param {number} [length]
694
+ * @param {number} [position]
695
+ * @returns {number}
696
+ */
697
+ function readSync(fd, buffer, offsetOrOptions, length, position) {
698
+ fd = getValidatedFd(fd);
699
+
700
+ validateBuffer(buffer);
701
+
702
+ let offset = offsetOrOptions;
703
+ if (arguments.length <= 3 || typeof offsetOrOptions === 'object') {
704
+ if (offsetOrOptions !== undefined) {
705
+ validateObject(offsetOrOptions, 'options', kValidateObjectAllowNullable);
706
+ }
707
+
708
+ ({
709
+ offset = 0,
710
+ length = buffer.byteLength - offset,
711
+ position = null,
712
+ } = offsetOrOptions ?? kEmptyObject);
713
+ }
714
+
715
+ if (offset === undefined) {
716
+ offset = 0;
717
+ } else {
718
+ validateInteger(offset, 'offset', 0);
719
+ }
720
+
721
+ length |= 0;
722
+
723
+ if (length === 0) {
724
+ return 0;
725
+ }
726
+
727
+ if (buffer.byteLength === 0) {
728
+ throw new ERR_INVALID_ARG_VALUE('buffer', buffer,
729
+ 'is empty and cannot be written');
730
+ }
731
+
732
+ validateOffsetLengthRead(offset, length, buffer.byteLength);
733
+
734
+ if (position == null) {
735
+ position = -1;
736
+ } else {
737
+ validatePosition(position, 'position', length);
738
+ }
739
+
740
+ return binding.read(fd, buffer, offset, length, position);
741
+ }
742
+
743
+ /**
744
+ * Reads file from the specified `fd` (file descriptor)
745
+ * and writes to an array of `ArrayBufferView`s.
746
+ * @param {number} fd
747
+ * @param {ArrayBufferView[]} buffers
748
+ * @param {number | null} [position]
749
+ * @param {(
750
+ * err?: Error,
751
+ * bytesRead?: number,
752
+ * buffers?: ArrayBufferView[]
753
+ * ) => any} callback
754
+ * @returns {void}
755
+ */
756
+ function readv(fd, buffers, position, callback) {
757
+ function wrapper(err, read) {
758
+ callback(err, read || 0, buffers);
759
+ }
760
+
761
+ fd = getValidatedFd(fd);
762
+ validateBufferArray(buffers);
763
+ callback ||= position;
764
+ validateFunction(callback, 'cb');
765
+
766
+ const req = new FSReqCallback();
767
+ req.oncomplete = wrapper;
768
+
769
+ if (typeof position !== 'number')
770
+ position = null;
771
+
772
+ binding.readBuffers(fd, buffers, position, req);
773
+ }
774
+
775
+ ObjectDefineProperty(readv, kCustomPromisifyArgsSymbol,
776
+ { __proto__: null, value: ['bytesRead', 'buffers'], enumerable: false });
777
+
778
+ /**
779
+ * Synchronously reads file from the
780
+ * specified `fd` (file descriptor) and writes to an array
781
+ * of `ArrayBufferView`s.
782
+ * @param {number} fd
783
+ * @param {ArrayBufferView[]} buffers
784
+ * @param {number | null} [position]
785
+ * @returns {number}
786
+ */
787
+ function readvSync(fd, buffers, position) {
788
+ fd = getValidatedFd(fd);
789
+ validateBufferArray(buffers);
790
+
791
+ if (typeof position !== 'number')
792
+ position = null;
793
+
794
+ return binding.readBuffers(fd, buffers, position);
795
+ }
796
+
797
+ /**
798
+ * Writes `buffer` to the specified `fd` (file descriptor).
799
+ * @param {number} fd
800
+ * @param {Buffer | TypedArray | DataView | string} buffer
801
+ * @param {number | object} [offsetOrOptions]
802
+ * @param {number} [length]
803
+ * @param {number | null} [position]
804
+ * @param {(
805
+ * err?: Error,
806
+ * bytesWritten?: number,
807
+ * buffer?: Buffer | TypedArray | DataView
808
+ * ) => any} callback
809
+ * @returns {void}
810
+ */
811
+ function write(fd, buffer, offsetOrOptions, length, position, callback) {
812
+ function wrapper(err, written) {
813
+ // Retain a reference to buffer so that it can't be GC'ed too soon.
814
+ callback(err, written || 0, buffer);
815
+ }
816
+
817
+ fd = getValidatedFd(fd);
818
+
819
+ let offset = offsetOrOptions;
820
+ if (isArrayBufferView(buffer)) {
821
+ callback ||= position || length || offset;
822
+ validateFunction(callback, 'cb');
823
+
824
+ if (typeof offset === 'object') {
825
+ ({
826
+ offset = 0,
827
+ length = buffer.byteLength - offset,
828
+ position = null,
829
+ } = offsetOrOptions ?? kEmptyObject);
830
+ }
831
+
832
+ if (offset == null || typeof offset === 'function') {
833
+ offset = 0;
834
+ } else {
835
+ validateInteger(offset, 'offset', 0);
836
+ }
837
+ if (typeof length !== 'number')
838
+ length = buffer.byteLength - offset;
839
+ if (typeof position !== 'number')
840
+ position = null;
841
+ validateOffsetLengthWrite(offset, length, buffer.byteLength);
842
+
843
+ const req = new FSReqCallback();
844
+ req.oncomplete = wrapper;
845
+ binding.writeBuffer(fd, buffer, offset, length, position, req);
846
+ return;
847
+ }
848
+
849
+ validateStringAfterArrayBufferView(buffer, 'buffer');
850
+
851
+ if (typeof position !== 'function') {
852
+ if (typeof offset === 'function') {
853
+ position = offset;
854
+ offset = null;
855
+ } else {
856
+ position = length;
857
+ }
858
+ length = 'utf8';
859
+ }
860
+
861
+ const str = buffer;
862
+ validateEncoding(str, length);
863
+ callback = position;
864
+ validateFunction(callback, 'cb');
865
+
866
+ const req = new FSReqCallback();
867
+ req.oncomplete = wrapper;
868
+ binding.writeString(fd, str, offset, length, req);
869
+ }
870
+
871
+ ObjectDefineProperty(write, kCustomPromisifyArgsSymbol,
872
+ { __proto__: null, value: ['bytesWritten', 'buffer'], enumerable: false });
873
+
874
+ /**
875
+ * Synchronously writes `buffer` to the
876
+ * specified `fd` (file descriptor).
877
+ * @param {number} fd
878
+ * @param {Buffer | TypedArray | DataView | string} buffer
879
+ * @param {{
880
+ * offset?: number;
881
+ * length?: number;
882
+ * position?: number | null;
883
+ * }} [offsetOrOptions]
884
+ * @param {number} [length]
885
+ * @param {number} [position]
886
+ * @returns {number}
887
+ */
888
+ function writeSync(fd, buffer, offsetOrOptions, length, position) {
889
+ fd = getValidatedFd(fd);
890
+ const ctx = {};
891
+ let result;
892
+
893
+ let offset = offsetOrOptions;
894
+ if (isArrayBufferView(buffer)) {
895
+ if (typeof offset === 'object') {
896
+ ({
897
+ offset = 0,
898
+ length = buffer.byteLength - offset,
899
+ position = null,
900
+ } = offsetOrOptions ?? kEmptyObject);
901
+ }
902
+ if (position === undefined)
903
+ position = null;
904
+ if (offset == null) {
905
+ offset = 0;
906
+ } else {
907
+ validateInteger(offset, 'offset', 0);
908
+ }
909
+ if (typeof length !== 'number')
910
+ length = buffer.byteLength - offset;
911
+ validateOffsetLengthWrite(offset, length, buffer.byteLength);
912
+ result = binding.writeBuffer(fd, buffer, offset, length, position,
913
+ undefined, ctx);
914
+ } else {
915
+ validateStringAfterArrayBufferView(buffer, 'buffer');
916
+ validateEncoding(buffer, length);
917
+
918
+ if (offset === undefined)
919
+ offset = null;
920
+ result = binding.writeString(fd, buffer, offset, length,
921
+ undefined, ctx);
922
+ }
923
+ handleErrorFromBinding(ctx);
924
+ return result;
925
+ }
926
+
927
+ /**
928
+ * Writes an array of `ArrayBufferView`s to the
929
+ * specified `fd` (file descriptor).
930
+ * @param {number} fd
931
+ * @param {ArrayBufferView[]} buffers
932
+ * @param {number | null} [position]
933
+ * @param {(
934
+ * err?: Error,
935
+ * bytesWritten?: number,
936
+ * buffers?: ArrayBufferView[]
937
+ * ) => any} callback
938
+ * @returns {void}
939
+ */
940
+ function writev(fd, buffers, position, callback) {
941
+ function wrapper(err, written) {
942
+ callback(err, written || 0, buffers);
943
+ }
944
+
945
+ fd = getValidatedFd(fd);
946
+ validateBufferArray(buffers);
947
+ callback ||= position;
948
+ validateFunction(callback, 'cb');
949
+
950
+ if (buffers.length === 0) {
951
+ process.nextTick(callback, null, 0, buffers);
952
+ return;
953
+ }
954
+
955
+ const req = new FSReqCallback();
956
+ req.oncomplete = wrapper;
957
+
958
+ if (typeof position !== 'number')
959
+ position = null;
960
+
961
+ binding.writeBuffers(fd, buffers, position, req);
962
+ }
963
+
964
+ ObjectDefineProperty(writev, kCustomPromisifyArgsSymbol, {
965
+ __proto__: null,
966
+ value: ['bytesWritten', 'buffer'],
967
+ enumerable: false,
968
+ });
969
+
970
+ /**
971
+ * Synchronously writes an array of `ArrayBufferView`s
972
+ * to the specified `fd` (file descriptor).
973
+ * @param {number} fd
974
+ * @param {ArrayBufferView[]} buffers
975
+ * @param {number | null} [position]
976
+ * @returns {number}
977
+ */
978
+ function writevSync(fd, buffers, position) {
979
+ fd = getValidatedFd(fd);
980
+ validateBufferArray(buffers);
981
+
982
+ if (buffers.length === 0) {
983
+ return 0;
984
+ }
985
+
986
+ if (typeof position !== 'number')
987
+ position = null;
988
+
989
+ return binding.writeBuffers(fd, buffers, position);
990
+ }
991
+
992
+ /**
993
+ * Asynchronously renames file at `oldPath` to
994
+ * the pathname provided as `newPath`.
995
+ * @param {string | Buffer | URL} oldPath
996
+ * @param {string | Buffer | URL} newPath
997
+ * @param {(err?: Error) => any} callback
998
+ * @returns {void}
999
+ */
1000
+ function rename(oldPath, newPath, callback) {
1001
+ callback = makeCallback(callback);
1002
+ const req = new FSReqCallback();
1003
+ req.oncomplete = callback;
1004
+ binding.rename(
1005
+ getValidatedPath(oldPath, 'oldPath'),
1006
+ getValidatedPath(newPath, 'newPath'),
1007
+ req,
1008
+ );
1009
+ }
1010
+
1011
+
1012
+ /**
1013
+ * Synchronously renames file at `oldPath` to
1014
+ * the pathname provided as `newPath`.
1015
+ * @param {string | Buffer | URL} oldPath
1016
+ * @param {string | Buffer | URL} newPath
1017
+ * @returns {void}
1018
+ */
1019
+ function renameSync(oldPath, newPath) {
1020
+ binding.rename(
1021
+ getValidatedPath(oldPath, 'oldPath'),
1022
+ getValidatedPath(newPath, 'newPath'),
1023
+ );
1024
+ }
1025
+
1026
+ /**
1027
+ * Truncates the file.
1028
+ * @param {string | Buffer | URL} path
1029
+ * @param {number} [len]
1030
+ * @param {(err?: Error) => any} callback
1031
+ * @returns {void}
1032
+ */
1033
+ function truncate(path, len, callback) {
1034
+ if (typeof path === 'number') {
1035
+ showTruncateDeprecation();
1036
+ return fs.ftruncate(path, len, callback);
1037
+ }
1038
+ if (typeof len === 'function') {
1039
+ callback = len;
1040
+ len = 0;
1041
+ } else if (len === undefined) {
1042
+ len = 0;
1043
+ }
1044
+
1045
+ validateInteger(len, 'len');
1046
+ len = MathMax(0, len);
1047
+ validateFunction(callback, 'cb');
1048
+ fs.open(path, 'r+', (er, fd) => {
1049
+ if (er) return callback(er);
1050
+ const req = new FSReqCallback();
1051
+ req.oncomplete = function oncomplete(er) {
1052
+ fs.close(fd, (er2) => {
1053
+ callback(aggregateTwoErrors(er2, er));
1054
+ });
1055
+ };
1056
+ binding.ftruncate(fd, len, req);
1057
+ });
1058
+ }
1059
+
1060
+ /**
1061
+ * Synchronously truncates the file.
1062
+ * @param {string | Buffer | URL} path
1063
+ * @param {number} [len]
1064
+ * @returns {void}
1065
+ */
1066
+ function truncateSync(path, len) {
1067
+ if (typeof path === 'number') {
1068
+ // legacy
1069
+ showTruncateDeprecation();
1070
+ return fs.ftruncateSync(path, len);
1071
+ }
1072
+ if (len === undefined) {
1073
+ len = 0;
1074
+ }
1075
+ // Allow error to be thrown, but still close fd.
1076
+ const fd = fs.openSync(path, 'r+');
1077
+ try {
1078
+ fs.ftruncateSync(fd, len);
1079
+ } finally {
1080
+ fs.closeSync(fd);
1081
+ }
1082
+ }
1083
+
1084
+ /**
1085
+ * Truncates the file descriptor.
1086
+ * @param {number} fd
1087
+ * @param {number} [len]
1088
+ * @param {(err?: Error) => any} callback
1089
+ * @returns {void}
1090
+ */
1091
+ function ftruncate(fd, len = 0, callback) {
1092
+ if (typeof len === 'function') {
1093
+ callback = len;
1094
+ len = 0;
1095
+ }
1096
+ validateInteger(len, 'len');
1097
+ len = MathMax(0, len);
1098
+ callback = makeCallback(callback);
1099
+
1100
+ const req = new FSReqCallback();
1101
+ req.oncomplete = callback;
1102
+ binding.ftruncate(fd, len, req);
1103
+ }
1104
+
1105
+ /**
1106
+ * Synchronously truncates the file descriptor.
1107
+ * @param {number} fd
1108
+ * @param {number} [len]
1109
+ * @returns {void}
1110
+ */
1111
+ function ftruncateSync(fd, len = 0) {
1112
+ validateInteger(len, 'len');
1113
+ binding.ftruncate(fd, len < 0 ? 0 : len);
1114
+ }
1115
+
1116
+ function lazyLoadCp() {
1117
+ if (cpFn === undefined) {
1118
+ ({ cpFn } = require('internal/fs/cp/cp'));
1119
+ cpFn = require('util').callbackify(cpFn);
1120
+ ({ cpSyncFn } = require('internal/fs/cp/cp-sync'));
1121
+ }
1122
+ }
1123
+
1124
+ function lazyLoadRimraf() {
1125
+ if (rimraf === undefined)
1126
+ ({ rimraf, rimrafSync } = require('internal/fs/rimraf'));
1127
+ }
1128
+
1129
+ /**
1130
+ * Asynchronously removes a directory.
1131
+ * @param {string | Buffer | URL} path
1132
+ * @param {{
1133
+ * maxRetries?: number;
1134
+ * recursive?: boolean;
1135
+ * retryDelay?: number;
1136
+ * }} [options]
1137
+ * @param {(err?: Error) => any} callback
1138
+ * @returns {void}
1139
+ */
1140
+ function rmdir(path, options, callback) {
1141
+ if (typeof options === 'function') {
1142
+ callback = options;
1143
+ options = undefined;
1144
+ }
1145
+
1146
+ callback = makeCallback(callback);
1147
+ path = getValidatedPath(path);
1148
+
1149
+ if (options?.recursive) {
1150
+ emitRecursiveRmdirWarning();
1151
+ validateRmOptions(
1152
+ path,
1153
+ { ...options, force: false },
1154
+ true,
1155
+ (err, options) => {
1156
+ if (err === false) {
1157
+ const req = new FSReqCallback();
1158
+ req.oncomplete = callback;
1159
+ binding.rmdir(path, req);
1160
+ return;
1161
+ }
1162
+ if (err) {
1163
+ return callback(err);
1164
+ }
1165
+
1166
+ lazyLoadRimraf();
1167
+ rimraf(path, options, callback);
1168
+ });
1169
+ } else {
1170
+ validateRmdirOptions(options);
1171
+ const req = new FSReqCallback();
1172
+ req.oncomplete = callback;
1173
+ binding.rmdir(path, req);
1174
+ }
1175
+ }
1176
+
1177
+ /**
1178
+ * Synchronously removes a directory.
1179
+ * @param {string | Buffer | URL} path
1180
+ * @param {{
1181
+ * maxRetries?: number;
1182
+ * recursive?: boolean;
1183
+ * retryDelay?: number;
1184
+ * }} [options]
1185
+ * @returns {void}
1186
+ */
1187
+ function rmdirSync(path, options) {
1188
+ path = getValidatedPath(path);
1189
+
1190
+ if (options?.recursive) {
1191
+ emitRecursiveRmdirWarning();
1192
+ options = validateRmOptionsSync(path, { ...options, force: false }, true);
1193
+ if (options !== false) {
1194
+ lazyLoadRimraf();
1195
+ return rimrafSync(path, options);
1196
+ }
1197
+ } else {
1198
+ validateRmdirOptions(options);
1199
+ }
1200
+
1201
+ binding.rmdir(path);
1202
+ }
1203
+
1204
+ /**
1205
+ * Asynchronously removes files and
1206
+ * directories (modeled on the standard POSIX `rm` utility).
1207
+ * @param {string | Buffer | URL} path
1208
+ * @param {{
1209
+ * force?: boolean;
1210
+ * maxRetries?: number;
1211
+ * recursive?: boolean;
1212
+ * retryDelay?: number;
1213
+ * }} [options]
1214
+ * @param {(err?: Error) => any} callback
1215
+ * @returns {void}
1216
+ */
1217
+ function rm(path, options, callback) {
1218
+ if (typeof options === 'function') {
1219
+ callback = options;
1220
+ options = undefined;
1221
+ }
1222
+ path = getValidatedPath(path);
1223
+
1224
+ validateRmOptions(path, options, false, (err, options) => {
1225
+ if (err) {
1226
+ return callback(err);
1227
+ }
1228
+ lazyLoadRimraf();
1229
+ return rimraf(path, options, callback);
1230
+ });
1231
+ }
1232
+
1233
+ /**
1234
+ * Synchronously removes files and
1235
+ * directories (modeled on the standard POSIX `rm` utility).
1236
+ * @param {string | Buffer | URL} path
1237
+ * @param {{
1238
+ * force?: boolean;
1239
+ * maxRetries?: number;
1240
+ * recursive?: boolean;
1241
+ * retryDelay?: number;
1242
+ * }} [options]
1243
+ * @returns {void}
1244
+ */
1245
+ function rmSync(path, options) {
1246
+ lazyLoadRimraf();
1247
+ return rimrafSync(
1248
+ getValidatedPath(path),
1249
+ validateRmOptionsSync(path, options, false),
1250
+ );
1251
+ }
1252
+
1253
+ /**
1254
+ * Forces all currently queued I/O operations associated
1255
+ * with the file to the operating system's synchronized
1256
+ * I/O completion state.
1257
+ * @param {number} fd
1258
+ * @param {(err?: Error) => any} callback
1259
+ * @returns {void}
1260
+ */
1261
+ function fdatasync(fd, callback) {
1262
+ const req = new FSReqCallback();
1263
+ req.oncomplete = makeCallback(callback);
1264
+ binding.fdatasync(fd, req);
1265
+ }
1266
+
1267
+ /**
1268
+ * Synchronously forces all currently queued I/O operations
1269
+ * associated with the file to the operating
1270
+ * system's synchronized I/O completion state.
1271
+ * @param {number} fd
1272
+ * @returns {void}
1273
+ */
1274
+ function fdatasyncSync(fd) {
1275
+ binding.fdatasync(fd);
1276
+ }
1277
+
1278
+ /**
1279
+ * Requests for all data for the open file descriptor
1280
+ * to be flushed to the storage device.
1281
+ * @param {number} fd
1282
+ * @param {(err?: Error) => any} callback
1283
+ * @returns {void}
1284
+ */
1285
+ function fsync(fd, callback) {
1286
+ const req = new FSReqCallback();
1287
+ req.oncomplete = makeCallback(callback);
1288
+ binding.fsync(fd, req);
1289
+ }
1290
+
1291
+ /**
1292
+ * Synchronously requests for all data for the open
1293
+ * file descriptor to be flushed to the storage device.
1294
+ * @param {number} fd
1295
+ * @returns {void}
1296
+ */
1297
+ function fsyncSync(fd) {
1298
+ binding.fsync(fd);
1299
+ }
1300
+
1301
+ /**
1302
+ * Asynchronously creates a directory.
1303
+ * @param {string | Buffer | URL} path
1304
+ * @param {{
1305
+ * recursive?: boolean;
1306
+ * mode?: string | number;
1307
+ * } | number} [options]
1308
+ * @param {(err?: Error) => any} callback
1309
+ * @returns {void}
1310
+ */
1311
+ function mkdir(path, options, callback) {
1312
+ let mode = 0o777;
1313
+ let recursive = false;
1314
+ if (typeof options === 'function') {
1315
+ callback = options;
1316
+ } else if (typeof options === 'number' || typeof options === 'string') {
1317
+ mode = parseFileMode(options, 'mode');
1318
+ } else if (options) {
1319
+ if (options.recursive !== undefined) {
1320
+ recursive = options.recursive;
1321
+ validateBoolean(recursive, 'options.recursive');
1322
+ }
1323
+ if (options.mode !== undefined) {
1324
+ mode = parseFileMode(options.mode, 'options.mode');
1325
+ }
1326
+ }
1327
+ callback = makeCallback(callback);
1328
+
1329
+ const req = new FSReqCallback();
1330
+ req.oncomplete = callback;
1331
+ binding.mkdir(
1332
+ getValidatedPath(path),
1333
+ mode,
1334
+ recursive,
1335
+ req,
1336
+ );
1337
+ }
1338
+
1339
+ /**
1340
+ * Synchronously creates a directory.
1341
+ * @param {string | Buffer | URL} path
1342
+ * @param {{
1343
+ * recursive?: boolean;
1344
+ * mode?: string | number;
1345
+ * } | number} [options]
1346
+ * @returns {string | void}
1347
+ */
1348
+ function mkdirSync(path, options) {
1349
+ let mode = 0o777;
1350
+ let recursive = false;
1351
+ if (typeof options === 'number' || typeof options === 'string') {
1352
+ mode = parseFileMode(options, 'mode');
1353
+ } else if (options) {
1354
+ if (options.recursive !== undefined) {
1355
+ recursive = options.recursive;
1356
+ validateBoolean(recursive, 'options.recursive');
1357
+ }
1358
+ if (options.mode !== undefined) {
1359
+ mode = parseFileMode(options.mode, 'options.mode');
1360
+ }
1361
+ }
1362
+
1363
+ const result = binding.mkdir(
1364
+ getValidatedPath(path),
1365
+ mode,
1366
+ recursive,
1367
+ );
1368
+
1369
+ if (recursive) {
1370
+ return result;
1371
+ }
1372
+ }
1373
+
1374
+ /*
1375
+ * An recursive algorithm for reading the entire contents of the `basePath` directory.
1376
+ * This function does not validate `basePath` as a directory. It is passed directly to
1377
+ * `binding.readdir`.
1378
+ * @param {string} basePath
1379
+ * @param {{ encoding: string, withFileTypes: boolean }} options
1380
+ * @param {(
1381
+ * err?: Error,
1382
+ * files?: string[] | Buffer[] | Dirent[]
1383
+ * ) => any} callback
1384
+ * @returns {void}
1385
+ */
1386
+ function readdirRecursive(basePath, options, callback) {
1387
+ const context = {
1388
+ withFileTypes: Boolean(options.withFileTypes),
1389
+ encoding: options.encoding,
1390
+ basePath,
1391
+ readdirResults: [],
1392
+ pathsQueue: [basePath],
1393
+ };
1394
+
1395
+ let i = 0;
1396
+
1397
+ function read(path) {
1398
+ const req = new FSReqCallback();
1399
+ req.oncomplete = (err, result) => {
1400
+ if (err) {
1401
+ callback(err);
1402
+ return;
1403
+ }
1404
+
1405
+ if (result === undefined) {
1406
+ callback(null, context.readdirResults);
1407
+ return;
1408
+ }
1409
+
1410
+ processReaddirResult({
1411
+ result,
1412
+ currentPath: path,
1413
+ context,
1414
+ });
1415
+
1416
+ if (i < context.pathsQueue.length) {
1417
+ read(context.pathsQueue[i++]);
1418
+ } else {
1419
+ callback(null, context.readdirResults);
1420
+ }
1421
+ };
1422
+
1423
+ binding.readdir(
1424
+ path,
1425
+ context.encoding,
1426
+ context.withFileTypes,
1427
+ req,
1428
+ );
1429
+ }
1430
+
1431
+ read(context.pathsQueue[i++]);
1432
+ }
1433
+
1434
+ // Calling `readdir` with `withFileTypes=true`, the result is an array of arrays.
1435
+ // The first array is the names, and the second array is the types.
1436
+ // They are guaranteed to be the same length; hence, setting `length` to the length
1437
+ // of the first array within the result.
1438
+ const processReaddirResult = (args) => (args.context.withFileTypes ? handleDirents(args) : handleFilePaths(args));
1439
+
1440
+ function handleDirents({ result, currentPath, context }) {
1441
+ const { 0: names, 1: types } = result;
1442
+ const { length } = names;
1443
+
1444
+ for (let i = 0; i < length; i++) {
1445
+ // Avoid excluding symlinks, as they are not directories.
1446
+ // Refs: https://github.com/nodejs/node/issues/52663
1447
+ const fullPath = pathModule.join(currentPath, names[i]);
1448
+ const dirent = getDirent(currentPath, names[i], types[i]);
1449
+ ArrayPrototypePush(context.readdirResults, dirent);
1450
+
1451
+ if (dirent.isDirectory() || binding.internalModuleStat(fullPath) === 1) {
1452
+ ArrayPrototypePush(context.pathsQueue, fullPath);
1453
+ }
1454
+ }
1455
+ }
1456
+
1457
+ function handleFilePaths({ result, currentPath, context }) {
1458
+ for (let i = 0; i < result.length; i++) {
1459
+ const resultPath = pathModule.join(currentPath, result[i]);
1460
+ const relativeResultPath = pathModule.relative(context.basePath, resultPath);
1461
+ const stat = binding.internalModuleStat(resultPath);
1462
+ ArrayPrototypePush(context.readdirResults, relativeResultPath);
1463
+
1464
+ if (stat === 1) {
1465
+ ArrayPrototypePush(context.pathsQueue, resultPath);
1466
+ }
1467
+ }
1468
+ }
1469
+
1470
+ /**
1471
+ * An iterative algorithm for reading the entire contents of the `basePath` directory.
1472
+ * This function does not validate `basePath` as a directory. It is passed directly to
1473
+ * `binding.readdir`.
1474
+ * @param {string} basePath
1475
+ * @param {{ encoding: string, withFileTypes: boolean }} options
1476
+ * @returns {string[] | Dirent[]}
1477
+ */
1478
+ function readdirSyncRecursive(basePath, options) {
1479
+ const context = {
1480
+ withFileTypes: Boolean(options.withFileTypes),
1481
+ encoding: options.encoding,
1482
+ basePath,
1483
+ readdirResults: [],
1484
+ pathsQueue: [basePath],
1485
+ };
1486
+
1487
+ function read(path) {
1488
+ const readdirResult = binding.readdir(
1489
+ path,
1490
+ context.encoding,
1491
+ context.withFileTypes,
1492
+ );
1493
+
1494
+ if (readdirResult === undefined) {
1495
+ return;
1496
+ }
1497
+
1498
+ processReaddirResult({
1499
+ result: readdirResult,
1500
+ currentPath: path,
1501
+ context,
1502
+ });
1503
+ }
1504
+
1505
+ for (let i = 0; i < context.pathsQueue.length; i++) {
1506
+ read(context.pathsQueue[i]);
1507
+ }
1508
+
1509
+ return context.readdirResults;
1510
+ }
1511
+
1512
+ /**
1513
+ * Reads the contents of a directory.
1514
+ * @param {string | Buffer | URL} path
1515
+ * @param {string | {
1516
+ * encoding?: string;
1517
+ * withFileTypes?: boolean;
1518
+ * recursive?: boolean;
1519
+ * }} [options]
1520
+ * @param {(
1521
+ * err?: Error,
1522
+ * files?: string[] | Buffer[] | Dirent[]
1523
+ * ) => any} callback
1524
+ * @returns {void}
1525
+ */
1526
+ function readdir(path, options, callback) {
1527
+ callback = makeCallback(typeof options === 'function' ? options : callback);
1528
+ options = getOptions(options);
1529
+ path = getValidatedPath(path);
1530
+ if (options.recursive != null) {
1531
+ validateBoolean(options.recursive, 'options.recursive');
1532
+ }
1533
+
1534
+ if (options.recursive) {
1535
+ // Make shallow copy to prevent mutating options from affecting results
1536
+ options = copyObject(options);
1537
+
1538
+ readdirRecursive(path, options, callback);
1539
+ return;
1540
+ }
1541
+
1542
+ const req = new FSReqCallback();
1543
+ if (!options.withFileTypes) {
1544
+ req.oncomplete = callback;
1545
+ } else {
1546
+ req.oncomplete = (err, result) => {
1547
+ if (err) {
1548
+ callback(err);
1549
+ return;
1550
+ }
1551
+ getDirents(path, result, callback);
1552
+ };
1553
+ }
1554
+ binding.readdir(
1555
+ path,
1556
+ options.encoding,
1557
+ !!options.withFileTypes,
1558
+ req,
1559
+ );
1560
+ }
1561
+
1562
+ /**
1563
+ * Synchronously reads the contents of a directory.
1564
+ * @param {string | Buffer | URL} path
1565
+ * @param {string | {
1566
+ * encoding?: string;
1567
+ * withFileTypes?: boolean;
1568
+ * recursive?: boolean;
1569
+ * }} [options]
1570
+ * @returns {string | Buffer[] | Dirent[]}
1571
+ */
1572
+ function readdirSync(path, options) {
1573
+ options = getOptions(options);
1574
+ path = getValidatedPath(path);
1575
+ if (options.recursive != null) {
1576
+ validateBoolean(options.recursive, 'options.recursive');
1577
+ }
1578
+
1579
+ if (options.recursive) {
1580
+ return readdirSyncRecursive(path, options);
1581
+ }
1582
+
1583
+ const result = binding.readdir(
1584
+ path,
1585
+ options.encoding,
1586
+ !!options.withFileTypes,
1587
+ );
1588
+
1589
+ return result !== undefined && options.withFileTypes ? getDirents(path, result) : result;
1590
+ }
1591
+
1592
+ /**
1593
+ * Invokes the callback with the `fs.Stats`
1594
+ * for the file descriptor.
1595
+ * @param {number} fd
1596
+ * @param {{ bigint?: boolean; }} [options]
1597
+ * @param {(
1598
+ * err?: Error,
1599
+ * stats?: Stats
1600
+ * ) => any} [callback]
1601
+ * @returns {void}
1602
+ */
1603
+ function fstat(fd, options = { bigint: false }, callback) {
1604
+ if (typeof options === 'function') {
1605
+ callback = options;
1606
+ options = kEmptyObject;
1607
+ }
1608
+ callback = makeStatsCallback(callback);
1609
+
1610
+ const req = new FSReqCallback(options.bigint);
1611
+ req.oncomplete = callback;
1612
+ binding.fstat(fd, options.bigint, req);
1613
+ }
1614
+
1615
+ /**
1616
+ * Retrieves the `fs.Stats` for the symbolic link
1617
+ * referred to by the `path`.
1618
+ * @param {string | Buffer | URL} path
1619
+ * @param {{ bigint?: boolean; }} [options]
1620
+ * @param {(
1621
+ * err?: Error,
1622
+ * stats?: Stats
1623
+ * ) => any} callback
1624
+ * @returns {void}
1625
+ */
1626
+ function lstat(path, options = { bigint: false }, callback) {
1627
+ if (typeof options === 'function') {
1628
+ callback = options;
1629
+ options = kEmptyObject;
1630
+ }
1631
+ callback = makeStatsCallback(callback);
1632
+ path = getValidatedPath(path);
1633
+ if (permission.isEnabled() && !permission.has('fs.read', path)) {
1634
+ const resource = BufferIsBuffer(path) ? BufferToString(path) : path;
1635
+ callback(new ERR_ACCESS_DENIED('Access to this API has been restricted', 'FileSystemRead', resource));
1636
+ return;
1637
+ }
1638
+
1639
+ const req = new FSReqCallback(options.bigint);
1640
+ req.oncomplete = callback;
1641
+ binding.lstat(path, options.bigint, req);
1642
+ }
1643
+
1644
+ /**
1645
+ * Asynchronously gets the stats of a file.
1646
+ * @param {string | Buffer | URL} path
1647
+ * @param {{ bigint?: boolean; }} [options]
1648
+ * @param {(
1649
+ * err?: Error,
1650
+ * stats?: Stats
1651
+ * ) => any} callback
1652
+ * @returns {void}
1653
+ */
1654
+ function stat(path, options = { bigint: false }, callback) {
1655
+ if (typeof options === 'function') {
1656
+ callback = options;
1657
+ options = kEmptyObject;
1658
+ }
1659
+ callback = makeStatsCallback(callback);
1660
+
1661
+ const req = new FSReqCallback(options.bigint);
1662
+ req.oncomplete = callback;
1663
+ binding.stat(getValidatedPath(path), options.bigint, req);
1664
+ }
1665
+
1666
+ function statfs(path, options = { bigint: false }, callback) {
1667
+ if (typeof options === 'function') {
1668
+ callback = options;
1669
+ options = kEmptyObject;
1670
+ }
1671
+ validateFunction(callback, 'cb');
1672
+ path = getValidatedPath(path);
1673
+ const req = new FSReqCallback(options.bigint);
1674
+ req.oncomplete = (err, stats) => {
1675
+ if (err) {
1676
+ return callback(err);
1677
+ }
1678
+
1679
+ callback(err, getStatFsFromBinding(stats));
1680
+ };
1681
+ binding.statfs(getValidatedPath(path), options.bigint, req);
1682
+ }
1683
+
1684
+ /**
1685
+ * Synchronously retrieves the `fs.Stats` for
1686
+ * the file descriptor.
1687
+ * @param {number} fd
1688
+ * @param {{ bigint?: boolean; }} [options]
1689
+ * @returns {Stats | undefined}
1690
+ */
1691
+ function fstatSync(fd, options = { bigint: false }) {
1692
+ const stats = binding.fstat(fd, options.bigint, undefined, false);
1693
+ if (stats === undefined) {
1694
+ return;
1695
+ }
1696
+ return getStatsFromBinding(stats);
1697
+ }
1698
+
1699
+ /**
1700
+ * Synchronously retrieves the `fs.Stats` for
1701
+ * the symbolic link referred to by the `path`.
1702
+ * @param {string | Buffer | URL} path
1703
+ * @param {{
1704
+ * bigint?: boolean;
1705
+ * throwIfNoEntry?: boolean;
1706
+ * }} [options]
1707
+ * @returns {Stats | undefined}
1708
+ */
1709
+ function lstatSync(path, options = { bigint: false, throwIfNoEntry: true }) {
1710
+ path = getValidatedPath(path);
1711
+ if (permission.isEnabled() && !permission.has('fs.read', path)) {
1712
+ const resource = BufferIsBuffer(path) ? BufferToString(path) : path;
1713
+ throw new ERR_ACCESS_DENIED('Access to this API has been restricted', 'FileSystemRead', resource);
1714
+ }
1715
+ const stats = binding.lstat(
1716
+ getValidatedPath(path),
1717
+ options.bigint,
1718
+ undefined,
1719
+ options.throwIfNoEntry,
1720
+ );
1721
+
1722
+ if (stats === undefined) {
1723
+ return;
1724
+ }
1725
+ return getStatsFromBinding(stats);
1726
+ }
1727
+
1728
+ /**
1729
+ * Synchronously retrieves the `fs.Stats`
1730
+ * for the `path`.
1731
+ * @param {string | Buffer | URL} path
1732
+ * @param {{
1733
+ * bigint?: boolean;
1734
+ * throwIfNoEntry?: boolean;
1735
+ * }} [options]
1736
+ * @returns {Stats}
1737
+ */
1738
+ function statSync(path, options = { bigint: false, throwIfNoEntry: true }) {
1739
+ const stats = binding.stat(
1740
+ getValidatedPath(path),
1741
+ options.bigint,
1742
+ undefined,
1743
+ options.throwIfNoEntry,
1744
+ );
1745
+ if (stats === undefined) {
1746
+ return undefined;
1747
+ }
1748
+ return getStatsFromBinding(stats);
1749
+ }
1750
+
1751
+ function statfsSync(path, options = { bigint: false }) {
1752
+ const stats = binding.statfs(getValidatedPath(path), options.bigint);
1753
+ return getStatFsFromBinding(stats);
1754
+ }
1755
+
1756
+ /**
1757
+ * Reads the contents of a symbolic link
1758
+ * referred to by `path`.
1759
+ * @param {string | Buffer | URL} path
1760
+ * @param {{ encoding?: string; } | string} [options]
1761
+ * @param {(
1762
+ * err?: Error,
1763
+ * linkString?: string | Buffer
1764
+ * ) => any} callback
1765
+ * @returns {void}
1766
+ */
1767
+ function readlink(path, options, callback) {
1768
+ callback = makeCallback(typeof options === 'function' ? options : callback);
1769
+ options = getOptions(options);
1770
+ const req = new FSReqCallback();
1771
+ req.oncomplete = callback;
1772
+ binding.readlink(getValidatedPath(path), options.encoding, req);
1773
+ }
1774
+
1775
+ /**
1776
+ * Synchronously reads the contents of a symbolic link
1777
+ * referred to by `path`.
1778
+ * @param {string | Buffer | URL} path
1779
+ * @param {{ encoding?: string; } | string} [options]
1780
+ * @returns {string | Buffer}
1781
+ */
1782
+ function readlinkSync(path, options) {
1783
+ options = getOptions(options);
1784
+ return binding.readlink(getValidatedPath(path), options.encoding);
1785
+ }
1786
+
1787
+ /**
1788
+ * Creates the link called `path` pointing to `target`.
1789
+ * @param {string | Buffer | URL} target
1790
+ * @param {string | Buffer | URL} path
1791
+ * @param {string | null} [type_]
1792
+ * @param {(err?: Error) => any} callback_
1793
+ * @returns {void}
1794
+ */
1795
+ function symlink(target, path, type_, callback_) {
1796
+ const type = (typeof type_ === 'string' ? type_ : null);
1797
+ const callback = makeCallback(arguments[arguments.length - 1]);
1798
+
1799
+ if (permission.isEnabled()) {
1800
+ // The permission model's security guarantees fall apart in the presence of
1801
+ // relative symbolic links. Thus, we have to prevent their creation.
1802
+ if (BufferIsBuffer(target)) {
1803
+ if (!isAbsolute(BufferToString(target))) {
1804
+ callback(new ERR_ACCESS_DENIED('relative symbolic link target'));
1805
+ return;
1806
+ }
1807
+ } else if (typeof target !== 'string' || !isAbsolute(toPathIfFileURL(target))) {
1808
+ callback(new ERR_ACCESS_DENIED('relative symbolic link target'));
1809
+ return;
1810
+ }
1811
+ }
1812
+
1813
+ target = getValidatedPath(target, 'target');
1814
+ path = getValidatedPath(path);
1815
+
1816
+ if (isWindows && type === null) {
1817
+ let absoluteTarget;
1818
+ try {
1819
+ // Symlinks targets can be relative to the newly created path.
1820
+ // Calculate absolute file name of the symlink target, and check
1821
+ // if it is a directory. Ignore resolve error to keep symlink
1822
+ // errors consistent between platforms if invalid path is
1823
+ // provided.
1824
+ absoluteTarget = pathModule.resolve(path, '..', target);
1825
+ } catch {
1826
+ // Continue regardless of error.
1827
+ }
1828
+ if (absoluteTarget !== undefined) {
1829
+ stat(absoluteTarget, (err, stat) => {
1830
+ const resolvedType = !err && stat.isDirectory() ? 'dir' : 'file';
1831
+ const resolvedFlags = stringToSymlinkType(resolvedType);
1832
+ const destination = preprocessSymlinkDestination(target,
1833
+ resolvedType,
1834
+ path);
1835
+
1836
+ const req = new FSReqCallback();
1837
+ req.oncomplete = callback;
1838
+ binding.symlink(
1839
+ destination,
1840
+ path,
1841
+ resolvedFlags,
1842
+ req,
1843
+ );
1844
+ });
1845
+ return;
1846
+ }
1847
+ }
1848
+
1849
+ const destination = preprocessSymlinkDestination(target, type, path);
1850
+
1851
+ const flags = stringToSymlinkType(type);
1852
+ const req = new FSReqCallback();
1853
+ req.oncomplete = callback;
1854
+ binding.symlink(destination, path, flags, req);
1855
+ }
1856
+
1857
+ /**
1858
+ * Synchronously creates the link called `path`
1859
+ * pointing to `target`.
1860
+ * @param {string | Buffer | URL} target
1861
+ * @param {string | Buffer | URL} path
1862
+ * @param {string | null} [type]
1863
+ * @returns {void}
1864
+ */
1865
+ function symlinkSync(target, path, type) {
1866
+ type = (typeof type === 'string' ? type : null);
1867
+ if (isWindows && type === null) {
1868
+ const absoluteTarget = pathModule.resolve(`${path}`, '..', `${target}`);
1869
+ if (statSync(absoluteTarget, { throwIfNoEntry: false })?.isDirectory()) {
1870
+ type = 'dir';
1871
+ }
1872
+ }
1873
+
1874
+ if (permission.isEnabled()) {
1875
+ // The permission model's security guarantees fall apart in the presence of
1876
+ // relative symbolic links. Thus, we have to prevent their creation.
1877
+ if (BufferIsBuffer(target)) {
1878
+ if (!isAbsolute(BufferToString(target))) {
1879
+ throw new ERR_ACCESS_DENIED('relative symbolic link target');
1880
+ }
1881
+ } else if (typeof target !== 'string' || !isAbsolute(toPathIfFileURL(target))) {
1882
+ throw new ERR_ACCESS_DENIED('relative symbolic link target');
1883
+ }
1884
+ }
1885
+
1886
+ target = getValidatedPath(target, 'target');
1887
+ path = getValidatedPath(path);
1888
+
1889
+ binding.symlink(
1890
+ preprocessSymlinkDestination(target, type, path),
1891
+ path,
1892
+ stringToSymlinkType(type),
1893
+ );
1894
+ }
1895
+
1896
+ /**
1897
+ * Creates a new link from the `existingPath`
1898
+ * to the `newPath`.
1899
+ * @param {string | Buffer | URL} existingPath
1900
+ * @param {string | Buffer | URL} newPath
1901
+ * @param {(err?: Error) => any} callback
1902
+ * @returns {void}
1903
+ */
1904
+ function link(existingPath, newPath, callback) {
1905
+ callback = makeCallback(callback);
1906
+
1907
+ existingPath = getValidatedPath(existingPath, 'existingPath');
1908
+ newPath = getValidatedPath(newPath, 'newPath');
1909
+
1910
+ const req = new FSReqCallback();
1911
+ req.oncomplete = callback;
1912
+
1913
+ binding.link(existingPath, newPath, req);
1914
+ }
1915
+
1916
+ /**
1917
+ * Synchronously creates a new link from the `existingPath`
1918
+ * to the `newPath`.
1919
+ * @param {string | Buffer | URL} existingPath
1920
+ * @param {string | Buffer | URL} newPath
1921
+ * @returns {void}
1922
+ */
1923
+ function linkSync(existingPath, newPath) {
1924
+ existingPath = getValidatedPath(existingPath, 'existingPath');
1925
+ newPath = getValidatedPath(newPath, 'newPath');
1926
+
1927
+ binding.link(
1928
+ existingPath,
1929
+ newPath,
1930
+ );
1931
+ }
1932
+
1933
+ /**
1934
+ * Asynchronously removes a file or symbolic link.
1935
+ * @param {string | Buffer | URL} path
1936
+ * @param {(err?: Error) => any} callback
1937
+ * @returns {void}
1938
+ */
1939
+ function unlink(path, callback) {
1940
+ callback = makeCallback(callback);
1941
+ const req = new FSReqCallback();
1942
+ req.oncomplete = callback;
1943
+ binding.unlink(getValidatedPath(path), req);
1944
+ }
1945
+
1946
+ /**
1947
+ * Synchronously removes a file or symbolic link.
1948
+ * @param {string | Buffer | URL} path
1949
+ * @returns {void}
1950
+ */
1951
+ function unlinkSync(path) {
1952
+ binding.unlink(getValidatedPath(path));
1953
+ }
1954
+
1955
+ /**
1956
+ * Sets the permissions on the file.
1957
+ * @param {number} fd
1958
+ * @param {string | number} mode
1959
+ * @param {(err?: Error) => any} callback
1960
+ * @returns {void}
1961
+ */
1962
+ function fchmod(fd, mode, callback) {
1963
+ mode = parseFileMode(mode, 'mode');
1964
+ callback = makeCallback(callback);
1965
+
1966
+ if (permission.isEnabled()) {
1967
+ callback(new ERR_ACCESS_DENIED('fchmod API is disabled when Permission Model is enabled.'));
1968
+ return;
1969
+ }
1970
+
1971
+ const req = new FSReqCallback();
1972
+ req.oncomplete = callback;
1973
+ binding.fchmod(fd, mode, req);
1974
+ }
1975
+
1976
+ /**
1977
+ * Synchronously sets the permissions on the file.
1978
+ * @param {number} fd
1979
+ * @param {string | number} mode
1980
+ * @returns {void}
1981
+ */
1982
+ function fchmodSync(fd, mode) {
1983
+ if (permission.isEnabled()) {
1984
+ throw new ERR_ACCESS_DENIED('fchmod API is disabled when Permission Model is enabled.');
1985
+ }
1986
+ binding.fchmod(
1987
+ fd,
1988
+ parseFileMode(mode, 'mode'),
1989
+ );
1990
+ }
1991
+
1992
+ /**
1993
+ * Changes the permissions on a symbolic link.
1994
+ * @param {string | Buffer | URL} path
1995
+ * @param {number} mode
1996
+ * @param {(err?: Error) => any} callback
1997
+ * @returns {void}
1998
+ */
1999
+ function lchmod(path, mode, callback) {
2000
+ validateFunction(callback, 'cb');
2001
+ mode = parseFileMode(mode, 'mode');
2002
+ fs.open(path, O_WRONLY | O_SYMLINK, (err, fd) => {
2003
+ if (err) {
2004
+ callback(err);
2005
+ return;
2006
+ }
2007
+ // Prefer to return the chmod error, if one occurs,
2008
+ // but still try to close, and report closing errors if they occur.
2009
+ fs.fchmod(fd, mode, (err) => {
2010
+ fs.close(fd, (err2) => {
2011
+ callback(aggregateTwoErrors(err2, err));
2012
+ });
2013
+ });
2014
+ });
2015
+ }
2016
+
2017
+ /**
2018
+ * Synchronously changes the permissions on a symbolic link.
2019
+ * @param {string | Buffer | URL} path
2020
+ * @param {number} mode
2021
+ * @returns {void}
2022
+ */
2023
+ function lchmodSync(path, mode) {
2024
+ const fd = fs.openSync(path, O_WRONLY | O_SYMLINK);
2025
+
2026
+ // Prefer to return the chmod error, if one occurs,
2027
+ // but still try to close, and report closing errors if they occur.
2028
+ try {
2029
+ fs.fchmodSync(fd, mode);
2030
+ } finally {
2031
+ fs.closeSync(fd);
2032
+ }
2033
+ }
2034
+
2035
+ /**
2036
+ * Asynchronously changes the permissions of a file.
2037
+ * @param {string | Buffer | URL} path
2038
+ * @param {string | number} mode
2039
+ * @param {(err?: Error) => any} callback
2040
+ * @returns {void}
2041
+ */
2042
+ function chmod(path, mode, callback) {
2043
+ path = getValidatedPath(path);
2044
+ mode = parseFileMode(mode, 'mode');
2045
+ callback = makeCallback(callback);
2046
+
2047
+ const req = new FSReqCallback();
2048
+ req.oncomplete = callback;
2049
+ binding.chmod(path, mode, req);
2050
+ }
2051
+
2052
+ /**
2053
+ * Synchronously changes the permissions of a file.
2054
+ * @param {string | Buffer | URL} path
2055
+ * @param {string | number} mode
2056
+ * @returns {void}
2057
+ */
2058
+ function chmodSync(path, mode) {
2059
+ path = getValidatedPath(path);
2060
+ mode = parseFileMode(mode, 'mode');
2061
+
2062
+ binding.chmod(path, mode);
2063
+ }
2064
+
2065
+ /**
2066
+ * Sets the owner of the symbolic link.
2067
+ * @param {string | Buffer | URL} path
2068
+ * @param {number} uid
2069
+ * @param {number} gid
2070
+ * @param {(err?: Error) => any} callback
2071
+ * @returns {void}
2072
+ */
2073
+ function lchown(path, uid, gid, callback) {
2074
+ callback = makeCallback(callback);
2075
+ path = getValidatedPath(path);
2076
+ validateInteger(uid, 'uid', -1, kMaxUserId);
2077
+ validateInteger(gid, 'gid', -1, kMaxUserId);
2078
+ const req = new FSReqCallback();
2079
+ req.oncomplete = callback;
2080
+ binding.lchown(path, uid, gid, req);
2081
+ }
2082
+
2083
+ /**
2084
+ * Synchronously sets the owner of the symbolic link.
2085
+ * @param {string | Buffer | URL} path
2086
+ * @param {number} uid
2087
+ * @param {number} gid
2088
+ * @returns {void}
2089
+ */
2090
+ function lchownSync(path, uid, gid) {
2091
+ path = getValidatedPath(path);
2092
+ validateInteger(uid, 'uid', -1, kMaxUserId);
2093
+ validateInteger(gid, 'gid', -1, kMaxUserId);
2094
+ binding.lchown(path, uid, gid);
2095
+ }
2096
+
2097
+ /**
2098
+ * Sets the owner of the file.
2099
+ * @param {number} fd
2100
+ * @param {number} uid
2101
+ * @param {number} gid
2102
+ * @param {(err?: Error) => any} callback
2103
+ * @returns {void}
2104
+ */
2105
+ function fchown(fd, uid, gid, callback) {
2106
+ validateInteger(uid, 'uid', -1, kMaxUserId);
2107
+ validateInteger(gid, 'gid', -1, kMaxUserId);
2108
+ callback = makeCallback(callback);
2109
+ if (permission.isEnabled()) {
2110
+ callback(new ERR_ACCESS_DENIED('fchown API is disabled when Permission Model is enabled.'));
2111
+ return;
2112
+ }
2113
+
2114
+ const req = new FSReqCallback();
2115
+ req.oncomplete = callback;
2116
+ binding.fchown(fd, uid, gid, req);
2117
+ }
2118
+
2119
+ /**
2120
+ * Synchronously sets the owner of the file.
2121
+ * @param {number} fd
2122
+ * @param {number} uid
2123
+ * @param {number} gid
2124
+ * @returns {void}
2125
+ */
2126
+ function fchownSync(fd, uid, gid) {
2127
+ validateInteger(uid, 'uid', -1, kMaxUserId);
2128
+ validateInteger(gid, 'gid', -1, kMaxUserId);
2129
+ if (permission.isEnabled()) {
2130
+ throw new ERR_ACCESS_DENIED('fchown API is disabled when Permission Model is enabled.');
2131
+ }
2132
+
2133
+ binding.fchown(fd, uid, gid);
2134
+ }
2135
+
2136
+ /**
2137
+ * Asynchronously changes the owner and group
2138
+ * of a file.
2139
+ * @param {string | Buffer | URL} path
2140
+ * @param {number} uid
2141
+ * @param {number} gid
2142
+ * @param {(err?: Error) => any} callback
2143
+ * @returns {void}
2144
+ */
2145
+ function chown(path, uid, gid, callback) {
2146
+ callback = makeCallback(callback);
2147
+ path = getValidatedPath(path);
2148
+ validateInteger(uid, 'uid', -1, kMaxUserId);
2149
+ validateInteger(gid, 'gid', -1, kMaxUserId);
2150
+
2151
+ const req = new FSReqCallback();
2152
+ req.oncomplete = callback;
2153
+ binding.chown(path, uid, gid, req);
2154
+ }
2155
+
2156
+ /**
2157
+ * Synchronously changes the owner and group
2158
+ * of a file.
2159
+ * @param {string | Buffer | URL} path
2160
+ * @param {number} uid
2161
+ * @param {number} gid
2162
+ * @returns {void}
2163
+ */
2164
+ function chownSync(path, uid, gid) {
2165
+ path = getValidatedPath(path);
2166
+ validateInteger(uid, 'uid', -1, kMaxUserId);
2167
+ validateInteger(gid, 'gid', -1, kMaxUserId);
2168
+ binding.chown(path, uid, gid);
2169
+ }
2170
+
2171
+ /**
2172
+ * Changes the file system timestamps of the object
2173
+ * referenced by `path`.
2174
+ * @param {string | Buffer | URL} path
2175
+ * @param {number | string | Date} atime
2176
+ * @param {number | string | Date} mtime
2177
+ * @param {(err?: Error) => any} callback
2178
+ * @returns {void}
2179
+ */
2180
+ function utimes(path, atime, mtime, callback) {
2181
+ callback = makeCallback(callback);
2182
+ path = getValidatedPath(path);
2183
+
2184
+ const req = new FSReqCallback();
2185
+ req.oncomplete = callback;
2186
+ binding.utimes(
2187
+ path,
2188
+ toUnixTimestamp(atime),
2189
+ toUnixTimestamp(mtime),
2190
+ req,
2191
+ );
2192
+ }
2193
+
2194
+ /**
2195
+ * Synchronously changes the file system timestamps
2196
+ * of the object referenced by `path`.
2197
+ * @param {string | Buffer | URL} path
2198
+ * @param {number | string | Date} atime
2199
+ * @param {number | string | Date} mtime
2200
+ * @returns {void}
2201
+ */
2202
+ function utimesSync(path, atime, mtime) {
2203
+ binding.utimes(
2204
+ getValidatedPath(path),
2205
+ toUnixTimestamp(atime),
2206
+ toUnixTimestamp(mtime),
2207
+ );
2208
+ }
2209
+
2210
+ /**
2211
+ * Changes the file system timestamps of the object
2212
+ * referenced by the supplied `fd` (file descriptor).
2213
+ * @param {number} fd
2214
+ * @param {number | string | Date} atime
2215
+ * @param {number | string | Date} mtime
2216
+ * @param {(err?: Error) => any} callback
2217
+ * @returns {void}
2218
+ */
2219
+ function futimes(fd, atime, mtime, callback) {
2220
+ atime = toUnixTimestamp(atime, 'atime');
2221
+ mtime = toUnixTimestamp(mtime, 'mtime');
2222
+ callback = makeCallback(callback);
2223
+
2224
+ const req = new FSReqCallback();
2225
+ req.oncomplete = callback;
2226
+ binding.futimes(fd, atime, mtime, req);
2227
+ }
2228
+
2229
+ /**
2230
+ * Synchronously changes the file system timestamps
2231
+ * of the object referenced by the
2232
+ * supplied `fd` (file descriptor).
2233
+ * @param {number} fd
2234
+ * @param {number | string | Date} atime
2235
+ * @param {number | string | Date} mtime
2236
+ * @returns {void}
2237
+ */
2238
+ function futimesSync(fd, atime, mtime) {
2239
+ binding.futimes(
2240
+ fd,
2241
+ toUnixTimestamp(atime, 'atime'),
2242
+ toUnixTimestamp(mtime, 'mtime'),
2243
+ );
2244
+ }
2245
+
2246
+ /**
2247
+ * Changes the access and modification times of
2248
+ * a file in the same way as `fs.utimes()`.
2249
+ * @param {string | Buffer | URL} path
2250
+ * @param {number | string | Date} atime
2251
+ * @param {number | string | Date} mtime
2252
+ * @param {(err?: Error) => any} callback
2253
+ * @returns {void}
2254
+ */
2255
+ function lutimes(path, atime, mtime, callback) {
2256
+ callback = makeCallback(callback);
2257
+ path = getValidatedPath(path);
2258
+
2259
+ const req = new FSReqCallback();
2260
+ req.oncomplete = callback;
2261
+ binding.lutimes(
2262
+ path,
2263
+ toUnixTimestamp(atime),
2264
+ toUnixTimestamp(mtime),
2265
+ req,
2266
+ );
2267
+ }
2268
+
2269
+ /**
2270
+ * Synchronously changes the access and modification
2271
+ * times of a file in the same way as `fs.utimesSync()`.
2272
+ * @param {string | Buffer | URL} path
2273
+ * @param {number | string | Date} atime
2274
+ * @param {number | string | Date} mtime
2275
+ * @returns {void}
2276
+ */
2277
+ function lutimesSync(path, atime, mtime) {
2278
+ binding.lutimes(
2279
+ getValidatedPath(path),
2280
+ toUnixTimestamp(atime),
2281
+ toUnixTimestamp(mtime),
2282
+ );
2283
+ }
2284
+
2285
+ function writeAll(fd, isUserFd, buffer, offset, length, signal, flush, callback) {
2286
+ if (signal?.aborted) {
2287
+ const abortError = new AbortError(undefined, { cause: signal.reason });
2288
+ if (isUserFd) {
2289
+ callback(abortError);
2290
+ } else {
2291
+ fs.close(fd, (err) => {
2292
+ callback(aggregateTwoErrors(err, abortError));
2293
+ });
2294
+ }
2295
+ return;
2296
+ }
2297
+ // write(fd, buffer, offset, length, position, callback)
2298
+ fs.write(fd, buffer, offset, length, null, (writeErr, written) => {
2299
+ if (writeErr) {
2300
+ if (isUserFd) {
2301
+ callback(writeErr);
2302
+ } else {
2303
+ fs.close(fd, (err) => {
2304
+ callback(aggregateTwoErrors(err, writeErr));
2305
+ });
2306
+ }
2307
+ } else if (written === length) {
2308
+ if (!flush) {
2309
+ if (isUserFd) {
2310
+ callback(null);
2311
+ } else {
2312
+ fs.close(fd, callback);
2313
+ }
2314
+ } else {
2315
+ fs.fsync(fd, (syncErr) => {
2316
+ if (syncErr) {
2317
+ if (isUserFd) {
2318
+ callback(syncErr);
2319
+ } else {
2320
+ fs.close(fd, (err) => {
2321
+ callback(aggregateTwoErrors(err, syncErr));
2322
+ });
2323
+ }
2324
+ } else if (isUserFd) {
2325
+ callback(null);
2326
+ } else {
2327
+ fs.close(fd, callback);
2328
+ }
2329
+ });
2330
+ }
2331
+ } else {
2332
+ offset += written;
2333
+ length -= written;
2334
+ writeAll(fd, isUserFd, buffer, offset, length, signal, flush, callback);
2335
+ }
2336
+ });
2337
+ }
2338
+
2339
+ /**
2340
+ * Asynchronously writes data to the file.
2341
+ * @param {string | Buffer | URL | number} path
2342
+ * @param {string | Buffer | TypedArray | DataView} data
2343
+ * @param {{
2344
+ * encoding?: string | null;
2345
+ * mode?: number;
2346
+ * flag?: string;
2347
+ * signal?: AbortSignal;
2348
+ * flush?: boolean;
2349
+ * } | string} [options]
2350
+ * @param {(err?: Error) => any} callback
2351
+ * @returns {void}
2352
+ */
2353
+ function writeFile(path, data, options, callback) {
2354
+ callback ||= options;
2355
+ validateFunction(callback, 'cb');
2356
+ options = getOptions(options, {
2357
+ encoding: 'utf8',
2358
+ mode: 0o666,
2359
+ flag: 'w',
2360
+ flush: false,
2361
+ });
2362
+ const flag = options.flag || 'w';
2363
+ const flush = options.flush ?? false;
2364
+
2365
+ validateBoolean(flush, 'options.flush');
2366
+
2367
+ if (!isArrayBufferView(data)) {
2368
+ validateStringAfterArrayBufferView(data, 'data');
2369
+ data = Buffer.from(data, options.encoding || 'utf8');
2370
+ }
2371
+
2372
+ if (isFd(path)) {
2373
+ const isUserFd = true;
2374
+ const signal = options.signal;
2375
+ writeAll(path, isUserFd, data, 0, data.byteLength, signal, flush, callback);
2376
+ return;
2377
+ }
2378
+
2379
+ if (checkAborted(options.signal, callback))
2380
+ return;
2381
+
2382
+ fs.open(path, flag, options.mode, (openErr, fd) => {
2383
+ if (openErr) {
2384
+ callback(openErr);
2385
+ } else {
2386
+ const isUserFd = false;
2387
+ const signal = options.signal;
2388
+ writeAll(fd, isUserFd, data, 0, data.byteLength, signal, flush, callback);
2389
+ }
2390
+ });
2391
+ }
2392
+
2393
+ /**
2394
+ * Synchronously writes data to the file.
2395
+ * @param {string | Buffer | URL | number} path
2396
+ * @param {string | Buffer | TypedArray | DataView} data
2397
+ * @param {{
2398
+ * encoding?: string | null;
2399
+ * mode?: number;
2400
+ * flag?: string;
2401
+ * flush?: boolean;
2402
+ * } | string} [options]
2403
+ * @returns {void}
2404
+ */
2405
+ function writeFileSync(path, data, options) {
2406
+ options = getOptions(options, {
2407
+ encoding: 'utf8',
2408
+ mode: 0o666,
2409
+ flag: 'w',
2410
+ flush: false,
2411
+ });
2412
+
2413
+ const flush = options.flush ?? false;
2414
+
2415
+ validateBoolean(flush, 'options.flush');
2416
+
2417
+ const flag = options.flag || 'w';
2418
+
2419
+ // C++ fast path for string data and UTF8 encoding
2420
+ if (typeof data === 'string' && (options.encoding === 'utf8' || options.encoding === 'utf-8')) {
2421
+ if (!isInt32(path)) {
2422
+ path = getValidatedPath(path);
2423
+ }
2424
+
2425
+ return binding.writeFileUtf8(
2426
+ path,
2427
+ data,
2428
+ stringToFlags(flag),
2429
+ parseFileMode(options.mode, 'mode', 0o666),
2430
+ );
2431
+ }
2432
+
2433
+ if (!isArrayBufferView(data)) {
2434
+ validateStringAfterArrayBufferView(data, 'data');
2435
+ data = Buffer.from(data, options.encoding || 'utf8');
2436
+ }
2437
+
2438
+ const isUserFd = isFd(path); // File descriptor ownership
2439
+ const fd = isUserFd ? path : fs.openSync(path, flag, options.mode);
2440
+
2441
+ let offset = 0;
2442
+ let length = data.byteLength;
2443
+ try {
2444
+ while (length > 0) {
2445
+ const written = fs.writeSync(fd, data, offset, length);
2446
+ offset += written;
2447
+ length -= written;
2448
+ }
2449
+
2450
+ if (flush) {
2451
+ fs.fsyncSync(fd);
2452
+ }
2453
+ } finally {
2454
+ if (!isUserFd) fs.closeSync(fd);
2455
+ }
2456
+ }
2457
+
2458
+ /**
2459
+ * Asynchronously appends data to a file.
2460
+ * @param {string | Buffer | URL | number} path
2461
+ * @param {string | Buffer} data
2462
+ * @param {{
2463
+ * encoding?: string | null;
2464
+ * mode?: number;
2465
+ * flag?: string;
2466
+ * flush?: boolean;
2467
+ * } | string} [options]
2468
+ * @param {(err?: Error) => any} callback
2469
+ * @returns {void}
2470
+ */
2471
+ function appendFile(path, data, options, callback) {
2472
+ callback ||= options;
2473
+ validateFunction(callback, 'cb');
2474
+ options = getOptions(options, { encoding: 'utf8', mode: 0o666, flag: 'a' });
2475
+
2476
+ // Don't make changes directly on options object
2477
+ options = copyObject(options);
2478
+
2479
+ // Force append behavior when using a supplied file descriptor
2480
+ if (!options.flag || isFd(path))
2481
+ options.flag = 'a';
2482
+
2483
+ fs.writeFile(path, data, options, callback);
2484
+ }
2485
+
2486
+ /**
2487
+ * Synchronously appends data to a file.
2488
+ * @param {string | Buffer | URL | number} path
2489
+ * @param {string | Buffer} data
2490
+ * @param {{
2491
+ * encoding?: string | null;
2492
+ * mode?: number;
2493
+ * flag?: string;
2494
+ * } | string} [options]
2495
+ * @returns {void}
2496
+ */
2497
+ function appendFileSync(path, data, options) {
2498
+ options = getOptions(options, { encoding: 'utf8', mode: 0o666, flag: 'a' });
2499
+
2500
+ // Don't make changes directly on options object
2501
+ options = copyObject(options);
2502
+
2503
+ // Force append behavior when using a supplied file descriptor
2504
+ if (!options.flag || isFd(path))
2505
+ options.flag = 'a';
2506
+
2507
+ fs.writeFileSync(path, data, options);
2508
+ }
2509
+
2510
+ /**
2511
+ * Watches for the changes on `filename`.
2512
+ * @param {string | Buffer | URL} filename
2513
+ * @param {string | {
2514
+ * persistent?: boolean;
2515
+ * recursive?: boolean;
2516
+ * encoding?: string;
2517
+ * signal?: AbortSignal;
2518
+ * }} [options]
2519
+ * @param {(
2520
+ * eventType?: string,
2521
+ * filename?: string | Buffer
2522
+ * ) => any} [listener]
2523
+ * @returns {watchers.FSWatcher}
2524
+ */
2525
+ function watch(filename, options, listener) {
2526
+ if (typeof options === 'function') {
2527
+ listener = options;
2528
+ }
2529
+ options = getOptions(options);
2530
+
2531
+ // Don't make changes directly on options object
2532
+ options = copyObject(options);
2533
+
2534
+ if (options.persistent === undefined) options.persistent = true;
2535
+ if (options.recursive === undefined) options.recursive = false;
2536
+
2537
+ let watcher;
2538
+ const watchers = require('internal/fs/watchers');
2539
+ const path = getValidatedPath(filename);
2540
+ // TODO(anonrig): Remove non-native watcher when/if libuv supports recursive.
2541
+ // As of November 2022, libuv does not support recursive file watch on all platforms,
2542
+ // e.g. Linux due to the limitations of inotify.
2543
+ if (options.recursive && !isMacOS && !isWindows) {
2544
+ const nonNativeWatcher = require('internal/fs/recursive_watch');
2545
+ watcher = new nonNativeWatcher.FSWatcher(options);
2546
+ watcher[watchers.kFSWatchStart](path);
2547
+ } else {
2548
+ watcher = new watchers.FSWatcher();
2549
+ watcher[watchers.kFSWatchStart](path,
2550
+ options.persistent,
2551
+ options.recursive,
2552
+ options.encoding);
2553
+ }
2554
+
2555
+ if (listener) {
2556
+ watcher.addListener('change', listener);
2557
+ }
2558
+ if (options.signal) {
2559
+ if (options.signal.aborted) {
2560
+ process.nextTick(() => watcher.close());
2561
+ } else {
2562
+ const listener = () => watcher.close();
2563
+ kResistStopPropagation ??= require('internal/event_target').kResistStopPropagation;
2564
+ options.signal.addEventListener('abort', listener, { __proto__: null, [kResistStopPropagation]: true });
2565
+ watcher.once('close', () => {
2566
+ options.signal.removeEventListener('abort', listener);
2567
+ });
2568
+ }
2569
+ }
2570
+
2571
+ return watcher;
2572
+ }
2573
+
2574
+
2575
+ const statWatchers = new SafeMap();
2576
+
2577
+ /**
2578
+ * Watches for changes on `filename`.
2579
+ * @param {string | Buffer | URL} filename
2580
+ * @param {{
2581
+ * bigint?: boolean;
2582
+ * persistent?: boolean;
2583
+ * interval?: number;
2584
+ * }} [options]
2585
+ * @param {(
2586
+ * current?: Stats,
2587
+ * previous?: Stats
2588
+ * ) => any} listener
2589
+ * @returns {watchers.StatWatcher}
2590
+ */
2591
+ function watchFile(filename, options, listener) {
2592
+ filename = getValidatedPath(filename);
2593
+ filename = pathModule.resolve(filename);
2594
+ let stat;
2595
+
2596
+ if (options === null || typeof options !== 'object') {
2597
+ listener = options;
2598
+ options = null;
2599
+ }
2600
+
2601
+ options = {
2602
+ // Poll interval in milliseconds. 5007 is what libev used to use. It's
2603
+ // a little on the slow side but let's stick with it for now to keep
2604
+ // behavioral changes to a minimum.
2605
+ interval: 5007,
2606
+ persistent: true,
2607
+ ...options,
2608
+ };
2609
+
2610
+ validateFunction(listener, 'listener');
2611
+
2612
+ stat = statWatchers.get(filename);
2613
+ const watchers = require('internal/fs/watchers');
2614
+ if (stat === undefined) {
2615
+ stat = new watchers.StatWatcher(options.bigint);
2616
+ stat[watchers.kFSStatWatcherStart](filename,
2617
+ options.persistent, options.interval);
2618
+ statWatchers.set(filename, stat);
2619
+ } else {
2620
+ stat[watchers.kFSStatWatcherAddOrCleanRef]('add');
2621
+ }
2622
+
2623
+ stat.addListener('change', listener);
2624
+ return stat;
2625
+ }
2626
+
2627
+ /**
2628
+ * Stops watching for changes on `filename`.
2629
+ * @param {string | Buffer | URL} filename
2630
+ * @param {() => any} [listener]
2631
+ * @returns {void}
2632
+ */
2633
+ function unwatchFile(filename, listener) {
2634
+ filename = getValidatedPath(filename);
2635
+ filename = pathModule.resolve(filename);
2636
+ const stat = statWatchers.get(filename);
2637
+
2638
+ if (stat === undefined) return;
2639
+ const watchers = require('internal/fs/watchers');
2640
+ if (typeof listener === 'function') {
2641
+ const beforeListenerCount = stat.listenerCount('change');
2642
+ stat.removeListener('change', listener);
2643
+ if (stat.listenerCount('change') < beforeListenerCount)
2644
+ stat[watchers.kFSStatWatcherAddOrCleanRef]('clean');
2645
+ } else {
2646
+ stat.removeAllListeners('change');
2647
+ stat[watchers.kFSStatWatcherAddOrCleanRef]('cleanAll');
2648
+ }
2649
+
2650
+ if (stat.listenerCount('change') === 0) {
2651
+ stat.stop();
2652
+ statWatchers.delete(filename);
2653
+ }
2654
+ }
2655
+
2656
+
2657
+ let splitRoot;
2658
+ if (isWindows) {
2659
+ // Regex to find the device root on Windows (e.g. 'c:\\'), including trailing
2660
+ // slash.
2661
+ const splitRootRe = /^(?:[a-zA-Z]:|[\\/]{2}[^\\/]+[\\/][^\\/]+)?[\\/]*/;
2662
+ splitRoot = function splitRoot(str) {
2663
+ return SideEffectFreeRegExpPrototypeExec(splitRootRe, str)[0];
2664
+ };
2665
+ } else {
2666
+ splitRoot = function splitRoot(str) {
2667
+ for (let i = 0; i < str.length; ++i) {
2668
+ if (StringPrototypeCharCodeAt(str, i) !== CHAR_FORWARD_SLASH)
2669
+ return StringPrototypeSlice(str, 0, i);
2670
+ }
2671
+ return str;
2672
+ };
2673
+ }
2674
+
2675
+ function encodeRealpathResult(result, options) {
2676
+ if (!options || !options.encoding || options.encoding === 'utf8')
2677
+ return result;
2678
+ const asBuffer = Buffer.from(result);
2679
+ if (options.encoding === 'buffer') {
2680
+ return asBuffer;
2681
+ }
2682
+ return asBuffer.toString(options.encoding);
2683
+ }
2684
+
2685
+ // Finds the next portion of a (partial) path, up to the next path delimiter
2686
+ let nextPart;
2687
+ if (isWindows) {
2688
+ nextPart = function nextPart(p, i) {
2689
+ for (; i < p.length; ++i) {
2690
+ const ch = StringPrototypeCharCodeAt(p, i);
2691
+
2692
+ // Check for a separator character
2693
+ if (ch === CHAR_BACKWARD_SLASH || ch === CHAR_FORWARD_SLASH)
2694
+ return i;
2695
+ }
2696
+ return -1;
2697
+ };
2698
+ } else {
2699
+ nextPart = function nextPart(p, i) {
2700
+ return StringPrototypeIndexOf(p, '/', i);
2701
+ };
2702
+ }
2703
+
2704
+ /**
2705
+ * Returns the resolved pathname.
2706
+ * @param {string | Buffer | URL} p
2707
+ * @param {string | { encoding?: string | null; }} [options]
2708
+ * @returns {string | Buffer}
2709
+ */
2710
+ function realpathSync(p, options) {
2711
+ options = getOptions(options);
2712
+ p = toPathIfFileURL(p);
2713
+ if (typeof p !== 'string') {
2714
+ p += '';
2715
+ }
2716
+ validatePath(p);
2717
+ p = pathModule.resolve(p);
2718
+
2719
+ const cache = options[realpathCacheKey];
2720
+ const maybeCachedResult = cache?.get(p);
2721
+ if (maybeCachedResult) {
2722
+ return maybeCachedResult;
2723
+ }
2724
+
2725
+ const seenLinks = new SafeMap();
2726
+ const knownHard = new SafeSet();
2727
+ const original = p;
2728
+
2729
+ // Current character position in p
2730
+ let pos;
2731
+ // The partial path so far, including a trailing slash if any
2732
+ let current;
2733
+ // The partial path without a trailing slash (except when pointing at a root)
2734
+ let base;
2735
+ // The partial path scanned in the previous round, with slash
2736
+ let previous;
2737
+
2738
+ // Skip over roots
2739
+ current = base = splitRoot(p);
2740
+ pos = current.length;
2741
+
2742
+ // On windows, check that the root exists. On unix there is no need.
2743
+ if (isWindows) {
2744
+ const out = binding.lstat(base, false, undefined, true /* throwIfNoEntry */);
2745
+ if (out === undefined) {
2746
+ return;
2747
+ }
2748
+ knownHard.add(base);
2749
+ }
2750
+
2751
+ // Walk down the path, swapping out linked path parts for their real
2752
+ // values
2753
+ // NB: p.length changes.
2754
+ while (pos < p.length) {
2755
+ // find the next part
2756
+ const result = nextPart(p, pos);
2757
+ previous = current;
2758
+ if (result === -1) {
2759
+ const last = StringPrototypeSlice(p, pos);
2760
+ current += last;
2761
+ base = previous + last;
2762
+ pos = p.length;
2763
+ } else {
2764
+ current += StringPrototypeSlice(p, pos, result + 1);
2765
+ base = previous + StringPrototypeSlice(p, pos, result);
2766
+ pos = result + 1;
2767
+ }
2768
+
2769
+ // Continue if not a symlink, break if a pipe/socket
2770
+ if (knownHard.has(base) || cache?.get(base) === base) {
2771
+ if (isFileType(statValues, S_IFIFO) ||
2772
+ isFileType(statValues, S_IFSOCK)) {
2773
+ break;
2774
+ }
2775
+ continue;
2776
+ }
2777
+
2778
+ let resolvedLink;
2779
+ const maybeCachedResolved = cache?.get(base);
2780
+ if (maybeCachedResolved) {
2781
+ resolvedLink = maybeCachedResolved;
2782
+ } else {
2783
+ // Use stats array directly to avoid creating an fs.Stats instance just
2784
+ // for our internal use.
2785
+
2786
+ const stats = binding.lstat(base, true, undefined, true /* throwIfNoEntry */);
2787
+ if (stats === undefined) {
2788
+ return;
2789
+ }
2790
+
2791
+ if (!isFileType(stats, S_IFLNK)) {
2792
+ knownHard.add(base);
2793
+ cache?.set(base, base);
2794
+ continue;
2795
+ }
2796
+
2797
+ // Read the link if it wasn't read before
2798
+ // dev/ino always return 0 on windows, so skip the check.
2799
+ let linkTarget = null;
2800
+ let id;
2801
+ if (!isWindows) {
2802
+ const dev = BigIntPrototypeToString(stats[0], 32);
2803
+ const ino = BigIntPrototypeToString(stats[7], 32);
2804
+ id = `${dev}:${ino}`;
2805
+ if (seenLinks.has(id)) {
2806
+ linkTarget = seenLinks.get(id);
2807
+ }
2808
+ }
2809
+ if (linkTarget === null) {
2810
+ binding.stat(base, false, undefined, true);
2811
+ linkTarget = binding.readlink(base, undefined);
2812
+ }
2813
+ resolvedLink = pathModule.resolve(previous, linkTarget);
2814
+
2815
+ cache?.set(base, resolvedLink);
2816
+ if (!isWindows) seenLinks.set(id, linkTarget);
2817
+ }
2818
+
2819
+ // Resolve the link, then start over
2820
+ p = pathModule.resolve(resolvedLink, StringPrototypeSlice(p, pos));
2821
+
2822
+ // Skip over roots
2823
+ current = base = splitRoot(p);
2824
+ pos = current.length;
2825
+
2826
+ // On windows, check that the root exists. On unix there is no need.
2827
+ if (isWindows && !knownHard.has(base)) {
2828
+ const out = binding.lstat(base, false, undefined, true /* throwIfNoEntry */);
2829
+ if (out === undefined) {
2830
+ return;
2831
+ }
2832
+ knownHard.add(base);
2833
+ }
2834
+ }
2835
+
2836
+ cache?.set(original, p);
2837
+ return encodeRealpathResult(p, options);
2838
+ }
2839
+
2840
+ /**
2841
+ * Returns the resolved pathname.
2842
+ * @param {string | Buffer | URL} path
2843
+ * @param {string | { encoding?: string; }} [options]
2844
+ * @returns {string | Buffer}
2845
+ */
2846
+ realpathSync.native = (path, options) => {
2847
+ options = getOptions(options);
2848
+ return binding.realpath(
2849
+ getValidatedPath(path),
2850
+ options.encoding,
2851
+ );
2852
+ };
2853
+
2854
+ /**
2855
+ * Asynchronously computes the canonical pathname by
2856
+ * resolving `.`, `..` and symbolic links.
2857
+ * @param {string | Buffer | URL} p
2858
+ * @param {string | { encoding?: string; }} [options]
2859
+ * @param {(
2860
+ * err?: Error,
2861
+ * resolvedPath?: string | Buffer
2862
+ * ) => any} callback
2863
+ * @returns {void}
2864
+ */
2865
+ function realpath(p, options, callback) {
2866
+ if (typeof options === 'function') {
2867
+ callback = options;
2868
+ } else {
2869
+ validateFunction(callback, 'cb');
2870
+ }
2871
+ options = getOptions(options);
2872
+ p = toPathIfFileURL(p);
2873
+
2874
+ if (typeof p !== 'string') {
2875
+ p += '';
2876
+ }
2877
+ validatePath(p);
2878
+ p = pathModule.resolve(p);
2879
+
2880
+ const seenLinks = new SafeMap();
2881
+ const knownHard = new SafeSet();
2882
+
2883
+ // Current character position in p
2884
+ let pos;
2885
+ // The partial path so far, including a trailing slash if any
2886
+ let current;
2887
+ // The partial path without a trailing slash (except when pointing at a root)
2888
+ let base;
2889
+ // The partial path scanned in the previous round, with slash
2890
+ let previous;
2891
+
2892
+ current = base = splitRoot(p);
2893
+ pos = current.length;
2894
+
2895
+ // On windows, check that the root exists. On unix there is no need.
2896
+ if (isWindows && !knownHard.has(base)) {
2897
+ fs.lstat(base, (err) => {
2898
+ if (err) return callback(err);
2899
+ knownHard.add(base);
2900
+ LOOP();
2901
+ });
2902
+ } else {
2903
+ process.nextTick(LOOP);
2904
+ }
2905
+
2906
+ // Walk down the path, swapping out linked path parts for their real
2907
+ // values
2908
+ function LOOP() {
2909
+ // Stop if scanned past end of path
2910
+ if (pos >= p.length) {
2911
+ return callback(null, encodeRealpathResult(p, options));
2912
+ }
2913
+
2914
+ // find the next part
2915
+ const result = nextPart(p, pos);
2916
+ previous = current;
2917
+ if (result === -1) {
2918
+ const last = StringPrototypeSlice(p, pos);
2919
+ current += last;
2920
+ base = previous + last;
2921
+ pos = p.length;
2922
+ } else {
2923
+ current += StringPrototypeSlice(p, pos, result + 1);
2924
+ base = previous + StringPrototypeSlice(p, pos, result);
2925
+ pos = result + 1;
2926
+ }
2927
+
2928
+ // Continue if not a symlink, break if a pipe/socket
2929
+ if (knownHard.has(base)) {
2930
+ if (isFileType(statValues, S_IFIFO) ||
2931
+ isFileType(statValues, S_IFSOCK)) {
2932
+ return callback(null, encodeRealpathResult(p, options));
2933
+ }
2934
+ return process.nextTick(LOOP);
2935
+ }
2936
+
2937
+ return fs.lstat(base, { bigint: true }, gotStat);
2938
+ }
2939
+
2940
+ function gotStat(err, stats) {
2941
+ if (err) return callback(err);
2942
+
2943
+ // If not a symlink, skip to the next path part
2944
+ if (!stats.isSymbolicLink()) {
2945
+ knownHard.add(base);
2946
+ return process.nextTick(LOOP);
2947
+ }
2948
+
2949
+ // Stat & read the link if not read before.
2950
+ // Call `gotTarget()` as soon as the link target is known.
2951
+ // `dev`/`ino` always return 0 on windows, so skip the check.
2952
+ let id;
2953
+ if (!isWindows) {
2954
+ const dev = BigIntPrototypeToString(stats.dev, 32);
2955
+ const ino = BigIntPrototypeToString(stats.ino, 32);
2956
+ id = `${dev}:${ino}`;
2957
+ if (seenLinks.has(id)) {
2958
+ return gotTarget(null, seenLinks.get(id));
2959
+ }
2960
+ }
2961
+ fs.stat(base, (err) => {
2962
+ if (err) return callback(err);
2963
+
2964
+ fs.readlink(base, (err, target) => {
2965
+ if (!isWindows) seenLinks.set(id, target);
2966
+ gotTarget(err, target);
2967
+ });
2968
+ });
2969
+ }
2970
+
2971
+ function gotTarget(err, target) {
2972
+ if (err) return callback(err);
2973
+
2974
+ gotResolvedLink(pathModule.resolve(previous, target));
2975
+ }
2976
+
2977
+ function gotResolvedLink(resolvedLink) {
2978
+ // Resolve the link, then start over
2979
+ p = pathModule.resolve(resolvedLink, StringPrototypeSlice(p, pos));
2980
+ current = base = splitRoot(p);
2981
+ pos = current.length;
2982
+
2983
+ // On windows, check that the root exists. On unix there is no need.
2984
+ if (isWindows && !knownHard.has(base)) {
2985
+ fs.lstat(base, (err) => {
2986
+ if (err) return callback(err);
2987
+ knownHard.add(base);
2988
+ LOOP();
2989
+ });
2990
+ } else {
2991
+ process.nextTick(LOOP);
2992
+ }
2993
+ }
2994
+ }
2995
+
2996
+ /**
2997
+ * Asynchronously computes the canonical pathname by
2998
+ * resolving `.`, `..` and symbolic links.
2999
+ * @param {string | Buffer | URL} path
3000
+ * @param {string | { encoding?: string; }} [options]
3001
+ * @param {(
3002
+ * err?: Error,
3003
+ * resolvedPath?: string | Buffer
3004
+ * ) => any} callback
3005
+ * @returns {void}
3006
+ */
3007
+ realpath.native = (path, options, callback) => {
3008
+ callback = makeCallback(callback || options);
3009
+ options = getOptions(options);
3010
+ path = getValidatedPath(path);
3011
+ const req = new FSReqCallback();
3012
+ req.oncomplete = callback;
3013
+ binding.realpath(path, options.encoding, req);
3014
+ };
3015
+
3016
+ /**
3017
+ * Creates a unique temporary directory.
3018
+ * @param {string | Buffer | URL} prefix
3019
+ * @param {string | { encoding?: string; }} [options]
3020
+ * @param {(
3021
+ * err?: Error,
3022
+ * directory?: string
3023
+ * ) => any} callback
3024
+ * @returns {void}
3025
+ */
3026
+ function mkdtemp(prefix, options, callback) {
3027
+ callback = makeCallback(typeof options === 'function' ? options : callback);
3028
+ options = getOptions(options);
3029
+
3030
+ prefix = getValidatedPath(prefix, 'prefix');
3031
+ warnOnNonPortableTemplate(prefix);
3032
+
3033
+ const req = new FSReqCallback();
3034
+ req.oncomplete = callback;
3035
+ binding.mkdtemp(prefix, options.encoding, req);
3036
+ }
3037
+
3038
+ /**
3039
+ * Synchronously creates a unique temporary directory.
3040
+ * @param {string | Buffer | URL} prefix
3041
+ * @param {string | { encoding?: string; }} [options]
3042
+ * @returns {string}
3043
+ */
3044
+ function mkdtempSync(prefix, options) {
3045
+ options = getOptions(options);
3046
+
3047
+ prefix = getValidatedPath(prefix, 'prefix');
3048
+ warnOnNonPortableTemplate(prefix);
3049
+ return binding.mkdtemp(prefix, options.encoding);
3050
+ }
3051
+
3052
+ /**
3053
+ * Asynchronously copies `src` to `dest`. By
3054
+ * default, `dest` is overwritten if it already exists.
3055
+ * @param {string | Buffer | URL} src
3056
+ * @param {string | Buffer | URL} dest
3057
+ * @param {number} [mode]
3058
+ * @param {(err?: Error) => any} callback
3059
+ * @returns {void}
3060
+ */
3061
+ function copyFile(src, dest, mode, callback) {
3062
+ if (typeof mode === 'function') {
3063
+ callback = mode;
3064
+ mode = 0;
3065
+ }
3066
+
3067
+ src = getValidatedPath(src, 'src');
3068
+ dest = getValidatedPath(dest, 'dest');
3069
+ callback = makeCallback(callback);
3070
+
3071
+ const req = new FSReqCallback();
3072
+ req.oncomplete = callback;
3073
+ binding.copyFile(src, dest, mode, req);
3074
+ }
3075
+
3076
+ /**
3077
+ * Synchronously copies `src` to `dest`. By
3078
+ * default, `dest` is overwritten if it already exists.
3079
+ * @param {string | Buffer | URL} src
3080
+ * @param {string | Buffer | URL} dest
3081
+ * @param {number} [mode]
3082
+ * @returns {void}
3083
+ */
3084
+ function copyFileSync(src, dest, mode) {
3085
+ binding.copyFile(
3086
+ getValidatedPath(src, 'src'),
3087
+ getValidatedPath(dest, 'dest'),
3088
+ mode,
3089
+ );
3090
+ }
3091
+
3092
+ /**
3093
+ * Asynchronously copies `src` to `dest`. `src` can be a file, directory, or
3094
+ * symlink. The contents of directories will be copied recursively.
3095
+ * @param {string | URL} src
3096
+ * @param {string | URL} dest
3097
+ * @param {object} [options]
3098
+ * @param {(err?: Error) => any} callback
3099
+ * @returns {void}
3100
+ */
3101
+ function cp(src, dest, options, callback) {
3102
+ if (typeof options === 'function') {
3103
+ callback = options;
3104
+ options = undefined;
3105
+ }
3106
+ callback = makeCallback(callback);
3107
+ options = validateCpOptions(options);
3108
+ src = getValidatedPath(src, 'src');
3109
+ dest = getValidatedPath(dest, 'dest');
3110
+ lazyLoadCp();
3111
+ cpFn(src, dest, options, callback);
3112
+ }
3113
+
3114
+ /**
3115
+ * Synchronously copies `src` to `dest`. `src` can be a file, directory, or
3116
+ * symlink. The contents of directories will be copied recursively.
3117
+ * @param {string | URL} src
3118
+ * @param {string | URL} dest
3119
+ * @param {object} [options]
3120
+ * @returns {void}
3121
+ */
3122
+ function cpSync(src, dest, options) {
3123
+ options = validateCpOptions(options);
3124
+ src = getValidatedPath(src, 'src');
3125
+ dest = getValidatedPath(dest, 'dest');
3126
+ lazyLoadCp();
3127
+ cpSyncFn(src, dest, options);
3128
+ }
3129
+
3130
+ function lazyLoadStreams() {
3131
+ if (!ReadStream) {
3132
+ ({ ReadStream, WriteStream } = require('internal/fs/streams'));
3133
+ FileReadStream = ReadStream;
3134
+ FileWriteStream = WriteStream;
3135
+ }
3136
+ }
3137
+
3138
+ /**
3139
+ * Creates a readable stream with a default `highWaterMark`
3140
+ * of 64 KiB.
3141
+ * @param {string | Buffer | URL} path
3142
+ * @param {string | {
3143
+ * flags?: string;
3144
+ * encoding?: string;
3145
+ * fd?: number | FileHandle;
3146
+ * mode?: number;
3147
+ * autoClose?: boolean;
3148
+ * emitClose?: boolean;
3149
+ * start: number;
3150
+ * end?: number;
3151
+ * highWaterMark?: number;
3152
+ * fs?: object | null;
3153
+ * signal?: AbortSignal | null;
3154
+ * }} [options]
3155
+ * @returns {ReadStream}
3156
+ */
3157
+ function createReadStream(path, options) {
3158
+ lazyLoadStreams();
3159
+ return new ReadStream(path, options);
3160
+ }
3161
+
3162
+ /**
3163
+ * Creates a write stream.
3164
+ * @param {string | Buffer | URL} path
3165
+ * @param {string | {
3166
+ * flags?: string;
3167
+ * encoding?: string;
3168
+ * fd?: number | FileHandle;
3169
+ * mode?: number;
3170
+ * autoClose?: boolean;
3171
+ * emitClose?: boolean;
3172
+ * start: number;
3173
+ * fs?: object | null;
3174
+ * signal?: AbortSignal | null;
3175
+ * highWaterMark?: number;
3176
+ * flush?: boolean;
3177
+ * }} [options]
3178
+ * @returns {WriteStream}
3179
+ */
3180
+ function createWriteStream(path, options) {
3181
+ lazyLoadStreams();
3182
+ return new WriteStream(path, options);
3183
+ }
3184
+
3185
+ const lazyGlob = getLazy(() => require('internal/fs/glob').Glob);
3186
+
3187
+ function glob(pattern, options, callback) {
3188
+ if (typeof options === 'function') {
3189
+ callback = options;
3190
+ options = undefined;
3191
+ }
3192
+ callback = makeCallback(callback);
3193
+
3194
+ const Glob = lazyGlob();
3195
+ // TODO: Use iterator helpers when available
3196
+ (async () => {
3197
+ try {
3198
+ const res = [];
3199
+ for await (const entry of new Glob(pattern, options).glob()) {
3200
+ ArrayPrototypePush(res, entry);
3201
+ }
3202
+ callback(null, res);
3203
+ } catch (err) {
3204
+ callback(err);
3205
+ }
3206
+ })();
3207
+ }
3208
+
3209
+ function globSync(pattern, options) {
3210
+ const Glob = lazyGlob();
3211
+ return new Glob(pattern, options).globSync();
3212
+ }
3213
+
3214
+
3215
+ module.exports = fs = {
3216
+ appendFile,
3217
+ appendFileSync,
3218
+ access,
3219
+ accessSync,
3220
+ chown,
3221
+ chownSync,
3222
+ chmod,
3223
+ chmodSync,
3224
+ close,
3225
+ closeSync,
3226
+ copyFile,
3227
+ copyFileSync,
3228
+ cp,
3229
+ cpSync,
3230
+ createReadStream,
3231
+ createWriteStream,
3232
+ exists,
3233
+ existsSync,
3234
+ fchown,
3235
+ fchownSync,
3236
+ fchmod,
3237
+ fchmodSync,
3238
+ fdatasync,
3239
+ fdatasyncSync,
3240
+ fstat,
3241
+ fstatSync,
3242
+ fsync,
3243
+ fsyncSync,
3244
+ ftruncate,
3245
+ ftruncateSync,
3246
+ futimes,
3247
+ futimesSync,
3248
+ glob,
3249
+ globSync,
3250
+ lchown,
3251
+ lchownSync,
3252
+ lchmod: constants.O_SYMLINK !== undefined ? lchmod : undefined,
3253
+ lchmodSync: constants.O_SYMLINK !== undefined ? lchmodSync : undefined,
3254
+ link,
3255
+ linkSync,
3256
+ lstat,
3257
+ lstatSync,
3258
+ lutimes,
3259
+ lutimesSync,
3260
+ mkdir,
3261
+ mkdirSync,
3262
+ mkdtemp,
3263
+ mkdtempSync,
3264
+ open,
3265
+ openSync,
3266
+ openAsBlob,
3267
+ readdir,
3268
+ readdirSync,
3269
+ read,
3270
+ readSync,
3271
+ readv,
3272
+ readvSync,
3273
+ readFile,
3274
+ readFileSync,
3275
+ readlink,
3276
+ readlinkSync,
3277
+ realpath,
3278
+ realpathSync,
3279
+ rename,
3280
+ renameSync,
3281
+ rm,
3282
+ rmSync,
3283
+ rmdir,
3284
+ rmdirSync,
3285
+ stat,
3286
+ statfs,
3287
+ statSync,
3288
+ statfsSync,
3289
+ symlink,
3290
+ symlinkSync,
3291
+ truncate,
3292
+ truncateSync,
3293
+ unwatchFile,
3294
+ unlink,
3295
+ unlinkSync,
3296
+ utimes,
3297
+ utimesSync,
3298
+ watch,
3299
+ watchFile,
3300
+ writeFile,
3301
+ writeFileSync,
3302
+ write,
3303
+ writeSync,
3304
+ writev,
3305
+ writevSync,
3306
+ Dirent,
3307
+ Stats,
3308
+
3309
+ get ReadStream() {
3310
+ lazyLoadStreams();
3311
+ return ReadStream;
3312
+ },
3313
+
3314
+ set ReadStream(val) {
3315
+ ReadStream = val;
3316
+ },
3317
+
3318
+ get WriteStream() {
3319
+ lazyLoadStreams();
3320
+ return WriteStream;
3321
+ },
3322
+
3323
+ set WriteStream(val) {
3324
+ WriteStream = val;
3325
+ },
3326
+
3327
+ // Legacy names... these have to be separate because of how graceful-fs
3328
+ // (and possibly other) modules monkey patch the values.
3329
+ get FileReadStream() {
3330
+ lazyLoadStreams();
3331
+ return FileReadStream;
3332
+ },
3333
+
3334
+ set FileReadStream(val) {
3335
+ FileReadStream = val;
3336
+ },
3337
+
3338
+ get FileWriteStream() {
3339
+ lazyLoadStreams();
3340
+ return FileWriteStream;
3341
+ },
3342
+
3343
+ set FileWriteStream(val) {
3344
+ FileWriteStream = val;
3345
+ },
3346
+
3347
+ // For tests
3348
+ _toUnixTimestamp: toUnixTimestamp,
3349
+ };
3350
+
3351
+ defineLazyProperties(
3352
+ fs,
3353
+ 'internal/fs/dir',
3354
+ ['Dir', 'opendir', 'opendirSync'],
3355
+ );
3356
+
3357
+ ObjectDefineProperties(fs, {
3358
+ F_OK: { __proto__: null, enumerable: true, value: F_OK || 0 },
3359
+ R_OK: { __proto__: null, enumerable: true, value: R_OK || 0 },
3360
+ W_OK: { __proto__: null, enumerable: true, value: W_OK || 0 },
3361
+ X_OK: { __proto__: null, enumerable: true, value: X_OK || 0 },
3362
+ constants: {
3363
+ __proto__: null,
3364
+ configurable: false,
3365
+ enumerable: true,
3366
+ value: constants,
3367
+ },
3368
+ promises: {
3369
+ __proto__: null,
3370
+ configurable: true,
3371
+ enumerable: true,
3372
+ get() {
3373
+ promises ??= require('internal/fs/promises').exports;
3374
+ return promises;
3375
+ },
3376
+ },
3377
+ });