@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,1036 @@
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
+ 'use strict';
23
+
24
+ const {
25
+ ArrayBuffer,
26
+ MathMax,
27
+ NumberIsNaN,
28
+ ObjectDefineProperties,
29
+ ObjectDefineProperty,
30
+ ObjectEntries,
31
+ ObjectFreeze,
32
+ ObjectKeys,
33
+ ObjectSetPrototypeOf,
34
+ ReflectApply,
35
+ Symbol,
36
+ Uint32Array,
37
+ } = primordials;
38
+
39
+ const {
40
+ codes: {
41
+ ERR_BROTLI_INVALID_PARAM,
42
+ ERR_BUFFER_TOO_LARGE,
43
+ ERR_INVALID_ARG_TYPE,
44
+ ERR_OUT_OF_RANGE,
45
+ ERR_TRAILING_JUNK_AFTER_STREAM_END,
46
+ ERR_ZSTD_INVALID_PARAM,
47
+ },
48
+ genericNodeError,
49
+ } = require('internal/errors');
50
+ const { Transform, finished } = require('stream');
51
+ const {
52
+ deprecate,
53
+ } = require('internal/util');
54
+ const {
55
+ isArrayBufferView,
56
+ isAnyArrayBuffer,
57
+ isUint8Array,
58
+ } = require('internal/util/types');
59
+ const binding = internalBinding('zlib');
60
+ const { crc32: crc32Native } = binding;
61
+ const assert = require('internal/assert');
62
+ const {
63
+ Buffer,
64
+ kMaxLength,
65
+ } = require('buffer');
66
+ const { owner_symbol } = require('internal/async_hooks').symbols;
67
+ const {
68
+ checkRangesOrGetDefault,
69
+ validateFunction,
70
+ validateUint32,
71
+ validateFiniteNumber,
72
+ } = require('internal/validators');
73
+
74
+ const kFlushFlag = Symbol('kFlushFlag');
75
+ const kError = Symbol('kError');
76
+
77
+ const constants = internalBinding('constants').zlib;
78
+ const {
79
+ // Zlib flush levels
80
+ Z_NO_FLUSH, Z_BLOCK, Z_PARTIAL_FLUSH, Z_SYNC_FLUSH, Z_FULL_FLUSH, Z_FINISH,
81
+ // Zlib option values
82
+ Z_MIN_CHUNK, Z_MIN_WINDOWBITS, Z_MAX_WINDOWBITS, Z_MIN_LEVEL, Z_MAX_LEVEL,
83
+ Z_MIN_MEMLEVEL, Z_MAX_MEMLEVEL, Z_DEFAULT_CHUNK, Z_DEFAULT_COMPRESSION,
84
+ Z_DEFAULT_STRATEGY, Z_DEFAULT_WINDOWBITS, Z_DEFAULT_MEMLEVEL, Z_FIXED,
85
+ // Node's compression stream modes (node_zlib_mode)
86
+ DEFLATE, DEFLATERAW, INFLATE, INFLATERAW, GZIP, GUNZIP, UNZIP,
87
+ BROTLI_DECODE, BROTLI_ENCODE,
88
+ ZSTD_COMPRESS, ZSTD_DECOMPRESS,
89
+ // Brotli operations (~flush levels)
90
+ BROTLI_OPERATION_PROCESS, BROTLI_OPERATION_FLUSH,
91
+ BROTLI_OPERATION_FINISH, BROTLI_OPERATION_EMIT_METADATA,
92
+ // Zstd end directives (~flush levels)
93
+ ZSTD_e_continue, ZSTD_e_flush, ZSTD_e_end,
94
+ } = constants;
95
+
96
+ // Translation table for return codes.
97
+ const codes = {
98
+ Z_OK: constants.Z_OK,
99
+ Z_STREAM_END: constants.Z_STREAM_END,
100
+ Z_NEED_DICT: constants.Z_NEED_DICT,
101
+ Z_ERRNO: constants.Z_ERRNO,
102
+ Z_STREAM_ERROR: constants.Z_STREAM_ERROR,
103
+ Z_DATA_ERROR: constants.Z_DATA_ERROR,
104
+ Z_MEM_ERROR: constants.Z_MEM_ERROR,
105
+ Z_BUF_ERROR: constants.Z_BUF_ERROR,
106
+ Z_VERSION_ERROR: constants.Z_VERSION_ERROR,
107
+ };
108
+
109
+ for (const ckey of ObjectKeys(codes)) {
110
+ codes[codes[ckey]] = ckey;
111
+ }
112
+
113
+ function zlibBuffer(engine, buffer, callback) {
114
+ validateFunction(callback, 'callback');
115
+ // Streams do not support non-Uint8Array ArrayBufferViews yet. Convert it to a
116
+ // Buffer without copying.
117
+ if (isArrayBufferView(buffer) && !isUint8Array(buffer)) {
118
+ buffer = Buffer.from(buffer.buffer, buffer.byteOffset, buffer.byteLength);
119
+ } else if (isAnyArrayBuffer(buffer)) {
120
+ buffer = Buffer.from(buffer);
121
+ }
122
+ engine.buffers = null;
123
+ engine.nread = 0;
124
+ engine.cb = callback;
125
+ engine.on('data', zlibBufferOnData);
126
+ engine.on('error', zlibBufferOnError);
127
+ engine.on('end', zlibBufferOnEnd);
128
+ engine.end(buffer);
129
+ }
130
+
131
+ function zlibBufferOnData(chunk) {
132
+ if (!this.buffers) {
133
+ this.buffers = [chunk];
134
+ } else {
135
+ this.buffers.push(chunk);
136
+ }
137
+ this.nread += chunk.length;
138
+ if (this.nread > this._maxOutputLength) {
139
+ this.close();
140
+ this.removeAllListeners('end');
141
+ this.cb(new ERR_BUFFER_TOO_LARGE(this._maxOutputLength));
142
+ }
143
+ }
144
+
145
+ function zlibBufferOnError(err) {
146
+ this.removeAllListeners('end');
147
+ this.cb(err);
148
+ }
149
+
150
+ function zlibBufferOnEnd() {
151
+ let buf;
152
+ if (this.nread === 0) {
153
+ buf = Buffer.alloc(0);
154
+ } else {
155
+ const bufs = this.buffers;
156
+ buf = (bufs.length === 1 ? bufs[0] : Buffer.concat(bufs, this.nread));
157
+ }
158
+ this.close();
159
+ if (this._info)
160
+ this.cb(null, { buffer: buf, engine: this });
161
+ else
162
+ this.cb(null, buf);
163
+ }
164
+
165
+ function zlibBufferSync(engine, buffer) {
166
+ if (typeof buffer === 'string') {
167
+ buffer = Buffer.from(buffer);
168
+ } else if (!isArrayBufferView(buffer)) {
169
+ if (isAnyArrayBuffer(buffer)) {
170
+ buffer = Buffer.from(buffer);
171
+ } else {
172
+ throw new ERR_INVALID_ARG_TYPE(
173
+ 'buffer',
174
+ ['string', 'Buffer', 'TypedArray', 'DataView', 'ArrayBuffer'],
175
+ buffer,
176
+ );
177
+ }
178
+ }
179
+ buffer = processChunkSync(engine, buffer, engine._finishFlushFlag);
180
+ if (engine._info)
181
+ return { buffer, engine };
182
+ return buffer;
183
+ }
184
+
185
+ function zlibOnError(message, errno, code) {
186
+ const self = this[owner_symbol];
187
+ // There is no way to cleanly recover.
188
+ // Continuing only obscures problems.
189
+
190
+ const error = genericNodeError(message, { errno, code });
191
+ error.errno = errno;
192
+ error.code = code;
193
+ self.destroy(error);
194
+ self[kError] = error;
195
+ }
196
+
197
+ const FLUSH_BOUND = [
198
+ [ Z_NO_FLUSH, Z_BLOCK ],
199
+ [ BROTLI_OPERATION_PROCESS, BROTLI_OPERATION_EMIT_METADATA ],
200
+ [ ZSTD_e_continue, ZSTD_e_end ],
201
+ ];
202
+ const FLUSH_BOUND_IDX_NORMAL = 0;
203
+ const FLUSH_BOUND_IDX_BROTLI = 1;
204
+ const FLUSH_BOUND_IDX_ZSTD = 2;
205
+
206
+ // The base class for all Zlib-style streams.
207
+ function ZlibBase(opts, mode, handle, { flush, finishFlush, fullFlush }) {
208
+ let chunkSize = Z_DEFAULT_CHUNK;
209
+ let maxOutputLength = kMaxLength;
210
+ // The ZlibBase class is not exported to user land, the mode should only be
211
+ // passed in by us.
212
+ assert(typeof mode === 'number');
213
+ assert(mode >= DEFLATE && mode <= ZSTD_DECOMPRESS);
214
+
215
+ let flushBoundIdx;
216
+ if (mode === BROTLI_ENCODE || mode === BROTLI_DECODE) {
217
+ flushBoundIdx = FLUSH_BOUND_IDX_BROTLI;
218
+ } else if (mode === ZSTD_COMPRESS || mode === ZSTD_DECOMPRESS) {
219
+ flushBoundIdx = FLUSH_BOUND_IDX_ZSTD;
220
+ } else {
221
+ flushBoundIdx = FLUSH_BOUND_IDX_NORMAL;
222
+ }
223
+
224
+ if (opts) {
225
+ chunkSize = opts.chunkSize;
226
+ if (!validateFiniteNumber(chunkSize, 'options.chunkSize')) {
227
+ chunkSize = Z_DEFAULT_CHUNK;
228
+ } else if (chunkSize < Z_MIN_CHUNK) {
229
+ throw new ERR_OUT_OF_RANGE('options.chunkSize',
230
+ `>= ${Z_MIN_CHUNK}`, chunkSize);
231
+ }
232
+
233
+ flush = checkRangesOrGetDefault(
234
+ opts.flush, 'options.flush',
235
+ FLUSH_BOUND[flushBoundIdx][0], FLUSH_BOUND[flushBoundIdx][1], flush);
236
+
237
+ finishFlush = checkRangesOrGetDefault(
238
+ opts.finishFlush, 'options.finishFlush',
239
+ FLUSH_BOUND[flushBoundIdx][0], FLUSH_BOUND[flushBoundIdx][1],
240
+ finishFlush);
241
+
242
+ maxOutputLength = checkRangesOrGetDefault(
243
+ opts.maxOutputLength, 'options.maxOutputLength',
244
+ 1, kMaxLength, kMaxLength);
245
+
246
+ if (opts.encoding || opts.objectMode || opts.writableObjectMode) {
247
+ opts = { ...opts };
248
+ opts.encoding = null;
249
+ opts.objectMode = false;
250
+ opts.writableObjectMode = false;
251
+ }
252
+ }
253
+
254
+ ReflectApply(Transform, this, [{ autoDestroy: true, ...opts }]);
255
+ this[kError] = null;
256
+ this.bytesWritten = 0;
257
+ this._handle = handle;
258
+ handle[owner_symbol] = this;
259
+ // Used by processCallback() and zlibOnError()
260
+ handle.onerror = zlibOnError;
261
+ this._outBuffer = Buffer.allocUnsafe(chunkSize);
262
+ this._outOffset = 0;
263
+
264
+ this._chunkSize = chunkSize;
265
+ this._defaultFlushFlag = flush;
266
+ this._finishFlushFlag = finishFlush;
267
+ this._defaultFullFlushFlag = fullFlush;
268
+ this._info = opts?.info;
269
+ this._maxOutputLength = maxOutputLength;
270
+
271
+ this._rejectGarbageAfterEnd = opts?.rejectGarbageAfterEnd === true;
272
+ }
273
+ ObjectSetPrototypeOf(ZlibBase.prototype, Transform.prototype);
274
+ ObjectSetPrototypeOf(ZlibBase, Transform);
275
+
276
+ ObjectDefineProperty(ZlibBase.prototype, '_closed', {
277
+ __proto__: null,
278
+ configurable: true,
279
+ enumerable: true,
280
+ get() {
281
+ return !this._handle;
282
+ },
283
+ });
284
+
285
+ // `bytesRead` made sense as a name when looking from the zlib engine's
286
+ // perspective, but it is inconsistent with all other streams exposed by Node.js
287
+ // that have this concept, where it stands for the number of bytes read
288
+ // *from* the stream (that is, net.Socket/tls.Socket & file system streams).
289
+ ObjectDefineProperty(ZlibBase.prototype, 'bytesRead', {
290
+ __proto__: null,
291
+ configurable: true,
292
+ enumerable: true,
293
+ get: deprecate(function() {
294
+ return this.bytesWritten;
295
+ }, 'zlib.bytesRead is deprecated and will change its meaning in the ' +
296
+ 'future. Use zlib.bytesWritten instead.', 'DEP0108'),
297
+ set: deprecate(function(value) {
298
+ this.bytesWritten = value;
299
+ }, 'Setting zlib.bytesRead is deprecated. ' +
300
+ 'This feature will be removed in the future.', 'DEP0108'),
301
+ });
302
+
303
+ /**
304
+ * @this ZlibBase
305
+ * @returns {void}
306
+ */
307
+ ZlibBase.prototype.reset = function() {
308
+ assert(this._handle, 'zlib binding closed');
309
+ return this._handle.reset();
310
+ };
311
+
312
+ // This is the _flush function called by the transform class,
313
+ // internally, when the last chunk has been written.
314
+ ZlibBase.prototype._flush = function(callback) {
315
+ this._transform(Buffer.alloc(0), '', callback);
316
+ };
317
+
318
+ // Force Transform compat behavior.
319
+ ZlibBase.prototype._final = function(callback) {
320
+ callback();
321
+ };
322
+
323
+ // If a flush is scheduled while another flush is still pending, a way to figure
324
+ // out which one is the "stronger" flush is needed.
325
+ // This is currently only used to figure out which flush flag to use for the
326
+ // last chunk.
327
+ // Roughly, the following holds:
328
+ // Z_NO_FLUSH < Z_BLOCK < Z_PARTIAL_FLUSH <
329
+ // Z_SYNC_FLUSH < Z_FULL_FLUSH < Z_FINISH
330
+ const flushiness = [];
331
+ const kFlushFlagList = [Z_NO_FLUSH, Z_BLOCK, Z_PARTIAL_FLUSH,
332
+ Z_SYNC_FLUSH, Z_FULL_FLUSH, Z_FINISH];
333
+ for (let i = 0; i < kFlushFlagList.length; i++) {
334
+ flushiness[kFlushFlagList[i]] = i;
335
+ }
336
+
337
+ function maxFlush(a, b) {
338
+ return flushiness[a] > flushiness[b] ? a : b;
339
+ }
340
+
341
+ // Set up a list of 'special' buffers that can be written using .write()
342
+ // from the .flush() code as a way of introducing flushing operations into the
343
+ // write sequence.
344
+ const kFlushBuffers = [];
345
+ {
346
+ const dummyArrayBuffer = new ArrayBuffer();
347
+ for (const flushFlag of kFlushFlagList) {
348
+ kFlushBuffers[flushFlag] = Buffer.from(dummyArrayBuffer);
349
+ kFlushBuffers[flushFlag][kFlushFlag] = flushFlag;
350
+ }
351
+ }
352
+
353
+ ZlibBase.prototype.flush = function(kind, callback) {
354
+ if (typeof kind === 'function' || (kind === undefined && !callback)) {
355
+ callback = kind;
356
+ kind = this._defaultFullFlushFlag;
357
+ }
358
+
359
+ if (this.writableFinished) {
360
+ if (callback)
361
+ process.nextTick(callback);
362
+ } else if (this.writableEnded) {
363
+ if (callback)
364
+ this.once('end', callback);
365
+ } else {
366
+ this.write(kFlushBuffers[kind], '', callback);
367
+ }
368
+ };
369
+
370
+ /**
371
+ * @this import('stream').Transform
372
+ * @param {(err?: Error) => any} [callback]
373
+ */
374
+ ZlibBase.prototype.close = function(callback) {
375
+ if (callback) finished(this, callback);
376
+ this.destroy();
377
+ };
378
+
379
+ ZlibBase.prototype._destroy = function(err, callback) {
380
+ _close(this);
381
+ callback(err);
382
+ };
383
+
384
+ ZlibBase.prototype._transform = function(chunk, encoding, cb) {
385
+ let flushFlag = this._defaultFlushFlag;
386
+ // We use a 'fake' zero-length chunk to carry information about flushes from
387
+ // the public API to the actual stream implementation.
388
+ if (typeof chunk[kFlushFlag] === 'number') {
389
+ flushFlag = chunk[kFlushFlag];
390
+ }
391
+
392
+ // For the last chunk, also apply `_finishFlushFlag`.
393
+ if (this.writableEnded && this.writableLength === chunk.byteLength) {
394
+ flushFlag = maxFlush(flushFlag, this._finishFlushFlag);
395
+ }
396
+ processChunk(this, chunk, flushFlag, cb);
397
+ };
398
+
399
+ ZlibBase.prototype._processChunk = function(chunk, flushFlag, cb) {
400
+ // _processChunk() is left for backwards compatibility
401
+ if (typeof cb === 'function')
402
+ processChunk(this, chunk, flushFlag, cb);
403
+ else
404
+ return processChunkSync(this, chunk, flushFlag);
405
+ };
406
+
407
+ function processChunkSync(self, chunk, flushFlag) {
408
+ let availInBefore = chunk.byteLength;
409
+ let availOutBefore = self._chunkSize - self._outOffset;
410
+ let inOff = 0;
411
+ let availOutAfter;
412
+ let availInAfter;
413
+
414
+ const buffers = [];
415
+ let nread = 0;
416
+ let inputRead = 0;
417
+ const state = self._writeState;
418
+ const handle = self._handle;
419
+ let buffer = self._outBuffer;
420
+ let offset = self._outOffset;
421
+ const chunkSize = self._chunkSize;
422
+
423
+ let error;
424
+ self.on('error', function onError(er) {
425
+ error = er;
426
+ });
427
+
428
+ while (true) {
429
+ handle.writeSync(flushFlag,
430
+ chunk, // in
431
+ inOff, // in_off
432
+ availInBefore, // in_len
433
+ buffer, // out
434
+ offset, // out_off
435
+ availOutBefore); // out_len
436
+ if (error)
437
+ throw error;
438
+ else if (self[kError])
439
+ throw self[kError];
440
+
441
+ availOutAfter = state[0];
442
+ availInAfter = state[1];
443
+
444
+ const inDelta = (availInBefore - availInAfter);
445
+ inputRead += inDelta;
446
+
447
+ const have = availOutBefore - availOutAfter;
448
+ if (have > 0) {
449
+ const out = buffer.slice(offset, offset + have);
450
+ offset += have;
451
+ buffers.push(out);
452
+ nread += out.byteLength;
453
+
454
+ if (nread > self._maxOutputLength) {
455
+ _close(self);
456
+ throw new ERR_BUFFER_TOO_LARGE(self._maxOutputLength);
457
+ }
458
+
459
+ } else {
460
+ assert(have === 0, 'have should not go down');
461
+ }
462
+
463
+ // Exhausted the output buffer, or used all the input create a new one.
464
+ if (availOutAfter === 0 || offset >= chunkSize) {
465
+ availOutBefore = chunkSize;
466
+ offset = 0;
467
+ buffer = Buffer.allocUnsafe(chunkSize);
468
+ }
469
+
470
+ if (availOutAfter === 0) {
471
+ // Not actually done. Need to reprocess.
472
+ // Also, update the availInBefore to the availInAfter value,
473
+ // so that if we have to hit it a third (fourth, etc.) time,
474
+ // it'll have the correct byte counts.
475
+ inOff += inDelta;
476
+ availInBefore = availInAfter;
477
+ } else {
478
+ break;
479
+ }
480
+ }
481
+
482
+ self.bytesWritten = inputRead;
483
+ _close(self);
484
+
485
+ if (nread === 0)
486
+ return Buffer.alloc(0);
487
+
488
+ return (buffers.length === 1 ? buffers[0] : Buffer.concat(buffers, nread));
489
+ }
490
+
491
+ function processChunk(self, chunk, flushFlag, cb) {
492
+ const handle = self._handle;
493
+ if (!handle) return process.nextTick(cb);
494
+
495
+ handle.buffer = chunk;
496
+ handle.cb = cb;
497
+ handle.availOutBefore = self._chunkSize - self._outOffset;
498
+ handle.availInBefore = chunk.byteLength;
499
+ handle.inOff = 0;
500
+ handle.flushFlag = flushFlag;
501
+
502
+ handle.write(flushFlag,
503
+ chunk, // in
504
+ 0, // in_off
505
+ handle.availInBefore, // in_len
506
+ self._outBuffer, // out
507
+ self._outOffset, // out_off
508
+ handle.availOutBefore); // out_len
509
+ }
510
+
511
+ function processCallback() {
512
+ // This callback's context (`this`) is the `_handle` (ZCtx) object. It is
513
+ // important to null out the values once they are no longer needed since
514
+ // `_handle` can stay in memory long after the buffer is needed.
515
+ const handle = this;
516
+ const self = this[owner_symbol];
517
+ const state = self._writeState;
518
+
519
+ if (self.destroyed) {
520
+ this.buffer = null;
521
+ this.cb();
522
+ return;
523
+ }
524
+
525
+ const availOutAfter = state[0];
526
+ const availInAfter = state[1];
527
+
528
+ const inDelta = handle.availInBefore - availInAfter;
529
+ self.bytesWritten += inDelta;
530
+
531
+ const have = handle.availOutBefore - availOutAfter;
532
+ let streamBufferIsFull = false;
533
+ if (have > 0) {
534
+ const out = self._outBuffer.slice(self._outOffset, self._outOffset + have);
535
+ self._outOffset += have;
536
+ streamBufferIsFull = !self.push(out);
537
+ } else {
538
+ assert(have === 0, 'have should not go down');
539
+ }
540
+
541
+ if (self.destroyed) {
542
+ this.cb();
543
+ return;
544
+ }
545
+
546
+ // Exhausted the output buffer, or used all the input create a new one.
547
+ if (availOutAfter === 0 || self._outOffset >= self._chunkSize) {
548
+ handle.availOutBefore = self._chunkSize;
549
+ self._outOffset = 0;
550
+ self._outBuffer = Buffer.allocUnsafe(self._chunkSize);
551
+ }
552
+
553
+ if (availOutAfter === 0) {
554
+ // Not actually done. Need to reprocess.
555
+ // Also, update the availInBefore to the availInAfter value,
556
+ // so that if we have to hit it a third (fourth, etc.) time,
557
+ // it'll have the correct byte counts.
558
+ handle.inOff += inDelta;
559
+ handle.availInBefore = availInAfter;
560
+
561
+
562
+ if (!streamBufferIsFull) {
563
+ this.write(handle.flushFlag,
564
+ this.buffer, // in
565
+ handle.inOff, // in_off
566
+ handle.availInBefore, // in_len
567
+ self._outBuffer, // out
568
+ self._outOffset, // out_off
569
+ self._chunkSize); // out_len
570
+ } else {
571
+ const oldRead = self._read;
572
+ self._read = (n) => {
573
+ self._read = oldRead;
574
+ this.write(handle.flushFlag,
575
+ this.buffer, // in
576
+ handle.inOff, // in_off
577
+ handle.availInBefore, // in_len
578
+ self._outBuffer, // out
579
+ self._outOffset, // out_off
580
+ self._chunkSize); // out_len
581
+ self._read(n);
582
+ };
583
+ }
584
+ return;
585
+ }
586
+
587
+ if (availInAfter > 0) {
588
+ // If we have more input that should be written, but we also have output
589
+ // space available, that means that the compression library was not
590
+ // interested in receiving more data, and in particular that the input
591
+ // stream has ended early.
592
+ // This applies to streams where we don't check data past the end of
593
+ // what was consumed; that is, everything except Gunzip/Unzip.
594
+
595
+ if (self._rejectGarbageAfterEnd) {
596
+ const err = new ERR_TRAILING_JUNK_AFTER_STREAM_END();
597
+ self.destroy(err);
598
+ this.cb(err);
599
+ return;
600
+ }
601
+
602
+ self.push(null);
603
+ }
604
+
605
+ // Finished with the chunk.
606
+ this.buffer = null;
607
+ this.cb();
608
+ }
609
+
610
+ /**
611
+ * @param {ZlibBase} engine
612
+ * @private
613
+ */
614
+ function _close(engine) {
615
+ // Caller may invoke .close after a zlib error (which will null _handle)
616
+ engine._handle?.close();
617
+ engine._handle = null;
618
+ }
619
+
620
+ const zlibDefaultOpts = {
621
+ flush: Z_NO_FLUSH,
622
+ finishFlush: Z_FINISH,
623
+ fullFlush: Z_FULL_FLUSH,
624
+ };
625
+ // Base class for all streams actually backed by zlib and using zlib-specific
626
+ // parameters.
627
+ function Zlib(opts, mode) {
628
+ let windowBits = Z_DEFAULT_WINDOWBITS;
629
+ let level = Z_DEFAULT_COMPRESSION;
630
+ let memLevel = Z_DEFAULT_MEMLEVEL;
631
+ let strategy = Z_DEFAULT_STRATEGY;
632
+ let dictionary;
633
+
634
+ if (opts) {
635
+ // windowBits is special. On the compression side, 0 is an invalid value.
636
+ // But on the decompression side, a value of 0 for windowBits tells zlib
637
+ // to use the window size in the zlib header of the compressed stream.
638
+ if ((opts.windowBits == null || opts.windowBits === 0) &&
639
+ (mode === INFLATE ||
640
+ mode === GUNZIP ||
641
+ mode === UNZIP)) {
642
+ windowBits = 0;
643
+ } else {
644
+ // `{ windowBits: 8 }` is valid for deflate but not gzip.
645
+ const min = Z_MIN_WINDOWBITS + (mode === GZIP ? 1 : 0);
646
+ windowBits = checkRangesOrGetDefault(
647
+ opts.windowBits, 'options.windowBits',
648
+ min, Z_MAX_WINDOWBITS, Z_DEFAULT_WINDOWBITS);
649
+ }
650
+
651
+ level = checkRangesOrGetDefault(
652
+ opts.level, 'options.level',
653
+ Z_MIN_LEVEL, Z_MAX_LEVEL, Z_DEFAULT_COMPRESSION);
654
+
655
+ memLevel = checkRangesOrGetDefault(
656
+ opts.memLevel, 'options.memLevel',
657
+ Z_MIN_MEMLEVEL, Z_MAX_MEMLEVEL, Z_DEFAULT_MEMLEVEL);
658
+
659
+ strategy = checkRangesOrGetDefault(
660
+ opts.strategy, 'options.strategy',
661
+ Z_DEFAULT_STRATEGY, Z_FIXED, Z_DEFAULT_STRATEGY);
662
+
663
+ dictionary = opts.dictionary;
664
+ if (dictionary !== undefined && !isArrayBufferView(dictionary)) {
665
+ if (isAnyArrayBuffer(dictionary)) {
666
+ dictionary = Buffer.from(dictionary);
667
+ } else {
668
+ throw new ERR_INVALID_ARG_TYPE(
669
+ 'options.dictionary',
670
+ ['Buffer', 'TypedArray', 'DataView', 'ArrayBuffer'],
671
+ dictionary,
672
+ );
673
+ }
674
+ }
675
+ }
676
+
677
+ const handle = new binding.Zlib(mode);
678
+ // Ideally, we could let ZlibBase() set up _writeState. I haven't been able
679
+ // to come up with a good solution that doesn't break our internal API,
680
+ // and with it all supported npm versions at the time of writing.
681
+ this._writeState = new Uint32Array(2);
682
+ handle.init(windowBits,
683
+ level,
684
+ memLevel,
685
+ strategy,
686
+ this._writeState,
687
+ processCallback,
688
+ dictionary);
689
+
690
+ ReflectApply(ZlibBase, this, [opts, mode, handle, zlibDefaultOpts]);
691
+
692
+ this._level = level;
693
+ this._strategy = strategy;
694
+ this._mode = mode;
695
+ }
696
+ ObjectSetPrototypeOf(Zlib.prototype, ZlibBase.prototype);
697
+ ObjectSetPrototypeOf(Zlib, ZlibBase);
698
+
699
+ // This callback is used by `.params()` to wait until a full flush happened
700
+ // before adjusting the parameters. In particular, the call to the native
701
+ // `params()` function should not happen while a write is currently in progress
702
+ // on the threadpool.
703
+ function paramsAfterFlushCallback(level, strategy, callback) {
704
+ assert(this._handle, 'zlib binding closed');
705
+ this._handle.params(level, strategy);
706
+ if (!this.destroyed) {
707
+ this._level = level;
708
+ this._strategy = strategy;
709
+ if (callback) callback();
710
+ }
711
+ }
712
+
713
+ Zlib.prototype.params = function params(level, strategy, callback) {
714
+ checkRangesOrGetDefault(level, 'level', Z_MIN_LEVEL, Z_MAX_LEVEL);
715
+ checkRangesOrGetDefault(strategy, 'strategy', Z_DEFAULT_STRATEGY, Z_FIXED);
716
+
717
+ if (this._level !== level || this._strategy !== strategy) {
718
+ this.flush(
719
+ Z_SYNC_FLUSH,
720
+ paramsAfterFlushCallback.bind(this, level, strategy, callback),
721
+ );
722
+ } else {
723
+ process.nextTick(callback);
724
+ }
725
+ };
726
+
727
+ // generic zlib
728
+ // minimal 2-byte header
729
+ function Deflate(opts) {
730
+ if (!(this instanceof Deflate))
731
+ return new Deflate(opts);
732
+ ReflectApply(Zlib, this, [opts, DEFLATE]);
733
+ }
734
+ ObjectSetPrototypeOf(Deflate.prototype, Zlib.prototype);
735
+ ObjectSetPrototypeOf(Deflate, Zlib);
736
+
737
+ function Inflate(opts) {
738
+ if (!(this instanceof Inflate))
739
+ return new Inflate(opts);
740
+ ReflectApply(Zlib, this, [opts, INFLATE]);
741
+ }
742
+ ObjectSetPrototypeOf(Inflate.prototype, Zlib.prototype);
743
+ ObjectSetPrototypeOf(Inflate, Zlib);
744
+
745
+ function Gzip(opts) {
746
+ if (!(this instanceof Gzip))
747
+ return new Gzip(opts);
748
+ ReflectApply(Zlib, this, [opts, GZIP]);
749
+ }
750
+ ObjectSetPrototypeOf(Gzip.prototype, Zlib.prototype);
751
+ ObjectSetPrototypeOf(Gzip, Zlib);
752
+
753
+ function Gunzip(opts) {
754
+ if (!(this instanceof Gunzip))
755
+ return new Gunzip(opts);
756
+ ReflectApply(Zlib, this, [opts, GUNZIP]);
757
+ }
758
+ ObjectSetPrototypeOf(Gunzip.prototype, Zlib.prototype);
759
+ ObjectSetPrototypeOf(Gunzip, Zlib);
760
+
761
+ function DeflateRaw(opts) {
762
+ if (opts && opts.windowBits === 8) opts.windowBits = 9;
763
+ if (!(this instanceof DeflateRaw))
764
+ return new DeflateRaw(opts);
765
+ ReflectApply(Zlib, this, [opts, DEFLATERAW]);
766
+ }
767
+ ObjectSetPrototypeOf(DeflateRaw.prototype, Zlib.prototype);
768
+ ObjectSetPrototypeOf(DeflateRaw, Zlib);
769
+
770
+ function InflateRaw(opts) {
771
+ if (!(this instanceof InflateRaw))
772
+ return new InflateRaw(opts);
773
+ ReflectApply(Zlib, this, [opts, INFLATERAW]);
774
+ }
775
+ ObjectSetPrototypeOf(InflateRaw.prototype, Zlib.prototype);
776
+ ObjectSetPrototypeOf(InflateRaw, Zlib);
777
+
778
+ function Unzip(opts) {
779
+ if (!(this instanceof Unzip))
780
+ return new Unzip(opts);
781
+ ReflectApply(Zlib, this, [opts, UNZIP]);
782
+ }
783
+ ObjectSetPrototypeOf(Unzip.prototype, Zlib.prototype);
784
+ ObjectSetPrototypeOf(Unzip, Zlib);
785
+
786
+ function createConvenienceMethod(ctor, sync) {
787
+ if (sync) {
788
+ return function syncBufferWrapper(buffer, opts) {
789
+ return zlibBufferSync(new ctor(opts), buffer);
790
+ };
791
+ }
792
+ return function asyncBufferWrapper(buffer, opts, callback) {
793
+ if (typeof opts === 'function') {
794
+ callback = opts;
795
+ opts = {};
796
+ }
797
+ return zlibBuffer(new ctor(opts), buffer, callback);
798
+ };
799
+ }
800
+
801
+ const kMaxBrotliParam = MathMax(
802
+ ...ObjectEntries(constants)
803
+ .map(({ 0: key, 1: value }) => (key.startsWith('BROTLI_PARAM_') ? value : 0)),
804
+ );
805
+ const brotliInitParamsArray = new Uint32Array(kMaxBrotliParam + 1);
806
+
807
+ const brotliDefaultOpts = {
808
+ flush: BROTLI_OPERATION_PROCESS,
809
+ finishFlush: BROTLI_OPERATION_FINISH,
810
+ fullFlush: BROTLI_OPERATION_FLUSH,
811
+ };
812
+ function Brotli(opts, mode) {
813
+ assert(mode === BROTLI_DECODE || mode === BROTLI_ENCODE);
814
+
815
+ brotliInitParamsArray.fill(-1);
816
+ if (opts?.params) {
817
+ ObjectKeys(opts.params).forEach((origKey) => {
818
+ const key = +origKey;
819
+ if (NumberIsNaN(key) || key < 0 || key > kMaxBrotliParam ||
820
+ (brotliInitParamsArray[key] | 0) !== -1) {
821
+ throw new ERR_BROTLI_INVALID_PARAM(origKey);
822
+ }
823
+
824
+ const value = opts.params[origKey];
825
+ if (typeof value !== 'number' && typeof value !== 'boolean') {
826
+ throw new ERR_INVALID_ARG_TYPE('options.params[key]',
827
+ 'number', opts.params[origKey]);
828
+ }
829
+ brotliInitParamsArray[key] = value;
830
+ });
831
+ }
832
+
833
+ const handle = mode === BROTLI_DECODE ?
834
+ new binding.BrotliDecoder(mode) : new binding.BrotliEncoder(mode);
835
+
836
+ this._writeState = new Uint32Array(2);
837
+ handle.init(brotliInitParamsArray, this._writeState, processCallback);
838
+
839
+ ReflectApply(ZlibBase, this, [opts, mode, handle, brotliDefaultOpts]);
840
+ }
841
+ ObjectSetPrototypeOf(Brotli.prototype, Zlib.prototype);
842
+ ObjectSetPrototypeOf(Brotli, Zlib);
843
+
844
+ function BrotliCompress(opts) {
845
+ if (!(this instanceof BrotliCompress))
846
+ return new BrotliCompress(opts);
847
+ ReflectApply(Brotli, this, [opts, BROTLI_ENCODE]);
848
+ }
849
+ ObjectSetPrototypeOf(BrotliCompress.prototype, Brotli.prototype);
850
+ ObjectSetPrototypeOf(BrotliCompress, Brotli);
851
+
852
+ function BrotliDecompress(opts) {
853
+ if (!(this instanceof BrotliDecompress))
854
+ return new BrotliDecompress(opts);
855
+ ReflectApply(Brotli, this, [opts, BROTLI_DECODE]);
856
+ }
857
+ ObjectSetPrototypeOf(BrotliDecompress.prototype, Brotli.prototype);
858
+ ObjectSetPrototypeOf(BrotliDecompress, Brotli);
859
+
860
+
861
+ const zstdDefaultOpts = {
862
+ flush: ZSTD_e_continue,
863
+ finishFlush: ZSTD_e_end,
864
+ fullFlush: ZSTD_e_flush,
865
+ };
866
+ class Zstd extends ZlibBase {
867
+ constructor(opts, mode, initParamsArray, maxParam) {
868
+ assert(mode === ZSTD_COMPRESS || mode === ZSTD_DECOMPRESS);
869
+
870
+ initParamsArray.fill(-1);
871
+ if (opts?.params) {
872
+ ObjectKeys(opts.params).forEach((origKey) => {
873
+ const key = +origKey;
874
+ if (NumberIsNaN(key) || key < 0 || key > maxParam ||
875
+ (initParamsArray[key] | 0) !== -1) {
876
+ throw new ERR_ZSTD_INVALID_PARAM(origKey);
877
+ }
878
+
879
+ const value = opts.params[origKey];
880
+ if (typeof value !== 'number' && typeof value !== 'boolean') {
881
+ throw new ERR_INVALID_ARG_TYPE('options.params[key]',
882
+ 'number', opts.params[origKey]);
883
+ }
884
+ initParamsArray[key] = value;
885
+ });
886
+ }
887
+
888
+ const handle = mode === ZSTD_COMPRESS ?
889
+ new binding.ZstdCompress() : new binding.ZstdDecompress();
890
+
891
+ const pledgedSrcSize = opts?.pledgedSrcSize ?? undefined;
892
+
893
+ const writeState = new Uint32Array(2);
894
+ handle.init(
895
+ initParamsArray,
896
+ pledgedSrcSize,
897
+ writeState,
898
+ processCallback,
899
+ );
900
+ super(opts, mode, handle, zstdDefaultOpts);
901
+ this._writeState = writeState;
902
+ }
903
+ }
904
+
905
+ const kMaxZstdCParam = MathMax(...ObjectKeys(constants).map(
906
+ (key) => (key.startsWith('ZSTD_c_') ?
907
+ constants[key] :
908
+ 0),
909
+ ));
910
+
911
+ const zstdInitCParamsArray = new Uint32Array(kMaxZstdCParam + 1);
912
+
913
+ class ZstdCompress extends Zstd {
914
+ constructor(opts) {
915
+ super(opts, ZSTD_COMPRESS, zstdInitCParamsArray, kMaxZstdCParam);
916
+ }
917
+ }
918
+
919
+ const kMaxZstdDParam = MathMax(...ObjectKeys(constants).map(
920
+ (key) => (key.startsWith('ZSTD_d_') ?
921
+ constants[key] :
922
+ 0),
923
+ ));
924
+
925
+ const zstdInitDParamsArray = new Uint32Array(kMaxZstdDParam + 1);
926
+
927
+ class ZstdDecompress extends Zstd {
928
+ constructor(opts) {
929
+ super(opts, ZSTD_DECOMPRESS, zstdInitDParamsArray, kMaxZstdDParam);
930
+ }
931
+ }
932
+
933
+ function createProperty(ctor) {
934
+ return {
935
+ __proto__: null,
936
+ configurable: true,
937
+ enumerable: true,
938
+ value: function(options) {
939
+ return new ctor(options);
940
+ },
941
+ };
942
+ }
943
+
944
+ function crc32(data, value = 0) {
945
+ if (typeof data !== 'string' && !isArrayBufferView(data)) {
946
+ throw new ERR_INVALID_ARG_TYPE('data', ['Buffer', 'TypedArray', 'DataView', 'string'], data);
947
+ }
948
+ validateUint32(value, 'value');
949
+ return crc32Native(data, value);
950
+ }
951
+
952
+ // Legacy alias on the C++ wrapper object. This is not public API, so we may
953
+ // want to runtime-deprecate it at some point. There's no hurry, though.
954
+ ObjectDefineProperty(binding.Zlib.prototype, 'jsref', {
955
+ __proto__: null,
956
+ get() { return this[owner_symbol]; },
957
+ set(v) { return this[owner_symbol] = v; },
958
+ });
959
+
960
+ module.exports = {
961
+ crc32,
962
+ Deflate,
963
+ Inflate,
964
+ Gzip,
965
+ Gunzip,
966
+ DeflateRaw,
967
+ InflateRaw,
968
+ Unzip,
969
+ BrotliCompress,
970
+ BrotliDecompress,
971
+ ZstdCompress,
972
+ ZstdDecompress,
973
+
974
+ // Convenience methods.
975
+ // compress/decompress a string or buffer in one step.
976
+ deflate: createConvenienceMethod(Deflate, false),
977
+ deflateSync: createConvenienceMethod(Deflate, true),
978
+ gzip: createConvenienceMethod(Gzip, false),
979
+ gzipSync: createConvenienceMethod(Gzip, true),
980
+ deflateRaw: createConvenienceMethod(DeflateRaw, false),
981
+ deflateRawSync: createConvenienceMethod(DeflateRaw, true),
982
+ unzip: createConvenienceMethod(Unzip, false),
983
+ unzipSync: createConvenienceMethod(Unzip, true),
984
+ inflate: createConvenienceMethod(Inflate, false),
985
+ inflateSync: createConvenienceMethod(Inflate, true),
986
+ gunzip: createConvenienceMethod(Gunzip, false),
987
+ gunzipSync: createConvenienceMethod(Gunzip, true),
988
+ inflateRaw: createConvenienceMethod(InflateRaw, false),
989
+ inflateRawSync: createConvenienceMethod(InflateRaw, true),
990
+ brotliCompress: createConvenienceMethod(BrotliCompress, false),
991
+ brotliCompressSync: createConvenienceMethod(BrotliCompress, true),
992
+ brotliDecompress: createConvenienceMethod(BrotliDecompress, false),
993
+ brotliDecompressSync: createConvenienceMethod(BrotliDecompress, true),
994
+ zstdCompress: createConvenienceMethod(ZstdCompress, false),
995
+ zstdCompressSync: createConvenienceMethod(ZstdCompress, true),
996
+ zstdDecompress: createConvenienceMethod(ZstdDecompress, false),
997
+ zstdDecompressSync: createConvenienceMethod(ZstdDecompress, true),
998
+ };
999
+
1000
+ ObjectDefineProperties(module.exports, {
1001
+ createDeflate: createProperty(Deflate),
1002
+ createInflate: createProperty(Inflate),
1003
+ createDeflateRaw: createProperty(DeflateRaw),
1004
+ createInflateRaw: createProperty(InflateRaw),
1005
+ createGzip: createProperty(Gzip),
1006
+ createGunzip: createProperty(Gunzip),
1007
+ createUnzip: createProperty(Unzip),
1008
+ createBrotliCompress: createProperty(BrotliCompress),
1009
+ createBrotliDecompress: createProperty(BrotliDecompress),
1010
+ createZstdCompress: createProperty(ZstdCompress),
1011
+ createZstdDecompress: createProperty(ZstdDecompress),
1012
+ constants: {
1013
+ __proto__: null,
1014
+ configurable: false,
1015
+ enumerable: true,
1016
+ value: constants,
1017
+ },
1018
+ codes: {
1019
+ __proto__: null,
1020
+ enumerable: true,
1021
+ writable: false,
1022
+ value: ObjectFreeze(codes),
1023
+ },
1024
+ });
1025
+
1026
+ // These should be considered deprecated
1027
+ // expose all the zlib constants
1028
+ for (const { 0: key, 1: value } of ObjectEntries(constants)) {
1029
+ if (key.startsWith('BROTLI')) continue;
1030
+ ObjectDefineProperty(module.exports, key, {
1031
+ __proto__: null,
1032
+ enumerable: false,
1033
+ value,
1034
+ writable: false,
1035
+ });
1036
+ }