visaljs 0.0.5 → 0.0.6

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 (433) hide show
  1. package/cli.js +469 -53
  2. package/node/include/js_node.h +36 -0
  3. package/node/prelude/async_hooks.js +63 -8
  4. package/node/prelude/buffer.js +0 -0
  5. package/node/prelude/diagnostics_channel.js +322 -0
  6. package/node/prelude/dns.js +3 -2
  7. package/node/prelude/events.js +17 -3
  8. package/node/prelude/fs.js +177 -5
  9. package/node/prelude/fs_promises.js +24 -0
  10. package/node/prelude/http.js +13 -4
  11. package/node/prelude/http2.js +0 -0
  12. package/node/prelude/internal/async_context.js +27 -0
  13. package/node/prelude/internal/crypto/asym.js +0 -0
  14. package/node/prelude/internal/crypto/cipher.js +0 -0
  15. package/node/prelude/internal/crypto/kdf.js +0 -0
  16. package/node/prelude/internal/crypto/keys.js +0 -0
  17. package/node/prelude/internal/crypto/random.js +0 -0
  18. package/node/prelude/internal/crypto/util.js +0 -0
  19. package/node/prelude/internal/errors.js +11 -0
  20. package/node/prelude/internal/process_events.js +14 -0
  21. package/node/prelude/internal/process_signals.js +42 -0
  22. package/node/prelude/internal/querystring.js +0 -0
  23. package/node/prelude/internal/timers.js +233 -0
  24. package/node/prelude/internal/timers_global.js +9 -0
  25. package/node/prelude/internal/zlib_brotli.js +6 -0
  26. package/node/prelude/internal/zlib_engines.js +4 -0
  27. package/node/prelude/internal/zlib_zstd.js +6 -0
  28. package/node/prelude/module.js +22 -6
  29. package/node/prelude/net.js +9 -8
  30. package/node/prelude/os.js +0 -0
  31. package/node/prelude/path.js +1599 -186
  32. package/node/prelude/path_posix.js +9 -0
  33. package/node/prelude/path_win32.js +9 -0
  34. package/node/prelude/process.js +3 -0
  35. package/node/prelude/querystring.js +0 -0
  36. package/node/prelude/stream.js +18 -6
  37. package/node/prelude/stream_promises.js +0 -0
  38. package/node/prelude/stream_web.js +0 -0
  39. package/node/prelude/string_decoder.js +0 -0
  40. package/node/prelude/timers.js +92 -0
  41. package/node/prelude/timers_promises.js +133 -0
  42. package/node/prelude/tty.js +0 -0
  43. package/node/prelude/url.js +0 -0
  44. package/node/prelude/util.js +0 -0
  45. package/node/prelude/zlib.js +912 -72
  46. package/node/src/host_brotli.c +157 -0
  47. package/node/src/host_fs.c +95 -1
  48. package/node/src/host_loop.c +10 -4
  49. package/node/src/host_os.c +0 -0
  50. package/node/src/host_signal.c +70 -0
  51. package/node/src/host_sys.c +50 -0
  52. package/node/src/host_zlib.c +314 -0
  53. package/node/src/host_zstd.c +179 -0
  54. package/node/third_party/brotli/LICENSE +19 -0
  55. package/node/third_party/brotli/common/constants.c +15 -0
  56. package/node/third_party/brotli/common/constants.h +201 -0
  57. package/node/third_party/brotli/common/context.c +156 -0
  58. package/node/third_party/brotli/common/context.h +113 -0
  59. package/node/third_party/brotli/common/dictionary.c +5916 -0
  60. package/node/third_party/brotli/common/dictionary.h +64 -0
  61. package/node/third_party/brotli/common/platform.c +23 -0
  62. package/node/third_party/brotli/common/platform.h +541 -0
  63. package/node/third_party/brotli/common/shared_dictionary.c +521 -0
  64. package/node/third_party/brotli/common/shared_dictionary_internal.h +75 -0
  65. package/node/third_party/brotli/common/transform.c +291 -0
  66. package/node/third_party/brotli/common/transform.h +85 -0
  67. package/node/third_party/brotli/common/version.h +51 -0
  68. package/node/third_party/brotli/dec/bit_reader.c +78 -0
  69. package/node/third_party/brotli/dec/bit_reader.h +423 -0
  70. package/node/third_party/brotli/dec/decode.c +2875 -0
  71. package/node/third_party/brotli/dec/huffman.c +342 -0
  72. package/node/third_party/brotli/dec/huffman.h +122 -0
  73. package/node/third_party/brotli/dec/prefix.h +733 -0
  74. package/node/third_party/brotli/dec/state.c +183 -0
  75. package/node/third_party/brotli/dec/state.h +400 -0
  76. package/node/third_party/brotli/enc/backward_references.c +207 -0
  77. package/node/third_party/brotli/enc/backward_references.h +40 -0
  78. package/node/third_party/brotli/enc/backward_references_hq.c +939 -0
  79. package/node/third_party/brotli/enc/backward_references_hq.h +96 -0
  80. package/node/third_party/brotli/enc/backward_references_inc.h +189 -0
  81. package/node/third_party/brotli/enc/bit_cost.c +36 -0
  82. package/node/third_party/brotli/enc/bit_cost.h +64 -0
  83. package/node/third_party/brotli/enc/bit_cost_inc.h +127 -0
  84. package/node/third_party/brotli/enc/block_encoder_inc.h +34 -0
  85. package/node/third_party/brotli/enc/block_splitter.c +217 -0
  86. package/node/third_party/brotli/enc/block_splitter.h +52 -0
  87. package/node/third_party/brotli/enc/block_splitter_inc.h +481 -0
  88. package/node/third_party/brotli/enc/brotli_bit_stream.c +1336 -0
  89. package/node/third_party/brotli/enc/brotli_bit_stream.h +89 -0
  90. package/node/third_party/brotli/enc/cluster.c +57 -0
  91. package/node/third_party/brotli/enc/cluster.h +49 -0
  92. package/node/third_party/brotli/enc/cluster_inc.h +325 -0
  93. package/node/third_party/brotli/enc/command.c +28 -0
  94. package/node/third_party/brotli/enc/command.h +191 -0
  95. package/node/third_party/brotli/enc/compound_dictionary.c +207 -0
  96. package/node/third_party/brotli/enc/compound_dictionary.h +74 -0
  97. package/node/third_party/brotli/enc/compress_fragment.c +800 -0
  98. package/node/third_party/brotli/enc/compress_fragment.h +86 -0
  99. package/node/third_party/brotli/enc/compress_fragment_two_pass.c +657 -0
  100. package/node/third_party/brotli/enc/compress_fragment_two_pass.h +72 -0
  101. package/node/third_party/brotli/enc/dictionary_hash.c +1848 -0
  102. package/node/third_party/brotli/enc/dictionary_hash.h +25 -0
  103. package/node/third_party/brotli/enc/encode.c +1996 -0
  104. package/node/third_party/brotli/enc/encoder_dict.c +640 -0
  105. package/node/third_party/brotli/enc/encoder_dict.h +157 -0
  106. package/node/third_party/brotli/enc/entropy_encode.c +504 -0
  107. package/node/third_party/brotli/enc/entropy_encode.h +123 -0
  108. package/node/third_party/brotli/enc/entropy_encode_static.h +542 -0
  109. package/node/third_party/brotli/enc/fast_log.c +105 -0
  110. package/node/third_party/brotli/enc/fast_log.h +67 -0
  111. package/node/third_party/brotli/enc/find_match_length.h +72 -0
  112. package/node/third_party/brotli/enc/hash.h +728 -0
  113. package/node/third_party/brotli/enc/hash_composite_inc.h +140 -0
  114. package/node/third_party/brotli/enc/hash_forgetful_chain_inc.h +295 -0
  115. package/node/third_party/brotli/enc/hash_longest_match64_inc.h +262 -0
  116. package/node/third_party/brotli/enc/hash_longest_match_inc.h +258 -0
  117. package/node/third_party/brotli/enc/hash_longest_match_quickly_inc.h +266 -0
  118. package/node/third_party/brotli/enc/hash_rolling_inc.h +212 -0
  119. package/node/third_party/brotli/enc/hash_to_binary_tree_inc.h +330 -0
  120. package/node/third_party/brotli/enc/histogram.c +100 -0
  121. package/node/third_party/brotli/enc/histogram.h +64 -0
  122. package/node/third_party/brotli/enc/histogram_inc.h +51 -0
  123. package/node/third_party/brotli/enc/literal_cost.c +180 -0
  124. package/node/third_party/brotli/enc/literal_cost.h +32 -0
  125. package/node/third_party/brotli/enc/memory.c +194 -0
  126. package/node/third_party/brotli/enc/memory.h +131 -0
  127. package/node/third_party/brotli/enc/metablock.c +677 -0
  128. package/node/third_party/brotli/enc/metablock.h +106 -0
  129. package/node/third_party/brotli/enc/metablock_inc.h +185 -0
  130. package/node/third_party/brotli/enc/params.h +47 -0
  131. package/node/third_party/brotli/enc/prefix.h +54 -0
  132. package/node/third_party/brotli/enc/quality.h +202 -0
  133. package/node/third_party/brotli/enc/ringbuffer.h +168 -0
  134. package/node/third_party/brotli/enc/state.h +104 -0
  135. package/node/third_party/brotli/enc/static_dict.c +542 -0
  136. package/node/third_party/brotli/enc/static_dict.h +41 -0
  137. package/node/third_party/brotli/enc/static_dict_lut.h +5866 -0
  138. package/node/third_party/brotli/enc/utf8_util.c +85 -0
  139. package/node/third_party/brotli/enc/utf8_util.h +33 -0
  140. package/node/third_party/brotli/enc/write_bits.h +88 -0
  141. package/node/third_party/brotli/include/brotli/decode.h +409 -0
  142. package/node/third_party/brotli/include/brotli/encode.h +501 -0
  143. package/node/third_party/brotli/include/brotli/port.h +305 -0
  144. package/node/third_party/brotli/include/brotli/shared_dictionary.h +100 -0
  145. package/node/third_party/brotli/include/brotli/types.h +83 -0
  146. package/node/third_party/libuv/LICENSE +0 -0
  147. package/node/third_party/libuv/include/uv/aix.h +0 -0
  148. package/node/third_party/libuv/include/uv/bsd.h +0 -0
  149. package/node/third_party/libuv/include/uv/darwin.h +0 -0
  150. package/node/third_party/libuv/include/uv/errno.h +0 -0
  151. package/node/third_party/libuv/include/uv/linux.h +0 -0
  152. package/node/third_party/libuv/include/uv/os390.h +0 -0
  153. package/node/third_party/libuv/include/uv/posix.h +0 -0
  154. package/node/third_party/libuv/include/uv/sunos.h +0 -0
  155. package/node/third_party/libuv/include/uv/threadpool.h +0 -0
  156. package/node/third_party/libuv/include/uv/tree.h +0 -0
  157. package/node/third_party/libuv/include/uv/unix.h +0 -0
  158. package/node/third_party/libuv/include/uv/version.h +0 -0
  159. package/node/third_party/libuv/include/uv/win.h +0 -0
  160. package/node/third_party/libuv/include/uv.h +0 -0
  161. package/node/third_party/libuv/src/fs-poll.c +0 -0
  162. package/node/third_party/libuv/src/heap-inl.h +0 -0
  163. package/node/third_party/libuv/src/idna.c +0 -0
  164. package/node/third_party/libuv/src/idna.h +0 -0
  165. package/node/third_party/libuv/src/inet.c +0 -0
  166. package/node/third_party/libuv/src/queue.h +0 -0
  167. package/node/third_party/libuv/src/random.c +0 -0
  168. package/node/third_party/libuv/src/strscpy.c +0 -0
  169. package/node/third_party/libuv/src/strscpy.h +0 -0
  170. package/node/third_party/libuv/src/strtok.c +0 -0
  171. package/node/third_party/libuv/src/strtok.h +0 -0
  172. package/node/third_party/libuv/src/thread-common.c +0 -0
  173. package/node/third_party/libuv/src/threadpool.c +0 -0
  174. package/node/third_party/libuv/src/timer.c +0 -0
  175. package/node/third_party/libuv/src/unix/async.c +0 -0
  176. package/node/third_party/libuv/src/unix/bsd-ifaddrs.c +0 -0
  177. package/node/third_party/libuv/src/unix/core.c +0 -0
  178. package/node/third_party/libuv/src/unix/darwin-proctitle.c +0 -0
  179. package/node/third_party/libuv/src/unix/darwin-stub.h +0 -0
  180. package/node/third_party/libuv/src/unix/darwin-syscalls.h +0 -0
  181. package/node/third_party/libuv/src/unix/darwin.c +0 -0
  182. package/node/third_party/libuv/src/unix/dl.c +0 -0
  183. package/node/third_party/libuv/src/unix/fs.c +0 -0
  184. package/node/third_party/libuv/src/unix/fsevents.c +0 -0
  185. package/node/third_party/libuv/src/unix/getaddrinfo.c +0 -0
  186. package/node/third_party/libuv/src/unix/getnameinfo.c +0 -0
  187. package/node/third_party/libuv/src/unix/internal.h +0 -0
  188. package/node/third_party/libuv/src/unix/kqueue.c +0 -0
  189. package/node/third_party/libuv/src/unix/linux.c +0 -0
  190. package/node/third_party/libuv/src/unix/loop-watcher.c +0 -0
  191. package/node/third_party/libuv/src/unix/loop.c +0 -0
  192. package/node/third_party/libuv/src/unix/pipe.c +0 -0
  193. package/node/third_party/libuv/src/unix/poll.c +0 -0
  194. package/node/third_party/libuv/src/unix/process.c +0 -0
  195. package/node/third_party/libuv/src/unix/procfs-exepath.c +0 -0
  196. package/node/third_party/libuv/src/unix/proctitle.c +0 -0
  197. package/node/third_party/libuv/src/unix/random-devurandom.c +0 -0
  198. package/node/third_party/libuv/src/unix/random-getentropy.c +0 -0
  199. package/node/third_party/libuv/src/unix/random-getrandom.c +0 -0
  200. package/node/third_party/libuv/src/unix/random-sysctl-linux.c +0 -0
  201. package/node/third_party/libuv/src/unix/signal.c +0 -0
  202. package/node/third_party/libuv/src/unix/stream.c +0 -0
  203. package/node/third_party/libuv/src/unix/tcp.c +0 -0
  204. package/node/third_party/libuv/src/unix/thread.c +0 -0
  205. package/node/third_party/libuv/src/unix/tty.c +0 -0
  206. package/node/third_party/libuv/src/unix/udp.c +0 -0
  207. package/node/third_party/libuv/src/uv-common.c +0 -0
  208. package/node/third_party/libuv/src/uv-common.h +0 -0
  209. package/node/third_party/libuv/src/uv-data-getter-setters.c +0 -0
  210. package/node/third_party/libuv/src/version.c +0 -0
  211. package/node/third_party/llhttp/LICENSE +0 -0
  212. package/node/third_party/llhttp/api.c +0 -0
  213. package/node/third_party/llhttp/http.c +0 -0
  214. package/node/third_party/llhttp/llhttp.c +0 -0
  215. package/node/third_party/llhttp/llhttp.h +0 -0
  216. package/node/third_party/zlib/LICENSE +19 -0
  217. package/node/third_party/zlib/README.chromium +38 -0
  218. package/node/third_party/zlib/adler32.c +197 -0
  219. package/node/third_party/zlib/chromeconf.h +203 -0
  220. package/node/third_party/zlib/contrib/optimizations/insert_string.h +80 -0
  221. package/node/third_party/zlib/cpu_features.c +213 -0
  222. package/node/third_party/zlib/cpu_features.h +22 -0
  223. package/node/third_party/zlib/crc32.c +1192 -0
  224. package/node/third_party/zlib/crc32.h +9446 -0
  225. package/node/third_party/zlib/deflate.c +2289 -0
  226. package/node/third_party/zlib/deflate.h +407 -0
  227. package/node/third_party/zlib/gzguts.h +214 -0
  228. package/node/third_party/zlib/inffast.c +327 -0
  229. package/node/third_party/zlib/inffast.h +26 -0
  230. package/node/third_party/zlib/inffixed.h +94 -0
  231. package/node/third_party/zlib/inflate.c +1528 -0
  232. package/node/third_party/zlib/inflate.h +126 -0
  233. package/node/third_party/zlib/inftrees.c +299 -0
  234. package/node/third_party/zlib/inftrees.h +62 -0
  235. package/node/third_party/zlib/trees.c +1161 -0
  236. package/node/third_party/zlib/trees.h +128 -0
  237. package/node/third_party/zlib/zconf.h +558 -0
  238. package/node/third_party/zlib/zlib.h +1967 -0
  239. package/node/third_party/zlib/zutil.c +299 -0
  240. package/node/third_party/zlib/zutil.h +275 -0
  241. package/node/third_party/zstd/LICENSE +30 -0
  242. package/node/third_party/zstd/common/allocations.h +55 -0
  243. package/node/third_party/zstd/common/bits.h +205 -0
  244. package/node/third_party/zstd/common/bitstream.h +454 -0
  245. package/node/third_party/zstd/common/compiler.h +464 -0
  246. package/node/third_party/zstd/common/cpu.h +249 -0
  247. package/node/third_party/zstd/common/debug.c +30 -0
  248. package/node/third_party/zstd/common/debug.h +107 -0
  249. package/node/third_party/zstd/common/entropy_common.c +340 -0
  250. package/node/third_party/zstd/common/error_private.c +64 -0
  251. package/node/third_party/zstd/common/error_private.h +158 -0
  252. package/node/third_party/zstd/common/fse.h +625 -0
  253. package/node/third_party/zstd/common/fse_decompress.c +315 -0
  254. package/node/third_party/zstd/common/huf.h +277 -0
  255. package/node/third_party/zstd/common/mem.h +422 -0
  256. package/node/third_party/zstd/common/pool.c +371 -0
  257. package/node/third_party/zstd/common/pool.h +81 -0
  258. package/node/third_party/zstd/common/portability_macros.h +171 -0
  259. package/node/third_party/zstd/common/threading.c +182 -0
  260. package/node/third_party/zstd/common/threading.h +142 -0
  261. package/node/third_party/zstd/common/xxhash.c +18 -0
  262. package/node/third_party/zstd/common/xxhash.h +7094 -0
  263. package/node/third_party/zstd/common/zstd_common.c +48 -0
  264. package/node/third_party/zstd/common/zstd_deps.h +123 -0
  265. package/node/third_party/zstd/common/zstd_internal.h +324 -0
  266. package/node/third_party/zstd/common/zstd_trace.h +156 -0
  267. package/node/third_party/zstd/compress/clevels.h +134 -0
  268. package/node/third_party/zstd/compress/fse_compress.c +625 -0
  269. package/node/third_party/zstd/compress/hist.c +191 -0
  270. package/node/third_party/zstd/compress/hist.h +82 -0
  271. package/node/third_party/zstd/compress/huf_compress.c +1464 -0
  272. package/node/third_party/zstd/compress/zstd_compress.c +7843 -0
  273. package/node/third_party/zstd/compress/zstd_compress_internal.h +1636 -0
  274. package/node/third_party/zstd/compress/zstd_compress_literals.c +235 -0
  275. package/node/third_party/zstd/compress/zstd_compress_literals.h +39 -0
  276. package/node/third_party/zstd/compress/zstd_compress_sequences.c +442 -0
  277. package/node/third_party/zstd/compress/zstd_compress_sequences.h +55 -0
  278. package/node/third_party/zstd/compress/zstd_compress_superblock.c +688 -0
  279. package/node/third_party/zstd/compress/zstd_compress_superblock.h +32 -0
  280. package/node/third_party/zstd/compress/zstd_cwksp.h +765 -0
  281. package/node/third_party/zstd/compress/zstd_double_fast.c +778 -0
  282. package/node/third_party/zstd/compress/zstd_double_fast.h +42 -0
  283. package/node/third_party/zstd/compress/zstd_fast.c +985 -0
  284. package/node/third_party/zstd/compress/zstd_fast.h +30 -0
  285. package/node/third_party/zstd/compress/zstd_lazy.c +2199 -0
  286. package/node/third_party/zstd/compress/zstd_lazy.h +193 -0
  287. package/node/third_party/zstd/compress/zstd_ldm.c +745 -0
  288. package/node/third_party/zstd/compress/zstd_ldm.h +109 -0
  289. package/node/third_party/zstd/compress/zstd_ldm_geartab.h +106 -0
  290. package/node/third_party/zstd/compress/zstd_opt.c +1580 -0
  291. package/node/third_party/zstd/compress/zstd_opt.h +72 -0
  292. package/node/third_party/zstd/compress/zstd_preSplit.c +238 -0
  293. package/node/third_party/zstd/compress/zstd_preSplit.h +33 -0
  294. package/node/third_party/zstd/compress/zstdmt_compress.c +1923 -0
  295. package/node/third_party/zstd/compress/zstdmt_compress.h +102 -0
  296. package/node/third_party/zstd/decompress/huf_decompress.c +1944 -0
  297. package/node/third_party/zstd/decompress/zstd_ddict.c +244 -0
  298. package/node/third_party/zstd/decompress/zstd_ddict.h +44 -0
  299. package/node/third_party/zstd/decompress/zstd_decompress.c +2410 -0
  300. package/node/third_party/zstd/decompress/zstd_decompress_block.c +2209 -0
  301. package/node/third_party/zstd/decompress/zstd_decompress_block.h +73 -0
  302. package/node/third_party/zstd/decompress/zstd_decompress_internal.h +240 -0
  303. package/node/third_party/zstd/zdict.h +481 -0
  304. package/node/third_party/zstd/zstd.h +3198 -0
  305. package/node/third_party/zstd/zstd_errors.h +107 -0
  306. package/package.json +2 -3
  307. package/runtime/include/js_atoms.gen.h +0 -0
  308. package/runtime/include/js_atoms.h +0 -0
  309. package/runtime/include/js_bigint.h +0 -0
  310. package/runtime/include/js_buffer.h +0 -0
  311. package/runtime/include/js_builtins.h +0 -0
  312. package/runtime/include/js_console.h +5 -2
  313. package/runtime/include/js_convert.h +0 -0
  314. package/runtime/include/js_core.def +0 -0
  315. package/runtime/include/js_error.h +0 -0
  316. package/runtime/include/js_exception.h +0 -0
  317. package/runtime/include/js_function.h +0 -0
  318. package/runtime/include/js_gc.h +0 -0
  319. package/runtime/include/js_generator.h +0 -0
  320. package/runtime/include/js_host.h +5 -3
  321. package/runtime/include/js_jobs.h +18 -1
  322. package/runtime/include/js_module.h +0 -0
  323. package/runtime/include/js_object.h +0 -0
  324. package/runtime/include/js_ops.h +0 -0
  325. package/runtime/include/js_promise.h +1 -0
  326. package/runtime/include/js_regexp.h +0 -0
  327. package/runtime/include/js_runtime.h +0 -0
  328. package/runtime/include/js_symbol.h +0 -0
  329. package/runtime/include/js_web.h +0 -0
  330. package/runtime/include/jscell.h +0 -0
  331. package/runtime/include/jscontext.h +14 -0
  332. package/runtime/include/jsnum.h +0 -0
  333. package/runtime/include/jsstring.h +0 -0
  334. package/runtime/include/jsvalue.h +0 -0
  335. package/runtime/src/arguments.c +0 -0
  336. package/runtime/src/array.c +0 -0
  337. package/runtime/src/arraybuffer.c +0 -0
  338. package/runtime/src/async_iter.c +0 -0
  339. package/runtime/src/atoms.c +0 -0
  340. package/runtime/src/base64.c +0 -0
  341. package/runtime/src/bigint.c +0 -0
  342. package/runtime/src/blob.c +0 -0
  343. package/runtime/src/buffer.c +20 -16
  344. package/runtime/src/builtin_table.c +0 -0
  345. package/runtime/src/builtins.c +0 -0
  346. package/runtime/src/builtins_util.h +0 -0
  347. package/runtime/src/collections.c +0 -0
  348. package/runtime/src/components.c +0 -0
  349. package/runtime/src/console.c +15 -2
  350. package/runtime/src/convert.c +0 -0
  351. package/runtime/src/core_all.c +0 -0
  352. package/runtime/src/crypto.c +0 -0
  353. package/runtime/src/crypto_host.c +0 -0
  354. package/runtime/src/crypto_kdf.c +0 -0
  355. package/runtime/src/crypto_key.c +0 -0
  356. package/runtime/src/date.c +0 -0
  357. package/runtime/src/domexception.c +0 -0
  358. package/runtime/src/elements.c +0 -0
  359. package/runtime/src/elements.h +0 -0
  360. package/runtime/src/encoding.c +0 -0
  361. package/runtime/src/error.c +0 -0
  362. package/runtime/src/events.c +1 -1
  363. package/runtime/src/exception.c +0 -0
  364. package/runtime/src/fetch.c +0 -0
  365. package/runtime/src/function.c +0 -0
  366. package/runtime/src/gc.c +2 -0
  367. package/runtime/src/generator.c +0 -0
  368. package/runtime/src/global.c +0 -0
  369. package/runtime/src/headers.c +0 -0
  370. package/runtime/src/inspect.c +0 -0
  371. package/runtime/src/internal.h +0 -0
  372. package/runtime/src/iterate.c +0 -0
  373. package/runtime/src/iterator.c +0 -0
  374. package/runtime/src/jobs.c +123 -44
  375. package/runtime/src/jsnum.c +0 -0
  376. package/runtime/src/json.c +0 -0
  377. package/runtime/src/math.c +0 -0
  378. package/runtime/src/module.c +0 -0
  379. package/runtime/src/number.c +0 -0
  380. package/runtime/src/object.c +0 -0
  381. package/runtime/src/ops.c +0 -0
  382. package/runtime/src/os.c +0 -0
  383. package/runtime/src/os.h +0 -0
  384. package/runtime/src/process.c +92 -8
  385. package/runtime/src/promise.c +7 -2
  386. package/runtime/src/proxy.c +0 -0
  387. package/runtime/src/reflect.c +0 -0
  388. package/runtime/src/regexp.c +0 -0
  389. package/runtime/src/regexp_anchor.h +0 -0
  390. package/runtime/src/regexp_message.h +0 -0
  391. package/runtime/src/shape.c +0 -0
  392. package/runtime/src/shape.h +0 -0
  393. package/runtime/src/streams.c +0 -0
  394. package/runtime/src/streams.h +0 -0
  395. package/runtime/src/string.c +0 -0
  396. package/runtime/src/string_builtins.c +0 -0
  397. package/runtime/src/symbol.c +0 -0
  398. package/runtime/src/test_host.c +0 -0
  399. package/runtime/src/typedarray.c +0 -0
  400. package/runtime/src/tznames.gen.h +0 -0
  401. package/runtime/src/uri.c +0 -0
  402. package/runtime/src/url.c +0 -0
  403. package/runtime/src/weak.c +1 -4
  404. package/runtime/src/web.c +0 -0
  405. package/runtime/src/wrapper.c +0 -0
  406. package/runtime/src/writable.c +0 -0
  407. package/runtime/third_party/ada-idna/LICENSE-MIT +0 -0
  408. package/runtime/third_party/ada-idna/README.md +0 -0
  409. package/runtime/third_party/ada-idna/convert.mjs +0 -0
  410. package/runtime/third_party/ada-idna/idna.c +0 -0
  411. package/runtime/third_party/ada-idna/idna.h +0 -0
  412. package/runtime/third_party/ada-idna/idna_tables.h +0 -0
  413. package/runtime/third_party/quickjs-dtoa/LICENSE +0 -0
  414. package/runtime/third_party/quickjs-dtoa/README.md +0 -0
  415. package/runtime/third_party/quickjs-dtoa/dtoa.c +0 -0
  416. package/runtime/third_party/quickjs-dtoa/dtoa.h +0 -0
  417. package/runtime/third_party/quickjs-dtoa/dtoa_compat.h +0 -0
  418. package/runtime/third_party/quickjs-regexp/LICENSE +0 -0
  419. package/runtime/third_party/quickjs-regexp/README.md +0 -0
  420. package/runtime/third_party/quickjs-regexp/cutils.c +0 -0
  421. package/runtime/third_party/quickjs-regexp/cutils.h +0 -0
  422. package/runtime/third_party/quickjs-regexp/libregexp-opcode.h +0 -0
  423. package/runtime/third_party/quickjs-regexp/libregexp.c +0 -0
  424. package/runtime/third_party/quickjs-regexp/libregexp.h +0 -0
  425. package/runtime/third_party/quickjs-regexp/libunicode-table.h +0 -0
  426. package/runtime/third_party/quickjs-regexp/libunicode.c +0 -0
  427. package/runtime/third_party/quickjs-regexp/libunicode.h +0 -0
  428. package/runtime/third_party/v8-ieee754/LICENSE +0 -0
  429. package/runtime/third_party/v8-ieee754/README.md +0 -0
  430. package/runtime/third_party/v8-ieee754/convert.py +0 -0
  431. package/runtime/third_party/v8-ieee754/ieee754.c +0 -0
  432. package/runtime/third_party/v8-ieee754/ieee754.h +0 -0
  433. package/runtime/tools/regexp_compile.c +0 -0
@@ -1,81 +1,921 @@
1
- // node:zlib (ADR 0012, layer 3): its constants and crc32. Compression itself isn't provided yet:
2
- // the streams and functions throw ERR_VISALJS_UNSUPPORTED when called (Express's body-parser
3
- // reaches them only for a request body with a Content-Encoding).
4
- import { invalidArgType, notSupported } from "./internal/errors.js";
5
-
6
- export const constants = Object.freeze({Z_NO_FLUSH: 0, Z_PARTIAL_FLUSH: 1, Z_SYNC_FLUSH: 2, Z_FULL_FLUSH: 3, Z_FINISH: 4, Z_BLOCK: 5, Z_OK: 0, Z_STREAM_END: 1, Z_NEED_DICT: 2, Z_ERRNO: -1, Z_STREAM_ERROR: -2, Z_DATA_ERROR: -3, Z_MEM_ERROR: -4, Z_BUF_ERROR: -5, Z_VERSION_ERROR: -6, Z_NO_COMPRESSION: 0, Z_BEST_SPEED: 1, Z_BEST_COMPRESSION: 9, Z_DEFAULT_COMPRESSION: -1, Z_FILTERED: 1, Z_HUFFMAN_ONLY: 2, Z_RLE: 3, Z_FIXED: 4, Z_DEFAULT_STRATEGY: 0, ZLIB_VERNUM: 4880, DEFLATE: 1, INFLATE: 2, GZIP: 3, GUNZIP: 4, DEFLATERAW: 5, INFLATERAW: 6, UNZIP: 7, BROTLI_DECODE: 8, BROTLI_ENCODE: 9, Z_MIN_WINDOWBITS: 8, Z_MAX_WINDOWBITS: 15, Z_DEFAULT_WINDOWBITS: 15, Z_MIN_CHUNK: 64, Z_MAX_CHUNK: null, Z_DEFAULT_CHUNK: 16384, Z_MIN_MEMLEVEL: 1, Z_MAX_MEMLEVEL: 9, Z_DEFAULT_MEMLEVEL: 8, Z_MIN_LEVEL: -1, Z_MAX_LEVEL: 9, Z_DEFAULT_LEVEL: -1, BROTLI_OPERATION_PROCESS: 0, BROTLI_OPERATION_FLUSH: 1, BROTLI_OPERATION_FINISH: 2, BROTLI_OPERATION_EMIT_METADATA: 3, BROTLI_PARAM_MODE: 0, BROTLI_MODE_GENERIC: 0, BROTLI_MODE_TEXT: 1, BROTLI_MODE_FONT: 2, BROTLI_DEFAULT_MODE: 0, BROTLI_PARAM_QUALITY: 1, BROTLI_MIN_QUALITY: 0, BROTLI_MAX_QUALITY: 11, BROTLI_DEFAULT_QUALITY: 11, BROTLI_PARAM_LGWIN: 2, BROTLI_MIN_WINDOW_BITS: 10, BROTLI_MAX_WINDOW_BITS: 24, BROTLI_LARGE_MAX_WINDOW_BITS: 30, BROTLI_DEFAULT_WINDOW: 22, BROTLI_PARAM_LGBLOCK: 3, BROTLI_MIN_INPUT_BLOCK_BITS: 16, BROTLI_MAX_INPUT_BLOCK_BITS: 24, BROTLI_PARAM_DISABLE_LITERAL_CONTEXT_MODELING: 4, BROTLI_PARAM_SIZE_HINT: 5, BROTLI_PARAM_LARGE_WINDOW: 6, BROTLI_PARAM_NPOSTFIX: 7, BROTLI_PARAM_NDIRECT: 8, BROTLI_DECODER_RESULT_ERROR: 0, BROTLI_DECODER_RESULT_SUCCESS: 1, BROTLI_DECODER_RESULT_NEEDS_MORE_INPUT: 2, BROTLI_DECODER_RESULT_NEEDS_MORE_OUTPUT: 3, BROTLI_DECODER_PARAM_DISABLE_RING_BUFFER_REALLOCATION: 0, BROTLI_DECODER_PARAM_LARGE_WINDOW: 1, BROTLI_DECODER_NO_ERROR: 0, BROTLI_DECODER_SUCCESS: 1, BROTLI_DECODER_NEEDS_MORE_INPUT: 2, BROTLI_DECODER_NEEDS_MORE_OUTPUT: 3, BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_NIBBLE: -1, BROTLI_DECODER_ERROR_FORMAT_RESERVED: -2, BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_META_NIBBLE: -3, BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_ALPHABET: -4, BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_SAME: -5, BROTLI_DECODER_ERROR_FORMAT_CL_SPACE: -6, BROTLI_DECODER_ERROR_FORMAT_HUFFMAN_SPACE: -7, BROTLI_DECODER_ERROR_FORMAT_CONTEXT_MAP_REPEAT: -8, BROTLI_DECODER_ERROR_FORMAT_BLOCK_LENGTH_1: -9, BROTLI_DECODER_ERROR_FORMAT_BLOCK_LENGTH_2: -10, BROTLI_DECODER_ERROR_FORMAT_TRANSFORM: -11, BROTLI_DECODER_ERROR_FORMAT_DICTIONARY: -12, BROTLI_DECODER_ERROR_FORMAT_WINDOW_BITS: -13, BROTLI_DECODER_ERROR_FORMAT_PADDING_1: -14, BROTLI_DECODER_ERROR_FORMAT_PADDING_2: -15, BROTLI_DECODER_ERROR_FORMAT_DISTANCE: -16, BROTLI_DECODER_ERROR_DICTIONARY_NOT_SET: -19, BROTLI_DECODER_ERROR_INVALID_ARGUMENTS: -20, BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MODES: -21, BROTLI_DECODER_ERROR_ALLOC_TREE_GROUPS: -22, BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MAP: -25, BROTLI_DECODER_ERROR_ALLOC_RING_BUFFER_1: -26, BROTLI_DECODER_ERROR_ALLOC_RING_BUFFER_2: -27, BROTLI_DECODER_ERROR_ALLOC_BLOCK_TYPE_TREES: -30, BROTLI_DECODER_ERROR_UNREACHABLE: -31});
7
- /* Node's codes: the names of the results, both ways */
8
- export const codes = Object.freeze({
9
- Z_OK: 0, Z_STREAM_END: 1, Z_NEED_DICT: 2, Z_ERRNO: -1, Z_STREAM_ERROR: -2, Z_DATA_ERROR: -3, Z_MEM_ERROR: -4, Z_BUF_ERROR: -5,
10
- Z_VERSION_ERROR: -6, 0: "Z_OK", 1: "Z_STREAM_END", 2: "Z_NEED_DICT", "-1": "Z_ERRNO", "-2": "Z_STREAM_ERROR", "-3": "Z_DATA_ERROR",
11
- "-4": "Z_MEM_ERROR", "-5": "Z_BUF_ERROR", "-6": "Z_VERSION_ERROR",
1
+ // node:zlib (ADR 0012, layer 3): Node's lib/zlib.js (v22) on Node's binding, which is C here
2
+ // (node/src/host_zlib.c over Chromium's zlib, the copy Node vendors): the same streams, the same
3
+ // convenience functions, and the same compressed bytes, Brotli's and zstd's too (node/src/host_brotli.c
4
+ // and host_zstd.c, linked into programs that name them: internal/zlib_engines.js). A write's
5
+ // callback runs a turn later, where Node's thread pool would call it back.
6
+ import { timerStart, zlibClose, zlibCrc32, zlibInit, zlibNew, zlibParams, zlibReset, zlibWrite } from "visaljs:host";
7
+ import { Buffer, kMaxLength } from "./buffer.js";
8
+ import { codeError, invalidArgType, outOfRange } from "./internal/errors.js";
9
+ import { finished, Transform } from "./stream.js";
10
+ import { deprecate } from "./util.js";
11
+ import { engines } from "./internal/zlib_engines.js";
12
+
13
+ /* Node's zlib.constants: a null-prototype object, not frozen */
14
+ export const constants = {
15
+ __proto__: null,
16
+ Z_NO_FLUSH: 0, Z_PARTIAL_FLUSH: 1, Z_SYNC_FLUSH: 2, Z_FULL_FLUSH: 3, Z_FINISH: 4, Z_BLOCK: 5, Z_OK: 0,
17
+ Z_STREAM_END: 1, Z_NEED_DICT: 2, Z_ERRNO: -1, Z_STREAM_ERROR: -2, Z_DATA_ERROR: -3, Z_MEM_ERROR: -4,
18
+ Z_BUF_ERROR: -5, Z_VERSION_ERROR: -6, Z_NO_COMPRESSION: 0, Z_BEST_SPEED: 1, Z_BEST_COMPRESSION: 9,
19
+ Z_DEFAULT_COMPRESSION: -1, Z_FILTERED: 1, Z_HUFFMAN_ONLY: 2, Z_RLE: 3, Z_FIXED: 4, Z_DEFAULT_STRATEGY: 0,
20
+ ZLIB_VERNUM: 4880, DEFLATE: 1, INFLATE: 2, GZIP: 3, GUNZIP: 4, DEFLATERAW: 5, INFLATERAW: 6, UNZIP: 7,
21
+ BROTLI_DECODE: 8, BROTLI_ENCODE: 9, ZSTD_DECOMPRESS: 11, ZSTD_COMPRESS: 10, Z_MIN_WINDOWBITS: 8,
22
+ Z_MAX_WINDOWBITS: 15, Z_DEFAULT_WINDOWBITS: 15, Z_MIN_CHUNK: 64, Z_MAX_CHUNK: Infinity,
23
+ Z_DEFAULT_CHUNK: 16384, Z_MIN_MEMLEVEL: 1, Z_MAX_MEMLEVEL: 9, Z_DEFAULT_MEMLEVEL: 8, Z_MIN_LEVEL: -1,
24
+ Z_MAX_LEVEL: 9, Z_DEFAULT_LEVEL: -1, BROTLI_OPERATION_PROCESS: 0, BROTLI_OPERATION_FLUSH: 1,
25
+ BROTLI_OPERATION_FINISH: 2, BROTLI_OPERATION_EMIT_METADATA: 3, BROTLI_PARAM_MODE: 0, BROTLI_MODE_GENERIC: 0,
26
+ BROTLI_MODE_TEXT: 1, BROTLI_MODE_FONT: 2, BROTLI_DEFAULT_MODE: 0, BROTLI_PARAM_QUALITY: 1,
27
+ BROTLI_MIN_QUALITY: 0, BROTLI_MAX_QUALITY: 11, BROTLI_DEFAULT_QUALITY: 11, BROTLI_PARAM_LGWIN: 2,
28
+ BROTLI_MIN_WINDOW_BITS: 10, BROTLI_MAX_WINDOW_BITS: 24, BROTLI_LARGE_MAX_WINDOW_BITS: 30,
29
+ BROTLI_DEFAULT_WINDOW: 22, BROTLI_PARAM_LGBLOCK: 3, BROTLI_MIN_INPUT_BLOCK_BITS: 16,
30
+ BROTLI_MAX_INPUT_BLOCK_BITS: 24, BROTLI_PARAM_DISABLE_LITERAL_CONTEXT_MODELING: 4, BROTLI_PARAM_SIZE_HINT: 5,
31
+ BROTLI_PARAM_LARGE_WINDOW: 6, BROTLI_PARAM_NPOSTFIX: 7, BROTLI_PARAM_NDIRECT: 8,
32
+ BROTLI_DECODER_RESULT_ERROR: 0, BROTLI_DECODER_RESULT_SUCCESS: 1, BROTLI_DECODER_RESULT_NEEDS_MORE_INPUT: 2,
33
+ BROTLI_DECODER_RESULT_NEEDS_MORE_OUTPUT: 3, BROTLI_DECODER_PARAM_DISABLE_RING_BUFFER_REALLOCATION: 0,
34
+ BROTLI_DECODER_PARAM_LARGE_WINDOW: 1, BROTLI_DECODER_NO_ERROR: 0, BROTLI_DECODER_SUCCESS: 1,
35
+ BROTLI_DECODER_NEEDS_MORE_INPUT: 2, BROTLI_DECODER_NEEDS_MORE_OUTPUT: 3,
36
+ BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_NIBBLE: -1, BROTLI_DECODER_ERROR_FORMAT_RESERVED: -2,
37
+ BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_META_NIBBLE: -3,
38
+ BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_ALPHABET: -4, BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_SAME: -5,
39
+ BROTLI_DECODER_ERROR_FORMAT_CL_SPACE: -6, BROTLI_DECODER_ERROR_FORMAT_HUFFMAN_SPACE: -7,
40
+ BROTLI_DECODER_ERROR_FORMAT_CONTEXT_MAP_REPEAT: -8, BROTLI_DECODER_ERROR_FORMAT_BLOCK_LENGTH_1: -9,
41
+ BROTLI_DECODER_ERROR_FORMAT_BLOCK_LENGTH_2: -10, BROTLI_DECODER_ERROR_FORMAT_TRANSFORM: -11,
42
+ BROTLI_DECODER_ERROR_FORMAT_DICTIONARY: -12, BROTLI_DECODER_ERROR_FORMAT_WINDOW_BITS: -13,
43
+ BROTLI_DECODER_ERROR_FORMAT_PADDING_1: -14, BROTLI_DECODER_ERROR_FORMAT_PADDING_2: -15,
44
+ BROTLI_DECODER_ERROR_FORMAT_DISTANCE: -16, BROTLI_DECODER_ERROR_DICTIONARY_NOT_SET: -19,
45
+ BROTLI_DECODER_ERROR_INVALID_ARGUMENTS: -20, BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MODES: -21,
46
+ BROTLI_DECODER_ERROR_ALLOC_TREE_GROUPS: -22, BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MAP: -25,
47
+ BROTLI_DECODER_ERROR_ALLOC_RING_BUFFER_1: -26, BROTLI_DECODER_ERROR_ALLOC_RING_BUFFER_2: -27,
48
+ BROTLI_DECODER_ERROR_ALLOC_BLOCK_TYPE_TREES: -30, BROTLI_DECODER_ERROR_UNREACHABLE: -31, ZSTD_e_continue: 0,
49
+ ZSTD_e_flush: 1, ZSTD_e_end: 2, ZSTD_fast: 1, ZSTD_dfast: 2, ZSTD_greedy: 3, ZSTD_lazy: 4, ZSTD_lazy2: 5,
50
+ ZSTD_btlazy2: 6, ZSTD_btopt: 7, ZSTD_btultra: 8, ZSTD_btultra2: 9, ZSTD_c_compressionLevel: 100,
51
+ ZSTD_c_windowLog: 101, ZSTD_c_hashLog: 102, ZSTD_c_chainLog: 103, ZSTD_c_searchLog: 104,
52
+ ZSTD_c_minMatch: 105, ZSTD_c_targetLength: 106, ZSTD_c_strategy: 107, ZSTD_c_enableLongDistanceMatching: 160,
53
+ ZSTD_c_ldmHashLog: 161, ZSTD_c_ldmMinMatch: 162, ZSTD_c_ldmBucketSizeLog: 163, ZSTD_c_ldmHashRateLog: 164,
54
+ ZSTD_c_contentSizeFlag: 200, ZSTD_c_checksumFlag: 201, ZSTD_c_dictIDFlag: 202, ZSTD_c_nbWorkers: 400,
55
+ ZSTD_c_jobSize: 401, ZSTD_c_overlapLog: 402, ZSTD_d_windowLogMax: 100, ZSTD_CLEVEL_DEFAULT: 3,
56
+ ZSTD_error_no_error: 0, ZSTD_error_GENERIC: 1, ZSTD_error_prefix_unknown: 10,
57
+ ZSTD_error_version_unsupported: 12, ZSTD_error_frameParameter_unsupported: 14,
58
+ ZSTD_error_frameParameter_windowTooLarge: 16, ZSTD_error_corruption_detected: 20,
59
+ ZSTD_error_checksum_wrong: 22, ZSTD_error_literals_headerWrong: 24, ZSTD_error_dictionary_corrupted: 30,
60
+ ZSTD_error_dictionary_wrong: 32, ZSTD_error_dictionaryCreation_failed: 34,
61
+ ZSTD_error_parameter_unsupported: 40, ZSTD_error_parameter_combination_unsupported: 41,
62
+ ZSTD_error_parameter_outOfBound: 42, ZSTD_error_tableLog_tooLarge: 44,
63
+ ZSTD_error_maxSymbolValue_tooLarge: 46, ZSTD_error_maxSymbolValue_tooSmall: 48,
64
+ ZSTD_error_stabilityCondition_notRespected: 50, ZSTD_error_stage_wrong: 60, ZSTD_error_init_missing: 62,
65
+ ZSTD_error_memory_allocation: 64, ZSTD_error_workSpace_tooSmall: 66, ZSTD_error_dstSize_tooSmall: 70,
66
+ ZSTD_error_srcSize_wrong: 72, ZSTD_error_dstBuffer_null: 74, ZSTD_error_noForwardProgress_destFull: 80,
67
+ ZSTD_error_noForwardProgress_inputEmpty: 82
68
+ };
69
+ const {
70
+ Z_NO_FLUSH, Z_BLOCK, Z_PARTIAL_FLUSH, Z_SYNC_FLUSH, Z_FULL_FLUSH, Z_FINISH,
71
+ Z_MIN_CHUNK, Z_MIN_WINDOWBITS, Z_MAX_WINDOWBITS, Z_MIN_LEVEL, Z_MAX_LEVEL,
72
+ Z_MIN_MEMLEVEL, Z_MAX_MEMLEVEL, Z_DEFAULT_CHUNK, Z_DEFAULT_COMPRESSION,
73
+ Z_DEFAULT_STRATEGY, Z_DEFAULT_WINDOWBITS, Z_DEFAULT_MEMLEVEL, Z_FIXED,
74
+ DEFLATE, DEFLATERAW, INFLATE, INFLATERAW, GZIP, GUNZIP, UNZIP, BROTLI_DECODE, BROTLI_ENCODE, ZSTD_DECOMPRESS,
75
+ BROTLI_OPERATION_PROCESS, BROTLI_OPERATION_FLUSH, BROTLI_OPERATION_FINISH, BROTLI_OPERATION_EMIT_METADATA,
76
+ ZSTD_COMPRESS, ZSTD_e_continue, ZSTD_e_flush, ZSTD_e_end,
77
+ } = constants;
78
+
79
+ /* the result codes' names, both ways */
80
+ export const codes = {
81
+ Z_OK: constants.Z_OK, Z_STREAM_END: constants.Z_STREAM_END, Z_NEED_DICT: constants.Z_NEED_DICT, Z_ERRNO: constants.Z_ERRNO,
82
+ Z_STREAM_ERROR: constants.Z_STREAM_ERROR, Z_DATA_ERROR: constants.Z_DATA_ERROR, Z_MEM_ERROR: constants.Z_MEM_ERROR,
83
+ Z_BUF_ERROR: constants.Z_BUF_ERROR, Z_VERSION_ERROR: constants.Z_VERSION_ERROR,
84
+ };
85
+ for (const ckey of Object.keys(codes)) codes[codes[ckey]] = ckey;
86
+ Object.freeze(codes);
87
+
88
+ const kFlushFlag = Symbol("kFlushFlag");
89
+ const kError = Symbol("kError");
90
+ const ownerSymbol = Symbol("owner_symbol");
91
+
92
+ const isArrayBufferView = (v) => ArrayBuffer.isView(v);
93
+ const isAnyArrayBuffer = (v) => v instanceof ArrayBuffer;
94
+ const emptyBuffer = () => Buffer.alloc(0);
95
+
96
+ function assert(value, message) {
97
+ if (!value) throw codeError(Error, "ERR_INTERNAL_ASSERTION", message ?? "Assertion failed");
98
+ }
99
+
100
+ const bufferTooLarge = (max) => codeError(RangeError, "ERR_BUFFER_TOO_LARGE", "Cannot create a Buffer larger than " + max + " bytes");
101
+
102
+ /* internal/validators' */
103
+ function validateFiniteNumber(number, name) {
104
+ if (number === undefined) return false;
105
+ if (Number.isFinite(number)) return true;
106
+ if (Number.isNaN(number)) return false;
107
+ if (typeof number !== "number") throw invalidArgType(name, "of type number", number);
108
+ throw outOfRange(name, "a finite number", number);
109
+ }
110
+
111
+ function checkRangesOrGetDefault(number, name, lower, upper, def) {
112
+ if (!validateFiniteNumber(number, name)) return def;
113
+ if (number < lower || number > upper) throw outOfRange(name, ">= " + lower + " and <= " + upper, number);
114
+ return number;
115
+ }
116
+
117
+ function validateFunction(value, name) {
118
+ if (typeof value !== "function") throw invalidArgType(name, "of type function", value);
119
+ }
120
+
121
+ /* Node's binding object for a stream (its CompressionStream), on the host's handle: write() runs
122
+ * the library now and calls back a turn later; a close while a write is pending waits for it, as
123
+ * there. `ops` are the host's primitives for the library. */
124
+ class CompressionHandle {
125
+ constructor(ops, native) {
126
+ this._ops = ops;
127
+ this._native = native;
128
+ this._writeResult = null;
129
+ this._writeCallback = null;
130
+ this._writing = false;
131
+ this._pendingClose = false;
132
+ this.onerror = null;
133
+ }
134
+
135
+ writeSync(flush, input, inOff, inLen, out, outOff, outLen) {
136
+ const failure = this._ops.write(this._native, flush, input, inOff, inLen, out, outOff, outLen, this._writeResult);
137
+ if (failure !== 0) this._emitError(failure);
138
+ }
139
+
140
+ write(flush, input, inOff, inLen, out, outOff, outLen) {
141
+ this._writing = true;
142
+ const failure = this._ops.write(this._native, flush, input, inOff, inLen, out, outOff, outLen, this._writeResult);
143
+ timerStart(() => {
144
+ this._writing = false;
145
+ if (failure !== 0) {
146
+ this._emitError(failure);
147
+ return;
148
+ }
149
+ this._writeCallback.call(this);
150
+ if (this._pendingClose) this.close();
151
+ }, -1, true, 0);
152
+ }
153
+
154
+ _emitError(failure) {
155
+ this.onerror?.call(this, failure[0], failure[1], failure[2]);
156
+ this._writing = false;
157
+ if (this._pendingClose) this.close();
158
+ }
159
+
160
+ reset() {
161
+ const failure = this._ops.reset(this._native);
162
+ if (failure !== 0) this._emitError(failure);
163
+ }
164
+
165
+ close() {
166
+ if (this._writing) {
167
+ this._pendingClose = true;
168
+ return;
169
+ }
170
+ this._pendingClose = false;
171
+ this._ops.close(this._native);
172
+ }
173
+ }
174
+
175
+ const zlibOps = { write: zlibWrite, reset: zlibReset, close: zlibClose };
176
+
177
+ class ZlibHandle extends CompressionHandle {
178
+ constructor(mode) {
179
+ super(zlibOps, zlibNew(mode));
180
+ }
181
+
182
+ init(windowBits, level, memLevel, strategy, writeResult, writeCallback, dictionary) {
183
+ this._writeResult = writeResult;
184
+ this._writeCallback = writeCallback;
185
+ zlibInit(this._native, windowBits, level, memLevel, strategy, isArrayBufferView(dictionary) ? dictionary : undefined);
186
+ }
187
+
188
+ params(level, strategy) {
189
+ const failure = zlibParams(this._native, level, strategy);
190
+ if (failure !== 0) this._emitError(failure);
191
+ }
192
+ }
193
+
194
+ /* an optional library's handle (internal/zlib_engines.js); not linked: Node's API is there, but
195
+ * creating a stream throws */
196
+ function engine(name, what) {
197
+ const ops = engines[name];
198
+ if (!ops) {
199
+ throw codeError(Error, "ERR_VISALJS_UNSUPPORTED",
200
+ what + " isn't linked into this program: visaljs links it when the program's code names it (" + what + "Compress, …)");
201
+ }
202
+ return ops;
203
+ }
204
+
205
+ class BrotliHandle extends CompressionHandle {
206
+ constructor(mode) {
207
+ const ops = engine("brotli", "Brotli");
208
+ super(ops, ops.new(mode));
209
+ }
210
+
211
+ init(params, writeResult, writeCallback) {
212
+ this._writeResult = writeResult;
213
+ this._writeCallback = writeCallback;
214
+ const failure = this._ops.init(this._native, params);
215
+ if (failure !== 0) {
216
+ this._emitError(failure);
217
+ throw codeError(Error, "ERR_ZLIB_INITIALIZATION_FAILED", "Initialization failed");
218
+ }
219
+ }
220
+
221
+ /* Brotli can't change its parameters mid-stream: Node's is a no-op too */
222
+ params() {}
223
+ }
224
+
225
+ class ZstdHandle extends CompressionHandle {
226
+ constructor(compress) {
227
+ const ops = engine("zstd", "Zstd");
228
+ super(ops, ops.new(compress));
229
+ }
230
+
231
+ init(params, pledgedSrcSize, writeResult, writeCallback, dictionary) {
232
+ this._writeResult = writeResult;
233
+ this._writeCallback = writeCallback;
234
+ if (typeof pledgedSrcSize === "number") {
235
+ pledgedSrcSize = Number.isNaN(pledgedSrcSize) ? 0 : Math.trunc(pledgedSrcSize);
236
+ if (pledgedSrcSize < 0) throw codeError(TypeError, "ERR_INVALID_ARG_VALUE", "pledgedSrcSize may not be negative");
237
+ } else {
238
+ pledgedSrcSize = undefined;
239
+ }
240
+ const failure = this._ops.init(this._native, params, pledgedSrcSize, dictionary);
241
+ if (failure !== 0) {
242
+ this._emitError(failure);
243
+ throw codeError(Error, "ERR_ZLIB_INITIALIZATION_FAILED", failure[0]);
244
+ }
245
+ }
246
+
247
+ params() {}
248
+ }
249
+
250
+ /* a legacy alias of the stream on its binding object */
251
+ Object.defineProperty(CompressionHandle.prototype, "jsref", {
252
+ __proto__: null,
253
+ get() {
254
+ return this[ownerSymbol];
255
+ },
256
+ set(v) {
257
+ this[ownerSymbol] = v;
258
+ },
12
259
  });
13
260
 
14
- let crcTable;
261
+ function zlibBuffer(engine, buffer, callback) {
262
+ validateFunction(callback, "callback");
263
+ /* streams take Uint8Arrays: another view becomes a Buffer over the same memory */
264
+ if (isArrayBufferView(buffer) && !(buffer instanceof Uint8Array)) {
265
+ buffer = Buffer.from(buffer.buffer, buffer.byteOffset, buffer.byteLength);
266
+ } else if (isAnyArrayBuffer(buffer)) {
267
+ buffer = Buffer.from(buffer);
268
+ }
269
+ engine.buffers = null;
270
+ engine.nread = 0;
271
+ engine.cb = callback;
272
+ engine.on("data", zlibBufferOnData);
273
+ engine.on("error", zlibBufferOnError);
274
+ engine.on("end", zlibBufferOnEnd);
275
+ engine.end(buffer);
276
+ }
15
277
 
16
- /** zlib.crc32(data, value = 0): CRC-32 (IEEE), as zlib computes it. */
17
- export function crc32(data, value = 0) {
18
- if (typeof data === "string") data = Buffer.from(data, "utf8");
19
- else if (!ArrayBuffer.isView(data)) throw invalidArgType("data", "of type string or an instance of Buffer, TypedArray, or DataView", data);
20
- if (typeof value !== "number") throw invalidArgType("value", "of type number", value);
21
- if (!crcTable) {
22
- crcTable = new Int32Array(256);
23
- for (let n = 0; n < 256; n++) {
24
- let c = n;
25
- for (let k = 0; k < 8; k++) c = c & 1 ? 0xedb88320 ^ (c >>> 1) : c >>> 1;
26
- crcTable[n] = c;
278
+ function zlibBufferOnData(chunk) {
279
+ if (!this.buffers) this.buffers = [chunk];
280
+ else this.buffers.push(chunk);
281
+ this.nread += chunk.length;
282
+ if (this.nread > this._maxOutputLength) {
283
+ this.close();
284
+ this.removeAllListeners("end");
285
+ this.cb(bufferTooLarge(this._maxOutputLength));
286
+ }
287
+ }
288
+
289
+ function zlibBufferOnError(err) {
290
+ this.removeAllListeners("end");
291
+ this.cb(err);
292
+ }
293
+
294
+ function zlibBufferOnEnd() {
295
+ let buf;
296
+ if (this.nread === 0) {
297
+ buf = emptyBuffer();
298
+ } else {
299
+ const bufs = this.buffers;
300
+ buf = bufs.length === 1 ? bufs[0] : Buffer.concat(bufs, this.nread);
301
+ }
302
+ this.close();
303
+ if (this._info) this.cb(null, { buffer: buf, engine: this });
304
+ else this.cb(null, buf);
305
+ }
306
+
307
+ function zlibBufferSync(engine, buffer) {
308
+ if (typeof buffer === "string") {
309
+ buffer = Buffer.from(buffer);
310
+ } else if (!isArrayBufferView(buffer)) {
311
+ if (isAnyArrayBuffer(buffer)) buffer = Buffer.from(buffer);
312
+ else throw invalidArgType("buffer", "of type string or an instance of Buffer, TypedArray, DataView, or ArrayBuffer", buffer);
313
+ }
314
+ buffer = processChunkSync(engine, buffer, engine._finishFlushFlag);
315
+ if (engine._info) return { buffer, engine };
316
+ return buffer;
317
+ }
318
+
319
+ function zlibOnError(message, errno, code) {
320
+ const self = this[ownerSymbol];
321
+ /* there's no way to recover cleanly */
322
+ const error = new Error(message);
323
+ error.errno = errno;
324
+ error.code = code;
325
+ self.destroy(error);
326
+ self[kError] = error;
327
+ }
328
+
329
+ /* the base of all the streams */
330
+ function ZlibBase(opts, mode, handle, { flush, finishFlush, fullFlush }) {
331
+ let chunkSize = Z_DEFAULT_CHUNK;
332
+ let maxOutputLength = kMaxLength;
333
+ assert(typeof mode === "number");
334
+ assert(mode >= DEFLATE && mode <= ZSTD_DECOMPRESS);
335
+ const brotli = mode === BROTLI_ENCODE || mode === BROTLI_DECODE;
336
+ const zstd = mode === ZSTD_COMPRESS || mode === ZSTD_DECOMPRESS;
337
+ const minFlush = brotli ? BROTLI_OPERATION_PROCESS : zstd ? ZSTD_e_continue : Z_NO_FLUSH;
338
+ const maxFlushFlag = brotli ? BROTLI_OPERATION_EMIT_METADATA : zstd ? ZSTD_e_end : Z_BLOCK;
339
+
340
+ if (opts) {
341
+ chunkSize = opts.chunkSize;
342
+ if (!validateFiniteNumber(chunkSize, "options.chunkSize")) {
343
+ chunkSize = Z_DEFAULT_CHUNK;
344
+ } else if (chunkSize < Z_MIN_CHUNK) {
345
+ throw outOfRange("options.chunkSize", ">= " + Z_MIN_CHUNK, chunkSize);
346
+ }
347
+ flush = checkRangesOrGetDefault(opts.flush, "options.flush", minFlush, maxFlushFlag, flush);
348
+ finishFlush = checkRangesOrGetDefault(opts.finishFlush, "options.finishFlush", minFlush, maxFlushFlag, finishFlush);
349
+ maxOutputLength = checkRangesOrGetDefault(opts.maxOutputLength, "options.maxOutputLength", 1, kMaxLength, kMaxLength);
350
+ if (opts.encoding || opts.objectMode || opts.writableObjectMode) {
351
+ opts = { ...opts };
352
+ opts.encoding = null;
353
+ opts.objectMode = false;
354
+ opts.writableObjectMode = false;
27
355
  }
28
356
  }
29
- const bytes = new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
30
- let crc = (value ^ 0xffffffff) >>> 0;
31
- for (let i = 0; i < bytes.length; i++) crc = crcTable[(crc ^ bytes[i]) & 0xff] ^ (crc >>> 8);
32
- return (crc ^ 0xffffffff) >>> 0;
357
+
358
+ Reflect.apply(Transform, this, [{ autoDestroy: true, ...opts }]);
359
+ this[kError] = null;
360
+ this.bytesWritten = 0;
361
+ this._handle = handle;
362
+ handle[ownerSymbol] = this;
363
+ handle.onerror = zlibOnError;
364
+ this._outBuffer = Buffer.allocUnsafe(chunkSize);
365
+ this._outOffset = 0;
366
+ this._chunkSize = chunkSize;
367
+ this._defaultFlushFlag = flush;
368
+ this._finishFlushFlag = finishFlush;
369
+ this._defaultFullFlushFlag = fullFlush;
370
+ this._info = opts?.info;
371
+ this._maxOutputLength = maxOutputLength;
372
+ this._rejectGarbageAfterEnd = opts?.rejectGarbageAfterEnd === true;
373
+ }
374
+ Object.setPrototypeOf(ZlibBase.prototype, Transform.prototype);
375
+ Object.setPrototypeOf(ZlibBase, Transform);
376
+
377
+ Object.defineProperty(ZlibBase.prototype, "_closed", {
378
+ __proto__: null,
379
+ configurable: true,
380
+ enumerable: true,
381
+ get() {
382
+ return !this._handle;
383
+ },
384
+ });
385
+
386
+ Object.defineProperty(ZlibBase.prototype, "bytesRead", {
387
+ __proto__: null,
388
+ configurable: true,
389
+ enumerable: true,
390
+ get: deprecate(function () {
391
+ return this.bytesWritten;
392
+ }, "zlib.bytesRead is deprecated and will change its meaning in the future. Use zlib.bytesWritten instead.", "DEP0108"),
393
+ set: deprecate(function (value) {
394
+ this.bytesWritten = value;
395
+ }, "Setting zlib.bytesRead is deprecated. This feature will be removed in the future.", "DEP0108"),
396
+ });
397
+
398
+ ZlibBase.prototype.reset = function () {
399
+ assert(this._handle, "zlib binding closed");
400
+ return this._handle.reset();
401
+ };
402
+
403
+ /* Transform calls it when the last chunk has been written */
404
+ ZlibBase.prototype._flush = function (callback) {
405
+ this._transform(emptyBuffer(), "", callback);
406
+ };
407
+
408
+ /* Transform's behavior, forced */
409
+ ZlibBase.prototype._final = function (callback) {
410
+ callback();
411
+ };
412
+
413
+ /* which of two pending flushes is the stronger: Z_NO_FLUSH < Z_BLOCK < Z_PARTIAL_FLUSH <
414
+ * Z_SYNC_FLUSH < Z_FULL_FLUSH < Z_FINISH */
415
+ const flushiness = [];
416
+ const kFlushFlagList = [Z_NO_FLUSH, Z_BLOCK, Z_PARTIAL_FLUSH, Z_SYNC_FLUSH, Z_FULL_FLUSH, Z_FINISH];
417
+ for (let i = 0; i < kFlushFlagList.length; i++) flushiness[kFlushFlagList[i]] = i;
418
+
419
+ function maxFlush(a, b) {
420
+ return flushiness[a] > flushiness[b] ? a : b;
421
+ }
422
+
423
+ /* empty buffers .flush() writes, to put a flush into the sequence of writes */
424
+ const kFlushBuffers = [];
425
+ {
426
+ const dummyArrayBuffer = new ArrayBuffer();
427
+ for (const flushFlag of kFlushFlagList) {
428
+ kFlushBuffers[flushFlag] = Buffer.from(dummyArrayBuffer);
429
+ kFlushBuffers[flushFlag][kFlushFlag] = flushFlag;
430
+ }
33
431
  }
34
432
 
35
- const unsupported = (name) =>
36
- function () {
37
- throw notSupported("zlib." + name);
433
+ ZlibBase.prototype.flush = function (kind, callback) {
434
+ if (typeof kind === "function" || (kind === undefined && !callback)) {
435
+ callback = kind;
436
+ kind = this._defaultFullFlushFlag;
437
+ }
438
+ if (this.writableFinished) {
439
+ if (callback) process.nextTick(callback);
440
+ } else if (this.writableEnded) {
441
+ if (callback) this.once("end", callback);
442
+ } else {
443
+ this.write(kFlushBuffers[kind], "", callback);
444
+ }
445
+ };
446
+
447
+ ZlibBase.prototype.close = function (callback) {
448
+ if (callback) finished(this, callback);
449
+ this.destroy();
450
+ };
451
+
452
+ ZlibBase.prototype._destroy = function (err, callback) {
453
+ _close(this);
454
+ callback(err);
455
+ };
456
+
457
+ ZlibBase.prototype._transform = function (chunk, encoding, cb) {
458
+ let flushFlag = this._defaultFlushFlag;
459
+ /* a zero-length chunk carries a flush from the public API */
460
+ if (typeof chunk[kFlushFlag] === "number") flushFlag = chunk[kFlushFlag];
461
+ /* the last chunk gets _finishFlushFlag too */
462
+ if (this.writableEnded && this.writableLength === chunk.byteLength) flushFlag = maxFlush(flushFlag, this._finishFlushFlag);
463
+ processChunk(this, chunk, flushFlag, cb);
464
+ };
465
+
466
+ /* kept for compatibility */
467
+ ZlibBase.prototype._processChunk = function (chunk, flushFlag, cb) {
468
+ if (typeof cb === "function") processChunk(this, chunk, flushFlag, cb);
469
+ else return processChunkSync(this, chunk, flushFlag);
470
+ };
471
+
472
+ function processChunkSync(self, chunk, flushFlag) {
473
+ let availInBefore = chunk.byteLength;
474
+ let availOutBefore = self._chunkSize - self._outOffset;
475
+ let inOff = 0;
476
+ let availOutAfter;
477
+ let availInAfter;
478
+
479
+ const buffers = [];
480
+ let nread = 0;
481
+ let inputRead = 0;
482
+ const state = self._writeState;
483
+ const handle = self._handle;
484
+ let buffer = self._outBuffer;
485
+ let offset = self._outOffset;
486
+ const chunkSize = self._chunkSize;
487
+
488
+ let error;
489
+ self.on("error", function onError(er) {
490
+ error = er;
491
+ });
492
+
493
+ while (true) {
494
+ handle.writeSync(flushFlag, chunk, inOff, availInBefore, buffer, offset, availOutBefore);
495
+ if (error) throw error;
496
+ else if (self[kError]) throw self[kError];
497
+
498
+ availOutAfter = state[0];
499
+ availInAfter = state[1];
500
+
501
+ const inDelta = availInBefore - availInAfter;
502
+ inputRead += inDelta;
503
+
504
+ const have = availOutBefore - availOutAfter;
505
+ if (have > 0) {
506
+ const out = buffer.slice(offset, offset + have);
507
+ offset += have;
508
+ buffers.push(out);
509
+ nread += out.byteLength;
510
+ if (nread > self._maxOutputLength) {
511
+ _close(self);
512
+ throw bufferTooLarge(self._maxOutputLength);
513
+ }
514
+ } else {
515
+ assert(have === 0, "have should not go down");
516
+ }
517
+
518
+ /* the output buffer is full, or all the input was used: a new one */
519
+ if (availOutAfter === 0 || offset >= chunkSize) {
520
+ availOutBefore = chunkSize;
521
+ offset = 0;
522
+ buffer = Buffer.allocUnsafe(chunkSize);
523
+ }
524
+
525
+ if (availOutAfter === 0) {
526
+ /* not done: again, from where the input stopped */
527
+ inOff += inDelta;
528
+ availInBefore = availInAfter;
529
+ } else {
530
+ break;
531
+ }
532
+ }
533
+
534
+ self.bytesWritten = inputRead;
535
+ _close(self);
536
+
537
+ if (nread === 0) return emptyBuffer();
538
+ return buffers.length === 1 ? buffers[0] : Buffer.concat(buffers, nread);
539
+ }
540
+
541
+ function processChunk(self, chunk, flushFlag, cb) {
542
+ const handle = self._handle;
543
+ if (!handle) return process.nextTick(cb);
544
+
545
+ handle.buffer = chunk;
546
+ handle.cb = cb;
547
+ handle.availOutBefore = self._chunkSize - self._outOffset;
548
+ handle.availInBefore = chunk.byteLength;
549
+ handle.inOff = 0;
550
+ handle.flushFlag = flushFlag;
551
+
552
+ handle.write(flushFlag, chunk, 0, handle.availInBefore, self._outBuffer, self._outOffset, handle.availOutBefore);
553
+ }
554
+
555
+ /* `this` is the handle: its values are nulled once they aren't needed, as it can outlive them */
556
+ function processCallback() {
557
+ const self = this[ownerSymbol];
558
+ const state = self._writeState;
559
+
560
+ if (self.destroyed) {
561
+ this.buffer = null;
562
+ this.cb();
563
+ return;
564
+ }
565
+
566
+ const availOutAfter = state[0];
567
+ const availInAfter = state[1];
568
+
569
+ const inDelta = this.availInBefore - availInAfter;
570
+ self.bytesWritten += inDelta;
571
+
572
+ const have = this.availOutBefore - availOutAfter;
573
+ let streamBufferIsFull = false;
574
+ if (have > 0) {
575
+ const out = self._outBuffer.slice(self._outOffset, self._outOffset + have);
576
+ self._outOffset += have;
577
+ streamBufferIsFull = !self.push(out);
578
+ } else {
579
+ assert(have === 0, "have should not go down");
580
+ }
581
+
582
+ if (self.destroyed) {
583
+ this.cb();
584
+ return;
585
+ }
586
+
587
+ /* the output buffer is full, or all the input was used: a new one */
588
+ if (availOutAfter === 0 || self._outOffset >= self._chunkSize) {
589
+ this.availOutBefore = self._chunkSize;
590
+ self._outOffset = 0;
591
+ self._outBuffer = Buffer.allocUnsafe(self._chunkSize);
592
+ }
593
+
594
+ if (availOutAfter === 0) {
595
+ /* not done: again, from where the input stopped */
596
+ this.inOff += inDelta;
597
+ this.availInBefore = availInAfter;
598
+ if (!streamBufferIsFull) {
599
+ this.write(this.flushFlag, this.buffer, this.inOff, this.availInBefore, self._outBuffer, self._outOffset, self._chunkSize);
600
+ } else {
601
+ const oldRead = self._read;
602
+ self._read = (n) => {
603
+ self._read = oldRead;
604
+ this.write(this.flushFlag, this.buffer, this.inOff, this.availInBefore, self._outBuffer, self._outOffset, self._chunkSize);
605
+ self._read(n);
606
+ };
607
+ }
608
+ return;
609
+ }
610
+
611
+ if (availInAfter > 0) {
612
+ /* input left with room for output: the compressed stream ended early (everything but Gunzip
613
+ * and Unzip stops at its end) */
614
+ if (self._rejectGarbageAfterEnd) {
615
+ const err = codeError(TypeError, "ERR_TRAILING_JUNK_AFTER_STREAM_END", "Trailing junk found after the end of the compressed stream");
616
+ self.destroy(err);
617
+ this.cb(err);
618
+ return;
619
+ }
620
+ self.push(null);
621
+ }
622
+
623
+ /* done with the chunk */
624
+ this.buffer = null;
625
+ this.cb();
626
+ }
627
+
628
+ function _close(engine) {
629
+ /* close() may come after an error, which nulls _handle */
630
+ engine._handle?.close();
631
+ engine._handle = null;
632
+ }
633
+
634
+ const zlibDefaultOpts = { flush: Z_NO_FLUSH, finishFlush: Z_FINISH, fullFlush: Z_FULL_FLUSH };
635
+
636
+ /* the base of the streams zlib itself runs, with its parameters */
637
+ function Zlib(opts, mode) {
638
+ let windowBits = Z_DEFAULT_WINDOWBITS;
639
+ let level = Z_DEFAULT_COMPRESSION;
640
+ let memLevel = Z_DEFAULT_MEMLEVEL;
641
+ let strategy = Z_DEFAULT_STRATEGY;
642
+ let dictionary;
643
+
644
+ if (opts) {
645
+ /* windowBits 0 is invalid to compress; to decompress, it's the window size in the stream's header */
646
+ if ((opts.windowBits == null || opts.windowBits === 0) && (mode === INFLATE || mode === GUNZIP || mode === UNZIP)) {
647
+ windowBits = 0;
648
+ } else {
649
+ /* { windowBits: 8 } is valid for deflate, not gzip */
650
+ const min = Z_MIN_WINDOWBITS + (mode === GZIP ? 1 : 0);
651
+ windowBits = checkRangesOrGetDefault(opts.windowBits, "options.windowBits", min, Z_MAX_WINDOWBITS, Z_DEFAULT_WINDOWBITS);
652
+ }
653
+ level = checkRangesOrGetDefault(opts.level, "options.level", Z_MIN_LEVEL, Z_MAX_LEVEL, Z_DEFAULT_COMPRESSION);
654
+ memLevel = checkRangesOrGetDefault(opts.memLevel, "options.memLevel", Z_MIN_MEMLEVEL, Z_MAX_MEMLEVEL, Z_DEFAULT_MEMLEVEL);
655
+ strategy = checkRangesOrGetDefault(opts.strategy, "options.strategy", Z_DEFAULT_STRATEGY, Z_FIXED, Z_DEFAULT_STRATEGY);
656
+ dictionary = opts.dictionary;
657
+ if (dictionary !== undefined && !isArrayBufferView(dictionary)) {
658
+ if (isAnyArrayBuffer(dictionary)) dictionary = Buffer.from(dictionary);
659
+ else throw invalidArgType("options.dictionary", "an instance of Buffer, TypedArray, DataView, or ArrayBuffer", dictionary);
660
+ }
661
+ }
662
+
663
+ const handle = new ZlibHandle(mode);
664
+ this._writeState = new Uint32Array(2);
665
+ handle.init(windowBits, level, memLevel, strategy, this._writeState, processCallback, dictionary);
666
+
667
+ Reflect.apply(ZlibBase, this, [opts, mode, handle, zlibDefaultOpts]);
668
+
669
+ this._level = level;
670
+ this._strategy = strategy;
671
+ this._mode = mode;
672
+ }
673
+ Object.setPrototypeOf(Zlib.prototype, ZlibBase.prototype);
674
+ Object.setPrototypeOf(Zlib, ZlibBase);
675
+
676
+ /* params() changes them after a full flush, not while a write is in progress */
677
+ function paramsAfterFlushCallback(level, strategy, callback) {
678
+ assert(this._handle, "zlib binding closed");
679
+ this._handle.params(level, strategy);
680
+ if (!this.destroyed) {
681
+ this._level = level;
682
+ this._strategy = strategy;
683
+ if (callback) callback();
684
+ }
685
+ }
686
+
687
+ Zlib.prototype.params = function params(level, strategy, callback) {
688
+ checkRangesOrGetDefault(level, "level", Z_MIN_LEVEL, Z_MAX_LEVEL);
689
+ checkRangesOrGetDefault(strategy, "strategy", Z_DEFAULT_STRATEGY, Z_FIXED);
690
+ if (this._level !== level || this._strategy !== strategy) {
691
+ this.flush(Z_SYNC_FLUSH, paramsAfterFlushCallback.bind(this, level, strategy, callback));
692
+ } else {
693
+ process.nextTick(callback);
694
+ }
695
+ };
696
+
697
+ export function Deflate(opts) {
698
+ if (!(this instanceof Deflate)) return new Deflate(opts);
699
+ Reflect.apply(Zlib, this, [opts, DEFLATE]);
700
+ }
701
+ Object.setPrototypeOf(Deflate.prototype, Zlib.prototype);
702
+ Object.setPrototypeOf(Deflate, Zlib);
703
+
704
+ export function Inflate(opts) {
705
+ if (!(this instanceof Inflate)) return new Inflate(opts);
706
+ Reflect.apply(Zlib, this, [opts, INFLATE]);
707
+ }
708
+ Object.setPrototypeOf(Inflate.prototype, Zlib.prototype);
709
+ Object.setPrototypeOf(Inflate, Zlib);
710
+
711
+ export function Gzip(opts) {
712
+ if (!(this instanceof Gzip)) return new Gzip(opts);
713
+ Reflect.apply(Zlib, this, [opts, GZIP]);
714
+ }
715
+ Object.setPrototypeOf(Gzip.prototype, Zlib.prototype);
716
+ Object.setPrototypeOf(Gzip, Zlib);
717
+
718
+ export function Gunzip(opts) {
719
+ if (!(this instanceof Gunzip)) return new Gunzip(opts);
720
+ Reflect.apply(Zlib, this, [opts, GUNZIP]);
721
+ }
722
+ Object.setPrototypeOf(Gunzip.prototype, Zlib.prototype);
723
+ Object.setPrototypeOf(Gunzip, Zlib);
724
+
725
+ export function DeflateRaw(opts) {
726
+ if (opts && opts.windowBits === 8) opts.windowBits = 9;
727
+ if (!(this instanceof DeflateRaw)) return new DeflateRaw(opts);
728
+ Reflect.apply(Zlib, this, [opts, DEFLATERAW]);
729
+ }
730
+ Object.setPrototypeOf(DeflateRaw.prototype, Zlib.prototype);
731
+ Object.setPrototypeOf(DeflateRaw, Zlib);
732
+
733
+ export function InflateRaw(opts) {
734
+ if (!(this instanceof InflateRaw)) return new InflateRaw(opts);
735
+ Reflect.apply(Zlib, this, [opts, INFLATERAW]);
736
+ }
737
+ Object.setPrototypeOf(InflateRaw.prototype, Zlib.prototype);
738
+ Object.setPrototypeOf(InflateRaw, Zlib);
739
+
740
+ export function Unzip(opts) {
741
+ if (!(this instanceof Unzip)) return new Unzip(opts);
742
+ Reflect.apply(Zlib, this, [opts, UNZIP]);
743
+ }
744
+ Object.setPrototypeOf(Unzip.prototype, Zlib.prototype);
745
+ Object.setPrototypeOf(Unzip, Zlib);
746
+
747
+ function createConvenienceMethod(ctor, sync) {
748
+ if (sync) {
749
+ return function syncBufferWrapper(buffer, opts) {
750
+ return zlibBufferSync(new ctor(opts), buffer);
751
+ };
752
+ }
753
+ return function asyncBufferWrapper(buffer, opts, callback) {
754
+ if (typeof opts === "function") {
755
+ callback = opts;
756
+ opts = {};
757
+ }
758
+ return zlibBuffer(new ctor(opts), buffer, callback);
38
759
  };
39
- export const Deflate = unsupported("Deflate");
40
- export const Inflate = unsupported("Inflate");
41
- export const Gzip = unsupported("Gzip");
42
- export const Gunzip = unsupported("Gunzip");
43
- export const DeflateRaw = unsupported("DeflateRaw");
44
- export const InflateRaw = unsupported("InflateRaw");
45
- export const Unzip = unsupported("Unzip");
46
- export const BrotliCompress = unsupported("BrotliCompress");
47
- export const BrotliDecompress = unsupported("BrotliDecompress");
48
- export const deflate = unsupported("deflate");
49
- export const deflateSync = unsupported("deflateSync");
50
- export const gzip = unsupported("gzip");
51
- export const gzipSync = unsupported("gzipSync");
52
- export const deflateRaw = unsupported("deflateRaw");
53
- export const deflateRawSync = unsupported("deflateRawSync");
54
- export const unzip = unsupported("unzip");
55
- export const unzipSync = unsupported("unzipSync");
56
- export const inflate = unsupported("inflate");
57
- export const inflateSync = unsupported("inflateSync");
58
- export const gunzip = unsupported("gunzip");
59
- export const gunzipSync = unsupported("gunzipSync");
60
- export const inflateRaw = unsupported("inflateRaw");
61
- export const inflateRawSync = unsupported("inflateRawSync");
62
- export const brotliCompress = unsupported("brotliCompress");
63
- export const brotliCompressSync = unsupported("brotliCompressSync");
64
- export const brotliDecompress = unsupported("brotliDecompress");
65
- export const brotliDecompressSync = unsupported("brotliDecompressSync");
66
- export const createDeflate = unsupported("createDeflate");
67
- export const createInflate = unsupported("createInflate");
68
- export const createDeflateRaw = unsupported("createDeflateRaw");
69
- export const createInflateRaw = unsupported("createInflateRaw");
70
- export const createGzip = unsupported("createGzip");
71
- export const createGunzip = unsupported("createGunzip");
72
- export const createUnzip = unsupported("createUnzip");
73
- export const createBrotliCompress = unsupported("createBrotliCompress");
74
- export const createBrotliDecompress = unsupported("createBrotliDecompress");
75
-
76
- export default {
77
- constants, codes, crc32, Deflate, Inflate, Gzip, Gunzip, DeflateRaw, InflateRaw, Unzip, BrotliCompress, BrotliDecompress, deflate,
78
- deflateSync, gzip, gzipSync, deflateRaw, deflateRawSync, unzip, unzipSync, inflate, inflateSync, gunzip, gunzipSync, inflateRaw,
79
- inflateRawSync, brotliCompress, brotliCompressSync, brotliDecompress, brotliDecompressSync, createDeflate, createInflate,
80
- createDeflateRaw, createInflateRaw, createGzip, createGunzip, createUnzip, createBrotliCompress, createBrotliDecompress,
760
+ }
761
+
762
+ const kMaxBrotliParam = Math.max(...Object.keys(constants).map((key) => (key.startsWith("BROTLI_PARAM_") ? constants[key] : 0)));
763
+ const brotliInitParamsArray = new Uint32Array(kMaxBrotliParam + 1);
764
+
765
+ const brotliDefaultOpts = { flush: BROTLI_OPERATION_PROCESS, finishFlush: BROTLI_OPERATION_FINISH, fullFlush: BROTLI_OPERATION_FLUSH };
766
+
767
+ function Brotli(opts, mode) {
768
+ assert(mode === BROTLI_DECODE || mode === BROTLI_ENCODE);
769
+ brotliInitParamsArray.fill(-1);
770
+ if (opts?.params) {
771
+ Object.keys(opts.params).forEach((origKey) => {
772
+ const key = +origKey;
773
+ if (Number.isNaN(key) || key < 0 || key > kMaxBrotliParam || (brotliInitParamsArray[key] | 0) !== -1) {
774
+ throw codeError(RangeError, "ERR_BROTLI_INVALID_PARAM", origKey + " is not a valid Brotli parameter");
775
+ }
776
+ const value = opts.params[origKey];
777
+ if (typeof value !== "number" && typeof value !== "boolean") {
778
+ throw invalidArgType("options.params[key]", "of type number", opts.params[origKey]);
779
+ }
780
+ brotliInitParamsArray[key] = value;
781
+ });
782
+ }
783
+
784
+ const handle = new BrotliHandle(mode);
785
+ this._writeState = new Uint32Array(2);
786
+ handle.init(brotliInitParamsArray, this._writeState, processCallback);
787
+
788
+ Reflect.apply(ZlibBase, this, [opts, mode, handle, brotliDefaultOpts]);
789
+ }
790
+ Object.setPrototypeOf(Brotli.prototype, Zlib.prototype);
791
+ Object.setPrototypeOf(Brotli, Zlib);
792
+
793
+ export function BrotliCompress(opts) {
794
+ if (!(this instanceof BrotliCompress)) return new BrotliCompress(opts);
795
+ Reflect.apply(Brotli, this, [opts, BROTLI_ENCODE]);
796
+ }
797
+ Object.setPrototypeOf(BrotliCompress.prototype, Brotli.prototype);
798
+ Object.setPrototypeOf(BrotliCompress, Brotli);
799
+
800
+ export function BrotliDecompress(opts) {
801
+ if (!(this instanceof BrotliDecompress)) return new BrotliDecompress(opts);
802
+ Reflect.apply(Brotli, this, [opts, BROTLI_DECODE]);
803
+ }
804
+ Object.setPrototypeOf(BrotliDecompress.prototype, Brotli.prototype);
805
+ Object.setPrototypeOf(BrotliDecompress, Brotli);
806
+
807
+ const zstdDefaultOpts = { flush: ZSTD_e_continue, finishFlush: ZSTD_e_end, fullFlush: ZSTD_e_flush };
808
+
809
+ class Zstd extends ZlibBase {
810
+ constructor(opts, mode, initParamsArray, maxParam) {
811
+ assert(mode === ZSTD_COMPRESS || mode === ZSTD_DECOMPRESS);
812
+ initParamsArray.fill(-1);
813
+ if (opts?.params) {
814
+ Object.keys(opts.params).forEach((origKey) => {
815
+ const key = +origKey;
816
+ if (Number.isNaN(key) || key < 0 || key > maxParam || (initParamsArray[key] | 0) !== -1) {
817
+ throw codeError(RangeError, "ERR_ZSTD_INVALID_PARAM", origKey + " is not a valid zstd parameter");
818
+ }
819
+ const value = opts.params[origKey];
820
+ if (typeof value !== "number" && typeof value !== "boolean") {
821
+ throw invalidArgType("options.params[key]", "of type number", opts.params[origKey]);
822
+ }
823
+ initParamsArray[key] = value;
824
+ });
825
+ }
826
+
827
+ const handle = new ZstdHandle(mode === ZSTD_COMPRESS);
828
+ const pledgedSrcSize = opts?.pledgedSrcSize ?? undefined;
829
+ const writeState = new Uint32Array(2);
830
+ handle.init(initParamsArray, pledgedSrcSize, writeState, processCallback,
831
+ opts?.dictionary && isArrayBufferView(opts.dictionary) ? opts.dictionary : undefined);
832
+
833
+ super(opts, mode, handle, zstdDefaultOpts);
834
+ this._writeState = writeState;
835
+ }
836
+ }
837
+
838
+ const kMaxZstdCParam = Math.max(...Object.keys(constants).map((key) => (key.startsWith("ZSTD_c_") ? constants[key] : 0)));
839
+ const zstdInitCParamsArray = new Uint32Array(kMaxZstdCParam + 1);
840
+
841
+ export class ZstdCompress extends Zstd {
842
+ constructor(opts) {
843
+ super(opts, ZSTD_COMPRESS, zstdInitCParamsArray, kMaxZstdCParam);
844
+ }
845
+ }
846
+
847
+ const kMaxZstdDParam = Math.max(...Object.keys(constants).map((key) => (key.startsWith("ZSTD_d_") ? constants[key] : 0)));
848
+ const zstdInitDParamsArray = new Uint32Array(kMaxZstdDParam + 1);
849
+
850
+ export class ZstdDecompress extends Zstd {
851
+ constructor(opts) {
852
+ super(opts, ZSTD_DECOMPRESS, zstdInitDParamsArray, kMaxZstdDParam);
853
+ }
854
+ }
855
+
856
+ /** zlib.crc32(data, value = 0): CRC-32 (IEEE), as zlib computes it. */
857
+ export function crc32(data, value = 0) {
858
+ if (typeof data !== "string" && !isArrayBufferView(data)) {
859
+ throw invalidArgType("data", "of type string or an instance of Buffer, TypedArray, or DataView", data);
860
+ }
861
+ if (typeof value !== "number") throw invalidArgType("value", "of type number", value);
862
+ if (!Number.isInteger(value)) throw outOfRange("value", "an integer", value);
863
+ if (value < 0 || value > 4294967295) throw outOfRange("value", ">= 0 && <= 4294967295", value);
864
+ return zlibCrc32(data, value);
865
+ }
866
+
867
+ export const deflate = createConvenienceMethod(Deflate, false);
868
+ export const deflateSync = createConvenienceMethod(Deflate, true);
869
+ export const gzip = createConvenienceMethod(Gzip, false);
870
+ export const gzipSync = createConvenienceMethod(Gzip, true);
871
+ export const deflateRaw = createConvenienceMethod(DeflateRaw, false);
872
+ export const deflateRawSync = createConvenienceMethod(DeflateRaw, true);
873
+ export const unzip = createConvenienceMethod(Unzip, false);
874
+ export const unzipSync = createConvenienceMethod(Unzip, true);
875
+ export const inflate = createConvenienceMethod(Inflate, false);
876
+ export const inflateSync = createConvenienceMethod(Inflate, true);
877
+ export const gunzip = createConvenienceMethod(Gunzip, false);
878
+ export const gunzipSync = createConvenienceMethod(Gunzip, true);
879
+ export const inflateRaw = createConvenienceMethod(InflateRaw, false);
880
+ export const inflateRawSync = createConvenienceMethod(InflateRaw, true);
881
+ export const brotliCompress = createConvenienceMethod(BrotliCompress, false);
882
+ export const brotliCompressSync = createConvenienceMethod(BrotliCompress, true);
883
+ export const brotliDecompress = createConvenienceMethod(BrotliDecompress, false);
884
+ export const brotliDecompressSync = createConvenienceMethod(BrotliDecompress, true);
885
+ export const zstdCompress = createConvenienceMethod(ZstdCompress, false);
886
+ export const zstdCompressSync = createConvenienceMethod(ZstdCompress, true);
887
+ export const zstdDecompress = createConvenienceMethod(ZstdDecompress, false);
888
+ export const zstdDecompressSync = createConvenienceMethod(ZstdDecompress, true);
889
+
890
+ export const createDeflate = (options) => new Deflate(options);
891
+ export const createInflate = (options) => new Inflate(options);
892
+ export const createDeflateRaw = (options) => new DeflateRaw(options);
893
+ export const createInflateRaw = (options) => new InflateRaw(options);
894
+ export const createGzip = (options) => new Gzip(options);
895
+ export const createGunzip = (options) => new Gunzip(options);
896
+ export const createUnzip = (options) => new Unzip(options);
897
+ export const createBrotliCompress = (options) => new BrotliCompress(options);
898
+ export const createBrotliDecompress = (options) => new BrotliDecompress(options);
899
+ export const createZstdCompress = (options) => new ZstdCompress(options);
900
+ export const createZstdDecompress = (options) => new ZstdDecompress(options);
901
+
902
+ /* module.exports as Node builds it: constants and codes read-only, and the zlib constants again,
903
+ * deprecated, as hidden properties */
904
+ const zlib = {
905
+ crc32, Deflate, Inflate, Gzip, Gunzip, DeflateRaw, InflateRaw, Unzip, BrotliCompress, BrotliDecompress, ZstdCompress,
906
+ ZstdDecompress, deflate, deflateSync, gzip, gzipSync, deflateRaw, deflateRawSync, unzip, unzipSync, inflate, inflateSync,
907
+ gunzip, gunzipSync, inflateRaw, inflateRawSync, brotliCompress, brotliCompressSync, brotliDecompress, brotliDecompressSync,
908
+ zstdCompress, zstdCompressSync, zstdDecompress, zstdDecompressSync, createDeflate, createInflate, createDeflateRaw,
909
+ createInflateRaw, createGzip, createGunzip, createUnzip, createBrotliCompress, createBrotliDecompress, createZstdCompress,
910
+ createZstdDecompress,
81
911
  };
912
+ Object.defineProperties(zlib, {
913
+ constants: { __proto__: null, configurable: false, enumerable: true, value: constants },
914
+ codes: { __proto__: null, enumerable: true, writable: false, value: codes },
915
+ });
916
+ for (const key of Object.keys(constants)) {
917
+ if (key.startsWith("BROTLI")) continue;
918
+ Object.defineProperty(zlib, key, { __proto__: null, enumerable: false, value: constants[key], writable: false });
919
+ }
920
+
921
+ export default zlib;