visaljs 0.0.0-stage → 0.0.2

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 (520) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +45 -2
  3. package/cli.js +8084 -0
  4. package/node/include/js_node.h +46 -0
  5. package/node/prelude/async_hooks.js +88 -0
  6. package/node/prelude/buffer.js +31 -0
  7. package/node/prelude/crypto.js +114 -0
  8. package/node/prelude/events.js +227 -0
  9. package/node/prelude/fs.js +79 -0
  10. package/node/prelude/http.js +536 -0
  11. package/node/prelude/http2.js +30 -0
  12. package/node/prelude/internal/crypto/asym.js +333 -0
  13. package/node/prelude/internal/crypto/cipher.js +205 -0
  14. package/node/prelude/internal/crypto/hash.js +137 -0
  15. package/node/prelude/internal/crypto/kdf.js +182 -0
  16. package/node/prelude/internal/crypto/keys.js +603 -0
  17. package/node/prelude/internal/crypto/random.js +118 -0
  18. package/node/prelude/internal/crypto/util.js +76 -0
  19. package/node/prelude/internal/errors.js +88 -0
  20. package/node/prelude/internal/querystring.js +105 -0
  21. package/node/prelude/module.js +53 -0
  22. package/node/prelude/net.js +51 -0
  23. package/node/prelude/os.js +129 -0
  24. package/node/prelude/path.js +257 -0
  25. package/node/prelude/process.js +21 -0
  26. package/node/prelude/querystring.js +469 -0
  27. package/node/prelude/stream.js +1327 -0
  28. package/node/prelude/stream_promises.js +7 -0
  29. package/node/prelude/stream_web.js +6 -0
  30. package/node/prelude/string_decoder.js +236 -0
  31. package/node/prelude/tty.js +18 -0
  32. package/node/prelude/url.js +1156 -0
  33. package/node/prelude/util.js +64 -0
  34. package/node/prelude/zlib.js +81 -0
  35. package/node/src/host_fs.c +126 -0
  36. package/node/src/host_http.c +486 -0
  37. package/node/src/host_os.c +505 -0
  38. package/node/src/host_sys.c +78 -0
  39. package/node/third_party/libuv/LICENSE +19 -0
  40. package/node/third_party/libuv/include/uv/aix.h +32 -0
  41. package/node/third_party/libuv/include/uv/bsd.h +34 -0
  42. package/node/third_party/libuv/include/uv/darwin.h +61 -0
  43. package/node/third_party/libuv/include/uv/errno.h +483 -0
  44. package/node/third_party/libuv/include/uv/linux.h +34 -0
  45. package/node/third_party/libuv/include/uv/os390.h +33 -0
  46. package/node/third_party/libuv/include/uv/posix.h +31 -0
  47. package/node/third_party/libuv/include/uv/sunos.h +44 -0
  48. package/node/third_party/libuv/include/uv/threadpool.h +37 -0
  49. package/node/third_party/libuv/include/uv/tree.h +521 -0
  50. package/node/third_party/libuv/include/uv/unix.h +512 -0
  51. package/node/third_party/libuv/include/uv/version.h +43 -0
  52. package/node/third_party/libuv/include/uv/win.h +698 -0
  53. package/node/third_party/libuv/include/uv.h +1990 -0
  54. package/node/third_party/libuv/src/fs-poll.c +290 -0
  55. package/node/third_party/libuv/src/heap-inl.h +245 -0
  56. package/node/third_party/libuv/src/idna.c +560 -0
  57. package/node/third_party/libuv/src/idna.h +31 -0
  58. package/node/third_party/libuv/src/inet.c +298 -0
  59. package/node/third_party/libuv/src/queue.h +90 -0
  60. package/node/third_party/libuv/src/random.c +123 -0
  61. package/node/third_party/libuv/src/strscpy.c +38 -0
  62. package/node/third_party/libuv/src/strscpy.h +39 -0
  63. package/node/third_party/libuv/src/strtok.c +52 -0
  64. package/node/third_party/libuv/src/strtok.h +27 -0
  65. package/node/third_party/libuv/src/thread-common.c +175 -0
  66. package/node/third_party/libuv/src/threadpool.c +419 -0
  67. package/node/third_party/libuv/src/timer.c +200 -0
  68. package/node/third_party/libuv/src/unix/async.c +418 -0
  69. package/node/third_party/libuv/src/unix/bsd-ifaddrs.c +164 -0
  70. package/node/third_party/libuv/src/unix/core.c +2104 -0
  71. package/node/third_party/libuv/src/unix/darwin-proctitle.c +176 -0
  72. package/node/third_party/libuv/src/unix/darwin-stub.h +97 -0
  73. package/node/third_party/libuv/src/unix/darwin-syscalls.h +17 -0
  74. package/node/third_party/libuv/src/unix/darwin.c +237 -0
  75. package/node/third_party/libuv/src/unix/dl.c +80 -0
  76. package/node/third_party/libuv/src/unix/fs.c +2303 -0
  77. package/node/third_party/libuv/src/unix/fsevents.c +906 -0
  78. package/node/third_party/libuv/src/unix/getaddrinfo.c +252 -0
  79. package/node/third_party/libuv/src/unix/getnameinfo.c +121 -0
  80. package/node/third_party/libuv/src/unix/internal.h +530 -0
  81. package/node/third_party/libuv/src/unix/kqueue.c +667 -0
  82. package/node/third_party/libuv/src/unix/linux.c +2761 -0
  83. package/node/third_party/libuv/src/unix/loop-watcher.c +68 -0
  84. package/node/third_party/libuv/src/unix/loop.c +240 -0
  85. package/node/third_party/libuv/src/unix/pipe.c +555 -0
  86. package/node/third_party/libuv/src/unix/poll.c +159 -0
  87. package/node/third_party/libuv/src/unix/process.c +1123 -0
  88. package/node/third_party/libuv/src/unix/procfs-exepath.c +45 -0
  89. package/node/third_party/libuv/src/unix/proctitle.c +157 -0
  90. package/node/third_party/libuv/src/unix/random-devurandom.c +93 -0
  91. package/node/third_party/libuv/src/unix/random-getentropy.c +57 -0
  92. package/node/third_party/libuv/src/unix/random-getrandom.c +86 -0
  93. package/node/third_party/libuv/src/unix/random-sysctl-linux.c +99 -0
  94. package/node/third_party/libuv/src/unix/signal.c +581 -0
  95. package/node/third_party/libuv/src/unix/stream.c +1567 -0
  96. package/node/third_party/libuv/src/unix/tcp.c +673 -0
  97. package/node/third_party/libuv/src/unix/thread.c +975 -0
  98. package/node/third_party/libuv/src/unix/tty.c +510 -0
  99. package/node/third_party/libuv/src/unix/udp.c +1434 -0
  100. package/node/third_party/libuv/src/uv-common.c +1051 -0
  101. package/node/third_party/libuv/src/uv-common.h +474 -0
  102. package/node/third_party/libuv/src/uv-data-getter-setters.c +119 -0
  103. package/node/third_party/libuv/src/version.c +45 -0
  104. package/node/third_party/llhttp/LICENSE +22 -0
  105. package/node/third_party/llhttp/api.c +509 -0
  106. package/node/third_party/llhttp/http.c +170 -0
  107. package/node/third_party/llhttp/llhttp.c +10099 -0
  108. package/node/third_party/llhttp/llhttp.h +907 -0
  109. package/package.json +25 -4
  110. package/runtime/include/js_atoms.gen.h +68 -0
  111. package/runtime/include/js_atoms.h +54 -0
  112. package/runtime/include/js_bigint.h +93 -0
  113. package/runtime/include/js_buffer.h +79 -0
  114. package/runtime/include/js_builtins.h +168 -0
  115. package/runtime/include/js_console.h +58 -0
  116. package/runtime/include/js_convert.h +22 -0
  117. package/runtime/include/js_core.def +188 -0
  118. package/runtime/include/js_crypto.h +58 -0
  119. package/runtime/include/js_error.h +37 -0
  120. package/runtime/include/js_exception.h +65 -0
  121. package/runtime/include/js_function.h +167 -0
  122. package/runtime/include/js_gc.h +195 -0
  123. package/runtime/include/js_generator.h +96 -0
  124. package/runtime/include/js_host.h +19 -0
  125. package/runtime/include/js_jobs.h +84 -0
  126. package/runtime/include/js_module.h +16 -0
  127. package/runtime/include/js_object.h +384 -0
  128. package/runtime/include/js_ops.h +111 -0
  129. package/runtime/include/js_promise.h +45 -0
  130. package/runtime/include/js_regexp.h +25 -0
  131. package/runtime/include/js_runtime.h +30 -0
  132. package/runtime/include/js_symbol.h +62 -0
  133. package/runtime/include/js_web.h +110 -0
  134. package/runtime/include/jscell.h +48 -0
  135. package/runtime/include/jscontext.h +240 -0
  136. package/runtime/include/jsnum.h +42 -0
  137. package/runtime/include/jsstring.h +161 -0
  138. package/runtime/include/jsvalue.h +142 -0
  139. package/runtime/src/arguments.c +115 -0
  140. package/runtime/src/array.c +1145 -0
  141. package/runtime/src/arraybuffer.c +608 -0
  142. package/runtime/src/async_iter.c +479 -0
  143. package/runtime/src/atoms.c +157 -0
  144. package/runtime/src/base64.c +107 -0
  145. package/runtime/src/bigint.c +1189 -0
  146. package/runtime/src/blob.c +371 -0
  147. package/runtime/src/buffer.c +1357 -0
  148. package/runtime/src/builtin_table.c +100 -0
  149. package/runtime/src/builtins.c +987 -0
  150. package/runtime/src/builtins_util.h +53 -0
  151. package/runtime/src/collections.c +912 -0
  152. package/runtime/src/components.c +28 -0
  153. package/runtime/src/console.c +637 -0
  154. package/runtime/src/convert.c +82 -0
  155. package/runtime/src/core_all.c +21 -0
  156. package/runtime/src/crypto.c +116 -0
  157. package/runtime/src/crypto_asym.c +644 -0
  158. package/runtime/src/crypto_cipher.c +671 -0
  159. package/runtime/src/crypto_hash.c +260 -0
  160. package/runtime/src/crypto_host.c +414 -0
  161. package/runtime/src/crypto_internal.h +304 -0
  162. package/runtime/src/crypto_kdf.c +143 -0
  163. package/runtime/src/crypto_key.c +171 -0
  164. package/runtime/src/crypto_pkey.c +794 -0
  165. package/runtime/src/crypto_subtle.c +1675 -0
  166. package/runtime/src/date.c +940 -0
  167. package/runtime/src/domexception.c +169 -0
  168. package/runtime/src/elements.c +312 -0
  169. package/runtime/src/elements.h +45 -0
  170. package/runtime/src/encoding.c +485 -0
  171. package/runtime/src/error.c +297 -0
  172. package/runtime/src/events.c +793 -0
  173. package/runtime/src/exception.c +56 -0
  174. package/runtime/src/fetch.c +772 -0
  175. package/runtime/src/function.c +530 -0
  176. package/runtime/src/gc.c +803 -0
  177. package/runtime/src/generator.c +218 -0
  178. package/runtime/src/global.c +119 -0
  179. package/runtime/src/headers.c +557 -0
  180. package/runtime/src/inspect.c +1792 -0
  181. package/runtime/src/internal.h +80 -0
  182. package/runtime/src/iterate.c +94 -0
  183. package/runtime/src/iterator.c +409 -0
  184. package/runtime/src/jobs.c +337 -0
  185. package/runtime/src/jsnum.c +353 -0
  186. package/runtime/src/json.c +1028 -0
  187. package/runtime/src/math.c +243 -0
  188. package/runtime/src/module.c +336 -0
  189. package/runtime/src/number.c +176 -0
  190. package/runtime/src/object.c +1265 -0
  191. package/runtime/src/ops.c +322 -0
  192. package/runtime/src/os.c +196 -0
  193. package/runtime/src/os.h +29 -0
  194. package/runtime/src/process.c +432 -0
  195. package/runtime/src/promise.c +721 -0
  196. package/runtime/src/proxy.c +570 -0
  197. package/runtime/src/reflect.c +194 -0
  198. package/runtime/src/regexp.c +1141 -0
  199. package/runtime/src/regexp_anchor.h +34 -0
  200. package/runtime/src/regexp_message.h +32 -0
  201. package/runtime/src/shape.c +294 -0
  202. package/runtime/src/shape.h +46 -0
  203. package/runtime/src/streams.c +1046 -0
  204. package/runtime/src/streams.h +47 -0
  205. package/runtime/src/string.c +364 -0
  206. package/runtime/src/string_builtins.c +837 -0
  207. package/runtime/src/symbol.c +143 -0
  208. package/runtime/src/test_host.c +59 -0
  209. package/runtime/src/typedarray.c +1330 -0
  210. package/runtime/src/tznames.gen.h +712 -0
  211. package/runtime/src/uri.c +169 -0
  212. package/runtime/src/url.c +2116 -0
  213. package/runtime/src/weak.c +486 -0
  214. package/runtime/src/web.c +214 -0
  215. package/runtime/src/wrapper.c +59 -0
  216. package/runtime/src/writable.c +1486 -0
  217. package/runtime/third_party/ada-idna/LICENSE-MIT +18 -0
  218. package/runtime/third_party/ada-idna/README.md +27 -0
  219. package/runtime/third_party/ada-idna/convert.mjs +83 -0
  220. package/runtime/third_party/ada-idna/idna.c +416 -0
  221. package/runtime/third_party/ada-idna/idna.h +15 -0
  222. package/runtime/third_party/ada-idna/idna_tables.h +2657 -0
  223. package/runtime/third_party/bearssl/LICENSE.txt +21 -0
  224. package/runtime/third_party/bearssl/README.txt +136 -0
  225. package/runtime/third_party/bearssl/VERSION +1 -0
  226. package/runtime/third_party/bearssl/inc/bearssl.h +183 -0
  227. package/runtime/third_party/bearssl/inc/bearssl_aead.h +1059 -0
  228. package/runtime/third_party/bearssl/inc/bearssl_block.h +2618 -0
  229. package/runtime/third_party/bearssl/inc/bearssl_ec.h +967 -0
  230. package/runtime/third_party/bearssl/inc/bearssl_hash.h +1346 -0
  231. package/runtime/third_party/bearssl/inc/bearssl_hmac.h +241 -0
  232. package/runtime/third_party/bearssl/inc/bearssl_kdf.h +284 -0
  233. package/runtime/third_party/bearssl/inc/bearssl_pem.h +294 -0
  234. package/runtime/third_party/bearssl/inc/bearssl_prf.h +150 -0
  235. package/runtime/third_party/bearssl/inc/bearssl_rand.h +397 -0
  236. package/runtime/third_party/bearssl/inc/bearssl_rsa.h +1655 -0
  237. package/runtime/third_party/bearssl/inc/bearssl_ssl.h +4296 -0
  238. package/runtime/third_party/bearssl/inc/bearssl_x509.h +1474 -0
  239. package/runtime/third_party/bearssl/src/aead/ccm.c +346 -0
  240. package/runtime/third_party/bearssl/src/aead/eax.c +525 -0
  241. package/runtime/third_party/bearssl/src/aead/gcm.c +318 -0
  242. package/runtime/third_party/bearssl/src/codec/ccopy.c +44 -0
  243. package/runtime/third_party/bearssl/src/codec/dec16be.c +38 -0
  244. package/runtime/third_party/bearssl/src/codec/dec16le.c +38 -0
  245. package/runtime/third_party/bearssl/src/codec/dec32be.c +38 -0
  246. package/runtime/third_party/bearssl/src/codec/dec32le.c +38 -0
  247. package/runtime/third_party/bearssl/src/codec/dec64be.c +38 -0
  248. package/runtime/third_party/bearssl/src/codec/dec64le.c +38 -0
  249. package/runtime/third_party/bearssl/src/codec/enc16be.c +38 -0
  250. package/runtime/third_party/bearssl/src/codec/enc16le.c +38 -0
  251. package/runtime/third_party/bearssl/src/codec/enc32be.c +38 -0
  252. package/runtime/third_party/bearssl/src/codec/enc32le.c +38 -0
  253. package/runtime/third_party/bearssl/src/codec/enc64be.c +38 -0
  254. package/runtime/third_party/bearssl/src/codec/enc64le.c +38 -0
  255. package/runtime/third_party/bearssl/src/codec/pemdec.c +526 -0
  256. package/runtime/third_party/bearssl/src/codec/pemdec.t0 +314 -0
  257. package/runtime/third_party/bearssl/src/codec/pemenc.c +173 -0
  258. package/runtime/third_party/bearssl/src/config.h +247 -0
  259. package/runtime/third_party/bearssl/src/ec/ec_all_m15.c +121 -0
  260. package/runtime/third_party/bearssl/src/ec/ec_all_m31.c +171 -0
  261. package/runtime/third_party/bearssl/src/ec/ec_c25519_i15.c +398 -0
  262. package/runtime/third_party/bearssl/src/ec/ec_c25519_i31.c +390 -0
  263. package/runtime/third_party/bearssl/src/ec/ec_c25519_m15.c +1478 -0
  264. package/runtime/third_party/bearssl/src/ec/ec_c25519_m31.c +800 -0
  265. package/runtime/third_party/bearssl/src/ec/ec_c25519_m62.c +605 -0
  266. package/runtime/third_party/bearssl/src/ec/ec_c25519_m64.c +831 -0
  267. package/runtime/third_party/bearssl/src/ec/ec_curve25519.c +46 -0
  268. package/runtime/third_party/bearssl/src/ec/ec_default.c +36 -0
  269. package/runtime/third_party/bearssl/src/ec/ec_keygen.c +86 -0
  270. package/runtime/third_party/bearssl/src/ec/ec_p256_m15.c +2124 -0
  271. package/runtime/third_party/bearssl/src/ec/ec_p256_m31.c +1469 -0
  272. package/runtime/third_party/bearssl/src/ec/ec_p256_m62.c +1765 -0
  273. package/runtime/third_party/bearssl/src/ec/ec_p256_m64.c +1781 -0
  274. package/runtime/third_party/bearssl/src/ec/ec_prime_i15.c +824 -0
  275. package/runtime/third_party/bearssl/src/ec/ec_prime_i31.c +826 -0
  276. package/runtime/third_party/bearssl/src/ec/ec_pubkey.c +85 -0
  277. package/runtime/third_party/bearssl/src/ec/ec_secp256r1.c +51 -0
  278. package/runtime/third_party/bearssl/src/ec/ec_secp384r1.c +57 -0
  279. package/runtime/third_party/bearssl/src/ec/ec_secp521r1.c +64 -0
  280. package/runtime/third_party/bearssl/src/ec/ecdsa_atr.c +134 -0
  281. package/runtime/third_party/bearssl/src/ec/ecdsa_default_sign_asn1.c +36 -0
  282. package/runtime/third_party/bearssl/src/ec/ecdsa_default_sign_raw.c +36 -0
  283. package/runtime/third_party/bearssl/src/ec/ecdsa_default_vrfy_asn1.c +36 -0
  284. package/runtime/third_party/bearssl/src/ec/ecdsa_default_vrfy_raw.c +36 -0
  285. package/runtime/third_party/bearssl/src/ec/ecdsa_i15_bits.c +47 -0
  286. package/runtime/third_party/bearssl/src/ec/ecdsa_i15_sign_asn1.c +45 -0
  287. package/runtime/third_party/bearssl/src/ec/ecdsa_i15_sign_raw.c +174 -0
  288. package/runtime/third_party/bearssl/src/ec/ecdsa_i15_vrfy_asn1.c +48 -0
  289. package/runtime/third_party/bearssl/src/ec/ecdsa_i15_vrfy_raw.c +166 -0
  290. package/runtime/third_party/bearssl/src/ec/ecdsa_i31_bits.c +47 -0
  291. package/runtime/third_party/bearssl/src/ec/ecdsa_i31_sign_asn1.c +45 -0
  292. package/runtime/third_party/bearssl/src/ec/ecdsa_i31_sign_raw.c +173 -0
  293. package/runtime/third_party/bearssl/src/ec/ecdsa_i31_vrfy_asn1.c +48 -0
  294. package/runtime/third_party/bearssl/src/ec/ecdsa_i31_vrfy_raw.c +165 -0
  295. package/runtime/third_party/bearssl/src/ec/ecdsa_rta.c +121 -0
  296. package/runtime/third_party/bearssl/src/hash/dig_oid.c +84 -0
  297. package/runtime/third_party/bearssl/src/hash/dig_size.c +50 -0
  298. package/runtime/third_party/bearssl/src/hash/ghash_ctmul.c +345 -0
  299. package/runtime/third_party/bearssl/src/hash/ghash_ctmul32.c +251 -0
  300. package/runtime/third_party/bearssl/src/hash/ghash_ctmul64.c +154 -0
  301. package/runtime/third_party/bearssl/src/hash/ghash_pclmul.c +389 -0
  302. package/runtime/third_party/bearssl/src/hash/ghash_pwr8.c +411 -0
  303. package/runtime/third_party/bearssl/src/hash/md5.c +208 -0
  304. package/runtime/third_party/bearssl/src/hash/md5sha1.c +141 -0
  305. package/runtime/third_party/bearssl/src/hash/mgf1.c +56 -0
  306. package/runtime/third_party/bearssl/src/hash/multihash.c +166 -0
  307. package/runtime/third_party/bearssl/src/hash/sha1.c +191 -0
  308. package/runtime/third_party/bearssl/src/hash/sha2big.c +285 -0
  309. package/runtime/third_party/bearssl/src/hash/sha2small.c +341 -0
  310. package/runtime/third_party/bearssl/src/inner.h +2577 -0
  311. package/runtime/third_party/bearssl/src/int/i15_add.c +46 -0
  312. package/runtime/third_party/bearssl/src/int/i15_bitlen.c +44 -0
  313. package/runtime/third_party/bearssl/src/int/i15_decmod.c +124 -0
  314. package/runtime/third_party/bearssl/src/int/i15_decode.c +56 -0
  315. package/runtime/third_party/bearssl/src/int/i15_decred.c +100 -0
  316. package/runtime/third_party/bearssl/src/int/i15_encode.c +56 -0
  317. package/runtime/third_party/bearssl/src/int/i15_fmont.c +59 -0
  318. package/runtime/third_party/bearssl/src/int/i15_iszero.c +39 -0
  319. package/runtime/third_party/bearssl/src/int/i15_moddiv.c +465 -0
  320. package/runtime/third_party/bearssl/src/int/i15_modpow.c +50 -0
  321. package/runtime/third_party/bearssl/src/int/i15_modpow2.c +160 -0
  322. package/runtime/third_party/bearssl/src/int/i15_montmul.c +184 -0
  323. package/runtime/third_party/bearssl/src/int/i15_mulacc.c +61 -0
  324. package/runtime/third_party/bearssl/src/int/i15_muladd.c +173 -0
  325. package/runtime/third_party/bearssl/src/int/i15_ninv15.c +38 -0
  326. package/runtime/third_party/bearssl/src/int/i15_reduce.c +66 -0
  327. package/runtime/third_party/bearssl/src/int/i15_rshift.c +47 -0
  328. package/runtime/third_party/bearssl/src/int/i15_sub.c +46 -0
  329. package/runtime/third_party/bearssl/src/int/i15_tmont.c +36 -0
  330. package/runtime/third_party/bearssl/src/int/i31_add.c +46 -0
  331. package/runtime/third_party/bearssl/src/int/i31_bitlen.c +44 -0
  332. package/runtime/third_party/bearssl/src/int/i31_decmod.c +124 -0
  333. package/runtime/third_party/bearssl/src/int/i31_decode.c +57 -0
  334. package/runtime/third_party/bearssl/src/int/i31_decred.c +103 -0
  335. package/runtime/third_party/bearssl/src/int/i31_encode.c +79 -0
  336. package/runtime/third_party/bearssl/src/int/i31_fmont.c +60 -0
  337. package/runtime/third_party/bearssl/src/int/i31_iszero.c +39 -0
  338. package/runtime/third_party/bearssl/src/int/i31_moddiv.c +488 -0
  339. package/runtime/third_party/bearssl/src/int/i31_modpow.c +65 -0
  340. package/runtime/third_party/bearssl/src/int/i31_modpow2.c +160 -0
  341. package/runtime/third_party/bearssl/src/int/i31_montmul.c +127 -0
  342. package/runtime/third_party/bearssl/src/int/i31_mulacc.c +74 -0
  343. package/runtime/third_party/bearssl/src/int/i31_muladd.c +157 -0
  344. package/runtime/third_party/bearssl/src/int/i31_ninv31.c +39 -0
  345. package/runtime/third_party/bearssl/src/int/i31_reduce.c +66 -0
  346. package/runtime/third_party/bearssl/src/int/i31_rshift.c +47 -0
  347. package/runtime/third_party/bearssl/src/int/i31_sub.c +46 -0
  348. package/runtime/third_party/bearssl/src/int/i31_tmont.c +36 -0
  349. package/runtime/third_party/bearssl/src/int/i32_add.c +51 -0
  350. package/runtime/third_party/bearssl/src/int/i32_bitlen.c +44 -0
  351. package/runtime/third_party/bearssl/src/int/i32_decmod.c +77 -0
  352. package/runtime/third_party/bearssl/src/int/i32_decode.c +63 -0
  353. package/runtime/third_party/bearssl/src/int/i32_decred.c +107 -0
  354. package/runtime/third_party/bearssl/src/int/i32_div32.c +56 -0
  355. package/runtime/third_party/bearssl/src/int/i32_encode.c +72 -0
  356. package/runtime/third_party/bearssl/src/int/i32_fmont.c +60 -0
  357. package/runtime/third_party/bearssl/src/int/i32_iszero.c +39 -0
  358. package/runtime/third_party/bearssl/src/int/i32_modpow.c +65 -0
  359. package/runtime/third_party/bearssl/src/int/i32_montmul.c +69 -0
  360. package/runtime/third_party/bearssl/src/int/i32_mulacc.c +56 -0
  361. package/runtime/third_party/bearssl/src/int/i32_muladd.c +138 -0
  362. package/runtime/third_party/bearssl/src/int/i32_ninv32.c +39 -0
  363. package/runtime/third_party/bearssl/src/int/i32_reduce.c +66 -0
  364. package/runtime/third_party/bearssl/src/int/i32_sub.c +51 -0
  365. package/runtime/third_party/bearssl/src/int/i32_tmont.c +36 -0
  366. package/runtime/third_party/bearssl/src/int/i62_modpow2.c +493 -0
  367. package/runtime/third_party/bearssl/src/kdf/hkdf.c +107 -0
  368. package/runtime/third_party/bearssl/src/kdf/shake.c +590 -0
  369. package/runtime/third_party/bearssl/src/mac/hmac.c +122 -0
  370. package/runtime/third_party/bearssl/src/mac/hmac_ct.c +193 -0
  371. package/runtime/third_party/bearssl/src/rand/aesctr_drbg.c +206 -0
  372. package/runtime/third_party/bearssl/src/rand/hmac_drbg.c +157 -0
  373. package/runtime/third_party/bearssl/src/rand/sysrng.c +252 -0
  374. package/runtime/third_party/bearssl/src/rsa/rsa_default_keygen.c +38 -0
  375. package/runtime/third_party/bearssl/src/rsa/rsa_default_modulus.c +36 -0
  376. package/runtime/third_party/bearssl/src/rsa/rsa_default_oaep_decrypt.c +38 -0
  377. package/runtime/third_party/bearssl/src/rsa/rsa_default_oaep_encrypt.c +38 -0
  378. package/runtime/third_party/bearssl/src/rsa/rsa_default_pkcs1_sign.c +38 -0
  379. package/runtime/third_party/bearssl/src/rsa/rsa_default_pkcs1_vrfy.c +38 -0
  380. package/runtime/third_party/bearssl/src/rsa/rsa_default_priv.c +38 -0
  381. package/runtime/third_party/bearssl/src/rsa/rsa_default_privexp.c +36 -0
  382. package/runtime/third_party/bearssl/src/rsa/rsa_default_pss_sign.c +38 -0
  383. package/runtime/third_party/bearssl/src/rsa/rsa_default_pss_vrfy.c +38 -0
  384. package/runtime/third_party/bearssl/src/rsa/rsa_default_pub.c +38 -0
  385. package/runtime/third_party/bearssl/src/rsa/rsa_default_pubexp.c +36 -0
  386. package/runtime/third_party/bearssl/src/rsa/rsa_i15_keygen.c +583 -0
  387. package/runtime/third_party/bearssl/src/rsa/rsa_i15_modulus.c +99 -0
  388. package/runtime/third_party/bearssl/src/rsa/rsa_i15_oaep_decrypt.c +41 -0
  389. package/runtime/third_party/bearssl/src/rsa/rsa_i15_oaep_encrypt.c +44 -0
  390. package/runtime/third_party/bearssl/src/rsa/rsa_i15_pkcs1_sign.c +37 -0
  391. package/runtime/third_party/bearssl/src/rsa/rsa_i15_pkcs1_vrfy.c +43 -0
  392. package/runtime/third_party/bearssl/src/rsa/rsa_i15_priv.c +209 -0
  393. package/runtime/third_party/bearssl/src/rsa/rsa_i15_privexp.c +320 -0
  394. package/runtime/third_party/bearssl/src/rsa/rsa_i15_pss_sign.c +40 -0
  395. package/runtime/third_party/bearssl/src/rsa/rsa_i15_pss_vrfy.c +44 -0
  396. package/runtime/third_party/bearssl/src/rsa/rsa_i15_pub.c +113 -0
  397. package/runtime/third_party/bearssl/src/rsa/rsa_i15_pubexp.c +152 -0
  398. package/runtime/third_party/bearssl/src/rsa/rsa_i31_keygen.c +37 -0
  399. package/runtime/third_party/bearssl/src/rsa/rsa_i31_keygen_inner.c +608 -0
  400. package/runtime/third_party/bearssl/src/rsa/rsa_i31_modulus.c +99 -0
  401. package/runtime/third_party/bearssl/src/rsa/rsa_i31_oaep_decrypt.c +41 -0
  402. package/runtime/third_party/bearssl/src/rsa/rsa_i31_oaep_encrypt.c +44 -0
  403. package/runtime/third_party/bearssl/src/rsa/rsa_i31_pkcs1_sign.c +37 -0
  404. package/runtime/third_party/bearssl/src/rsa/rsa_i31_pkcs1_vrfy.c +43 -0
  405. package/runtime/third_party/bearssl/src/rsa/rsa_i31_priv.c +203 -0
  406. package/runtime/third_party/bearssl/src/rsa/rsa_i31_privexp.c +318 -0
  407. package/runtime/third_party/bearssl/src/rsa/rsa_i31_pss_sign.c +40 -0
  408. package/runtime/third_party/bearssl/src/rsa/rsa_i31_pss_vrfy.c +44 -0
  409. package/runtime/third_party/bearssl/src/rsa/rsa_i31_pub.c +106 -0
  410. package/runtime/third_party/bearssl/src/rsa/rsa_i31_pubexp.c +152 -0
  411. package/runtime/third_party/bearssl/src/rsa/rsa_i32_oaep_decrypt.c +41 -0
  412. package/runtime/third_party/bearssl/src/rsa/rsa_i32_oaep_encrypt.c +44 -0
  413. package/runtime/third_party/bearssl/src/rsa/rsa_i32_pkcs1_sign.c +37 -0
  414. package/runtime/third_party/bearssl/src/rsa/rsa_i32_pkcs1_vrfy.c +43 -0
  415. package/runtime/third_party/bearssl/src/rsa/rsa_i32_priv.c +160 -0
  416. package/runtime/third_party/bearssl/src/rsa/rsa_i32_pss_sign.c +40 -0
  417. package/runtime/third_party/bearssl/src/rsa/rsa_i32_pss_vrfy.c +44 -0
  418. package/runtime/third_party/bearssl/src/rsa/rsa_i32_pub.c +77 -0
  419. package/runtime/third_party/bearssl/src/rsa/rsa_i62_keygen.c +57 -0
  420. package/runtime/third_party/bearssl/src/rsa/rsa_i62_oaep_decrypt.c +61 -0
  421. package/runtime/third_party/bearssl/src/rsa/rsa_i62_oaep_encrypt.c +64 -0
  422. package/runtime/third_party/bearssl/src/rsa/rsa_i62_pkcs1_sign.c +57 -0
  423. package/runtime/third_party/bearssl/src/rsa/rsa_i62_pkcs1_vrfy.c +63 -0
  424. package/runtime/third_party/bearssl/src/rsa/rsa_i62_priv.c +223 -0
  425. package/runtime/third_party/bearssl/src/rsa/rsa_i62_pss_sign.c +60 -0
  426. package/runtime/third_party/bearssl/src/rsa/rsa_i62_pss_vrfy.c +64 -0
  427. package/runtime/third_party/bearssl/src/rsa/rsa_i62_pub.c +125 -0
  428. package/runtime/third_party/bearssl/src/rsa/rsa_oaep_pad.c +112 -0
  429. package/runtime/third_party/bearssl/src/rsa/rsa_oaep_unpad.c +145 -0
  430. package/runtime/third_party/bearssl/src/rsa/rsa_pkcs1_sig_pad.c +100 -0
  431. package/runtime/third_party/bearssl/src/rsa/rsa_pkcs1_sig_unpad.c +121 -0
  432. package/runtime/third_party/bearssl/src/rsa/rsa_pss_sig_pad.c +106 -0
  433. package/runtime/third_party/bearssl/src/rsa/rsa_pss_sig_unpad.c +121 -0
  434. package/runtime/third_party/bearssl/src/rsa/rsa_ssl_decrypt.c +52 -0
  435. package/runtime/third_party/bearssl/src/settings.c +306 -0
  436. package/runtime/third_party/bearssl/src/symcipher/aes_big_cbcdec.c +69 -0
  437. package/runtime/third_party/bearssl/src/symcipher/aes_big_cbcenc.c +67 -0
  438. package/runtime/third_party/bearssl/src/symcipher/aes_big_ctr.c +84 -0
  439. package/runtime/third_party/bearssl/src/symcipher/aes_big_ctrcbc.c +142 -0
  440. package/runtime/third_party/bearssl/src/symcipher/aes_big_dec.c +254 -0
  441. package/runtime/third_party/bearssl/src/symcipher/aes_big_enc.c +157 -0
  442. package/runtime/third_party/bearssl/src/symcipher/aes_common.c +112 -0
  443. package/runtime/third_party/bearssl/src/symcipher/aes_ct.c +328 -0
  444. package/runtime/third_party/bearssl/src/symcipher/aes_ct64.c +398 -0
  445. package/runtime/third_party/bearssl/src/symcipher/aes_ct64_cbcdec.c +104 -0
  446. package/runtime/third_party/bearssl/src/symcipher/aes_ct64_cbcenc.c +81 -0
  447. package/runtime/third_party/bearssl/src/symcipher/aes_ct64_ctr.c +114 -0
  448. package/runtime/third_party/bearssl/src/symcipher/aes_ct64_ctrcbc.c +433 -0
  449. package/runtime/third_party/bearssl/src/symcipher/aes_ct64_dec.c +159 -0
  450. package/runtime/third_party/bearssl/src/symcipher/aes_ct64_enc.c +115 -0
  451. package/runtime/third_party/bearssl/src/symcipher/aes_ct_cbcdec.c +111 -0
  452. package/runtime/third_party/bearssl/src/symcipher/aes_ct_cbcenc.c +91 -0
  453. package/runtime/third_party/bearssl/src/symcipher/aes_ct_ctr.c +116 -0
  454. package/runtime/third_party/bearssl/src/symcipher/aes_ct_ctrcbc.c +422 -0
  455. package/runtime/third_party/bearssl/src/symcipher/aes_ct_dec.c +170 -0
  456. package/runtime/third_party/bearssl/src/symcipher/aes_ct_enc.c +112 -0
  457. package/runtime/third_party/bearssl/src/symcipher/aes_pwr8.c +445 -0
  458. package/runtime/third_party/bearssl/src/symcipher/aes_pwr8_cbcdec.c +670 -0
  459. package/runtime/third_party/bearssl/src/symcipher/aes_pwr8_cbcenc.c +417 -0
  460. package/runtime/third_party/bearssl/src/symcipher/aes_pwr8_ctr.c +717 -0
  461. package/runtime/third_party/bearssl/src/symcipher/aes_pwr8_ctrcbc.c +946 -0
  462. package/runtime/third_party/bearssl/src/symcipher/aes_small_cbcdec.c +69 -0
  463. package/runtime/third_party/bearssl/src/symcipher/aes_small_cbcenc.c +67 -0
  464. package/runtime/third_party/bearssl/src/symcipher/aes_small_ctr.c +84 -0
  465. package/runtime/third_party/bearssl/src/symcipher/aes_small_ctrcbc.c +142 -0
  466. package/runtime/third_party/bearssl/src/symcipher/aes_small_dec.c +176 -0
  467. package/runtime/third_party/bearssl/src/symcipher/aes_small_enc.c +129 -0
  468. package/runtime/third_party/bearssl/src/symcipher/aes_x86ni.c +240 -0
  469. package/runtime/third_party/bearssl/src/symcipher/aes_x86ni_cbcdec.c +223 -0
  470. package/runtime/third_party/bearssl/src/symcipher/aes_x86ni_cbcenc.c +122 -0
  471. package/runtime/third_party/bearssl/src/symcipher/aes_x86ni_ctr.c +211 -0
  472. package/runtime/third_party/bearssl/src/symcipher/aes_x86ni_ctrcbc.c +596 -0
  473. package/runtime/third_party/bearssl/src/symcipher/chacha20_ct.c +106 -0
  474. package/runtime/third_party/bearssl/src/symcipher/chacha20_sse2.c +237 -0
  475. package/runtime/third_party/bearssl/src/symcipher/des_ct.c +411 -0
  476. package/runtime/third_party/bearssl/src/symcipher/des_ct_cbcdec.c +87 -0
  477. package/runtime/third_party/bearssl/src/symcipher/des_ct_cbcenc.c +69 -0
  478. package/runtime/third_party/bearssl/src/symcipher/des_support.c +166 -0
  479. package/runtime/third_party/bearssl/src/symcipher/des_tab.c +310 -0
  480. package/runtime/third_party/bearssl/src/symcipher/des_tab_cbcdec.c +85 -0
  481. package/runtime/third_party/bearssl/src/symcipher/des_tab_cbcenc.c +67 -0
  482. package/runtime/third_party/bearssl/src/symcipher/poly1305_ctmul.c +260 -0
  483. package/runtime/third_party/bearssl/src/symcipher/poly1305_ctmul32.c +297 -0
  484. package/runtime/third_party/bearssl/src/symcipher/poly1305_ctmulq.c +475 -0
  485. package/runtime/third_party/bearssl/src/symcipher/poly1305_i15.c +221 -0
  486. package/runtime/third_party/bearssl/src/x509/asn1.t0 +757 -0
  487. package/runtime/third_party/bearssl/src/x509/asn1enc.c +93 -0
  488. package/runtime/third_party/bearssl/src/x509/encode_ec_pk8der.c +110 -0
  489. package/runtime/third_party/bearssl/src/x509/encode_ec_rawder.c +161 -0
  490. package/runtime/third_party/bearssl/src/x509/encode_rsa_pk8der.c +97 -0
  491. package/runtime/third_party/bearssl/src/x509/encode_rsa_rawder.c +96 -0
  492. package/runtime/third_party/bearssl/src/x509/skey_decoder.c +653 -0
  493. package/runtime/third_party/bearssl/src/x509/skey_decoder.t0 +376 -0
  494. package/runtime/third_party/bearssl/src/x509/x509_decoder.c +776 -0
  495. package/runtime/third_party/bearssl/src/x509/x509_decoder.t0 +324 -0
  496. package/runtime/third_party/bearssl/src/x509/x509_knownkey.c +105 -0
  497. package/runtime/third_party/bearssl/src/x509/x509_minimal.c +1722 -0
  498. package/runtime/third_party/bearssl/src/x509/x509_minimal.t0 +1526 -0
  499. package/runtime/third_party/bearssl/src/x509/x509_minimal_full.c +59 -0
  500. package/runtime/third_party/quickjs-dtoa/LICENSE +22 -0
  501. package/runtime/third_party/quickjs-dtoa/README.md +23 -0
  502. package/runtime/third_party/quickjs-dtoa/dtoa.c +1640 -0
  503. package/runtime/third_party/quickjs-dtoa/dtoa.h +83 -0
  504. package/runtime/third_party/quickjs-dtoa/dtoa_compat.h +89 -0
  505. package/runtime/third_party/quickjs-regexp/LICENSE +22 -0
  506. package/runtime/third_party/quickjs-regexp/README.md +22 -0
  507. package/runtime/third_party/quickjs-regexp/cutils.c +641 -0
  508. package/runtime/third_party/quickjs-regexp/cutils.h +457 -0
  509. package/runtime/third_party/quickjs-regexp/libregexp-opcode.h +73 -0
  510. package/runtime/third_party/quickjs-regexp/libregexp.c +3448 -0
  511. package/runtime/third_party/quickjs-regexp/libregexp.h +65 -0
  512. package/runtime/third_party/quickjs-regexp/libunicode-table.h +5206 -0
  513. package/runtime/third_party/quickjs-regexp/libunicode.c +2124 -0
  514. package/runtime/third_party/quickjs-regexp/libunicode.h +196 -0
  515. package/runtime/third_party/v8-ieee754/LICENSE +61 -0
  516. package/runtime/third_party/v8-ieee754/README.md +22 -0
  517. package/runtime/third_party/v8-ieee754/convert.py +84 -0
  518. package/runtime/third_party/v8-ieee754/ieee754.c +3030 -0
  519. package/runtime/third_party/v8-ieee754/ieee754.h +27 -0
  520. package/runtime/tools/regexp_compile.c +90 -0
@@ -0,0 +1,1327 @@
1
+ // node:stream (ADR 0012, layer 3): Readable, Writable, Duplex, Transform, PassThrough,
2
+ // pipeline and finished, with Node's semantics for the common API: buffering to a
3
+ // highWaterMark, flowing and paused modes ('data', 'readable', read()), backpressure ('drain'),
4
+ // end/finish/close ordering, destroy(err), pipe, async iteration, Readable.from, and the
5
+ // conversions to and from web streams (Readable.toWeb, Readable.fromWeb). Strings written or
6
+ // pushed become Buffers unless the stream is in object mode or has an encoding.
7
+ // Not yet: writev batching, the legacy `readable.wrap`, compose and the operators (map, filter, …).
8
+ import { EventEmitter } from "./events.js";
9
+
10
+ function codeError(Ctor, message, code) {
11
+ const e = new Ctor(message);
12
+ Object.defineProperty(e, "code", { value: code, writable: true, enumerable: true, configurable: true });
13
+ return e;
14
+ }
15
+ const prematureClose = () => codeError(Error, "Premature close", "ERR_STREAM_PREMATURE_CLOSE");
16
+
17
+ const nextTick = (fn, ...args) => process.nextTick(fn, ...args);
18
+
19
+ const isUint8 = (v) => v instanceof Uint8Array;
20
+ const chunkSize = (chunk, objectMode) => (objectMode ? 1 : chunk.length);
21
+
22
+ /* ---- Stream (the legacy base) ---------------------------------------------------------------- */
23
+
24
+ export function Stream(opts) {
25
+ EventEmitter.call(this, opts);
26
+ }
27
+ Object.setPrototypeOf(Stream.prototype, EventEmitter.prototype);
28
+ Object.setPrototypeOf(Stream, EventEmitter);
29
+
30
+ /* The legacy pipe (Node's lib/internal/streams/legacy.js): 'data' to write(), pausing on a
31
+ * full destination until 'drain'; the destination ends with the source unless { end: false }. */
32
+ Stream.prototype.pipe = function (dest, options) {
33
+ return legacyPipe(this, dest, options);
34
+ };
35
+
36
+ function legacyPipe(source, dest, options) {
37
+ function ondata(chunk) {
38
+ if (dest.writable && dest.write(chunk) === false && source.pause) source.pause();
39
+ }
40
+ source.on("data", ondata);
41
+ function ondrain() {
42
+ if (source.readable && source.resume) source.resume();
43
+ }
44
+ dest.on("drain", ondrain);
45
+
46
+ let didOnEnd = false;
47
+ function onend() {
48
+ if (didOnEnd) return;
49
+ didOnEnd = true;
50
+ dest.end();
51
+ }
52
+ function onclose() {
53
+ if (didOnEnd) return;
54
+ didOnEnd = true;
55
+ if (typeof dest.destroy === "function") dest.destroy();
56
+ }
57
+ if (!dest._isStdio && (!options || options.end !== false)) {
58
+ source.on("end", onend);
59
+ source.on("close", onclose);
60
+ }
61
+
62
+ function onerror(er) {
63
+ cleanup();
64
+ if (this.listenerCount("error") === 0) this.emit("error", er);
65
+ }
66
+ source.prependListener("error", onerror);
67
+ dest.prependListener("error", onerror);
68
+
69
+ function cleanup() {
70
+ source.removeListener("data", ondata);
71
+ dest.removeListener("drain", ondrain);
72
+ source.removeListener("end", onend);
73
+ source.removeListener("close", onclose);
74
+ source.removeListener("error", onerror);
75
+ dest.removeListener("error", onerror);
76
+ source.removeListener("end", cleanup);
77
+ source.removeListener("close", cleanup);
78
+ dest.removeListener("close", cleanup);
79
+ }
80
+ source.on("end", cleanup);
81
+ source.on("close", cleanup);
82
+ dest.on("close", cleanup);
83
+ dest.emit("pipe", source);
84
+ return dest;
85
+ }
86
+
87
+ /* ---- Readable -------------------------------------------------------------------------------- */
88
+
89
+ class ReadableState {
90
+ constructor(options, stream) {
91
+ this.objectMode = !!(options && (options.objectMode || options.readableObjectMode));
92
+ const hwm = options && (options.readableHighWaterMark ?? options.highWaterMark);
93
+ this.highWaterMark = hwm !== undefined ? hwm : this.objectMode ? 16 : 65536;
94
+ this.buffer = [];
95
+ this.length = 0;
96
+ this.pipes = [];
97
+ this.flowing = null;
98
+ this.ended = false;
99
+ this.endEmitted = false;
100
+ this.reading = false;
101
+ this.sync = true;
102
+ this.needReadable = false;
103
+ this.emittedReadable = false;
104
+ this.readableListening = false;
105
+ this.resumeScheduled = false;
106
+ this.destroyed = false;
107
+ this.closed = false;
108
+ this.closeEmitted = false;
109
+ this.errored = null;
110
+ this.errorEmitted = false;
111
+ this.emitClose = !options || options.emitClose !== false;
112
+ this.autoDestroy = !options || options.autoDestroy !== false;
113
+ this.dataEmitted = false;
114
+ this.encoding = null;
115
+ this.decoder = null;
116
+ this.stream = stream;
117
+ if (options && options.encoding) this.setEncoding(options.encoding);
118
+ }
119
+
120
+ setEncoding(enc) {
121
+ this.encoding = Buffer.isEncoding(enc) ? String(enc).toLowerCase().replace("-", "") : "utf8";
122
+ if (this.encoding === "utf-8") this.encoding = "utf8";
123
+ this.decoder = this.encoding === "utf8" ? new TextDecoder() : null;
124
+ }
125
+
126
+ decode(buf, flush) {
127
+ if (this.decoder) return this.decoder.decode(buf, { stream: !flush });
128
+ return buf.toString(this.encoding);
129
+ }
130
+ }
131
+
132
+ export function Readable(options) {
133
+ if (!(this instanceof Readable)) return new Readable(options);
134
+ Stream.call(this, options);
135
+ this._readableState = new ReadableState(options, this);
136
+ if (options) {
137
+ if (typeof options.read === "function") this._read = options.read;
138
+ if (typeof options.destroy === "function") this._destroy = options.destroy;
139
+ if (typeof options.construct === "function") this._construct = options.construct;
140
+ if (options.signal) addAbortSignal(options.signal, this);
141
+ }
142
+ }
143
+ Object.setPrototypeOf(Readable.prototype, Stream.prototype);
144
+ Object.setPrototypeOf(Readable, Stream);
145
+
146
+ Readable.prototype._read = function () {
147
+ throw codeError(Error, "The _read() method is not implemented", "ERR_METHOD_NOT_IMPLEMENTED");
148
+ };
149
+
150
+ function readableAddChunk(stream, chunk, encoding, prepend) {
151
+ const state = stream._readableState;
152
+ if (chunk === null) {
153
+ state.reading = false;
154
+ onEofChunk(stream, state);
155
+ return false;
156
+ }
157
+ if (!state.objectMode) {
158
+ if (typeof chunk === "string") {
159
+ encoding = encoding || "utf8";
160
+ if (state.encoding !== encoding) chunk = Buffer.from(chunk, encoding);
161
+ else if (state.encoding) {
162
+ return addChunk(stream, state, chunk, prepend);
163
+ }
164
+ } else if (isUint8(chunk) && !Buffer.isBuffer(chunk)) {
165
+ chunk = Buffer.from(chunk.buffer, chunk.byteOffset, chunk.byteLength);
166
+ } else if (!isUint8(chunk)) {
167
+ const e = codeError(TypeError, 'The "chunk" argument must be of type string or an instance of Buffer or Uint8Array.', "ERR_INVALID_ARG_TYPE");
168
+ errorOrDestroy(stream, e);
169
+ return false;
170
+ }
171
+ if (state.decoder || (state.encoding && state.encoding !== "buffer")) chunk = state.decode(chunk, false);
172
+ }
173
+ if (state.ended && !prepend) {
174
+ errorOrDestroy(stream, codeError(Error, "stream.push() after EOF", "ERR_STREAM_PUSH_AFTER_EOF"));
175
+ return false;
176
+ }
177
+ if (state.destroyed || state.errored) return false;
178
+ state.reading = false;
179
+ if (!state.objectMode && chunk.length === 0) {
180
+ maybeReadMore(stream, state);
181
+ return state.length < state.highWaterMark;
182
+ }
183
+ addChunk(stream, state, chunk, prepend);
184
+ return !state.ended && (state.length < state.highWaterMark || state.length === 0);
185
+ }
186
+
187
+ function addChunk(stream, state, chunk, prepend) {
188
+ if (state.flowing && state.length === 0 && !state.sync && stream.listenerCount("data") > 0) {
189
+ state.dataEmitted = true;
190
+ stream.emit("data", chunk);
191
+ } else {
192
+ state.length += chunkSize(chunk, state.objectMode);
193
+ if (prepend) state.buffer.unshift(chunk);
194
+ else state.buffer.push(chunk);
195
+ if (state.needReadable) emitReadable(stream);
196
+ }
197
+ maybeReadMore(stream, state);
198
+ }
199
+
200
+ Readable.prototype.push = function (chunk, encoding) {
201
+ return readableAddChunk(this, chunk, encoding, false);
202
+ };
203
+
204
+ Readable.prototype.unshift = function (chunk, encoding) {
205
+ return readableAddChunk(this, chunk, encoding, true);
206
+ };
207
+
208
+ Readable.prototype.isPaused = function () {
209
+ return this._readableState.flowing === false;
210
+ };
211
+
212
+ Readable.prototype.setEncoding = function (enc) {
213
+ const state = this._readableState;
214
+ state.setEncoding(enc);
215
+ state.buffer = state.buffer.map((c) => (typeof c === "string" ? c : state.decode(c, false)));
216
+ return this;
217
+ };
218
+
219
+ /* the chunks for read(n): n bytes (or characters), or everything */
220
+ function fromList(n, state) {
221
+ if (state.length === 0) return null;
222
+ let ret;
223
+ if (state.objectMode) ret = state.buffer.shift();
224
+ else if (!n || n >= state.length) {
225
+ ret = state.decoder || state.encoding ? state.buffer.join("") : state.buffer.length === 1 ? state.buffer[0] : Buffer.concat(state.buffer);
226
+ state.buffer = [];
227
+ } else {
228
+ const parts = [];
229
+ let need = n;
230
+ while (need > 0) {
231
+ const head = state.buffer[0];
232
+ if (head.length <= need) {
233
+ parts.push(head);
234
+ state.buffer.shift();
235
+ need -= head.length;
236
+ } else {
237
+ parts.push(head.slice(0, need));
238
+ state.buffer[0] = head.slice(need);
239
+ need = 0;
240
+ }
241
+ }
242
+ ret = typeof parts[0] === "string" ? parts.join("") : Buffer.concat(parts);
243
+ }
244
+ state.length -= chunkSize(ret, state.objectMode);
245
+ return ret;
246
+ }
247
+
248
+ /* how much read(n) returns: one object, the first chunk when flowing, everything when n is
249
+ * NaN, n when buffered, else nothing until more arrives (or it ends) */
250
+ function howMuchToRead(n, state) {
251
+ if (n <= 0 || (state.length === 0 && state.ended)) return 0;
252
+ if (state.objectMode) return 1;
253
+ if (Number.isNaN(n)) return state.flowing && state.length ? state.buffer[0].length : state.length;
254
+ if (n <= state.length) return n;
255
+ return state.ended ? state.length : 0;
256
+ }
257
+
258
+ Readable.prototype.read = function (n) {
259
+ const state = this._readableState;
260
+ n = n === undefined ? NaN : Number(n);
261
+ const nOrig = n;
262
+ if (n !== 0) state.emittedReadable = false;
263
+ if (n === 0 && state.needReadable && (state.length >= state.highWaterMark || state.ended)) {
264
+ if (state.length === 0 && state.ended) endReadable(this);
265
+ else emitReadable(this);
266
+ return null;
267
+ }
268
+ n = howMuchToRead(n, state);
269
+ if (n === 0 && state.ended) {
270
+ if (state.length === 0) endReadable(this);
271
+ return null;
272
+ }
273
+ let doRead = state.needReadable || state.length === 0 || state.length - n < state.highWaterMark;
274
+ if (state.ended || state.reading || state.destroyed || state.errored) doRead = false;
275
+ if (doRead) {
276
+ state.reading = true;
277
+ state.sync = true;
278
+ if (state.length === 0) state.needReadable = true;
279
+ try {
280
+ this._read(state.highWaterMark);
281
+ } catch (e) {
282
+ errorOrDestroy(this, e);
283
+ }
284
+ state.sync = false;
285
+ if (!state.reading) n = howMuchToRead(nOrig, state);
286
+ }
287
+ const ret = n > 0 ? fromList(n, state) : null;
288
+ if (ret === null) {
289
+ state.needReadable = state.length <= state.highWaterMark;
290
+ n = 0;
291
+ } else {
292
+ state.readableDidRead = true;
293
+ }
294
+ if (state.length === 0) {
295
+ if (!state.ended) state.needReadable = true;
296
+ if (nOrig !== n && state.ended) endReadable(this);
297
+ }
298
+ if (ret !== null && !state.errorEmitted && !state.closeEmitted) {
299
+ state.dataEmitted = true;
300
+ this.emit("data", ret);
301
+ }
302
+ return ret;
303
+ };
304
+
305
+ function onEofChunk(stream, state) {
306
+ if (state.ended) return;
307
+ if (state.decoder) {
308
+ const rest = state.decoder.decode();
309
+ if (rest.length) {
310
+ state.buffer.push(rest);
311
+ state.length += state.objectMode ? 1 : rest.length;
312
+ }
313
+ }
314
+ state.ended = true;
315
+ if (state.sync) emitReadable(stream);
316
+ else {
317
+ state.needReadable = false;
318
+ state.emittedReadable = true;
319
+ emitReadable_(stream);
320
+ }
321
+ }
322
+
323
+ function emitReadable(stream) {
324
+ const state = stream._readableState;
325
+ state.needReadable = false;
326
+ if (!state.emittedReadable) {
327
+ state.emittedReadable = true;
328
+ nextTick(emitReadable_, stream);
329
+ }
330
+ }
331
+
332
+ function emitReadable_(stream) {
333
+ const state = stream._readableState;
334
+ if (!state.destroyed && !state.errored && (state.length || state.ended)) {
335
+ stream.emit("readable");
336
+ state.emittedReadable = false;
337
+ }
338
+ state.needReadable = !state.flowing && !state.ended && state.length <= state.highWaterMark;
339
+ flow(stream);
340
+ }
341
+
342
+ function maybeReadMore(stream, state) {
343
+ if (!state.readingMore && !state.ended) {
344
+ state.readingMore = true;
345
+ nextTick(() => {
346
+ while (!state.reading && !state.ended && (state.length < state.highWaterMark || (state.flowing && state.length === 0))) {
347
+ const len = state.length;
348
+ stream.read(0);
349
+ if (len === state.length) break;
350
+ }
351
+ state.readingMore = false;
352
+ });
353
+ }
354
+ }
355
+
356
+ Readable.prototype.on = function (ev, fn) {
357
+ const res = Stream.prototype.on.call(this, ev, fn);
358
+ const state = this._readableState;
359
+ if (ev === "data") {
360
+ state.readableListening = this.listenerCount("readable") > 0;
361
+ if (state.flowing !== false) this.resume();
362
+ } else if (ev === "readable") {
363
+ if (!state.endEmitted && !state.readableListening) {
364
+ state.readableListening = state.needReadable = true;
365
+ state.flowing = false;
366
+ state.emittedReadable = false;
367
+ if (state.length) emitReadable(this);
368
+ else if (!state.reading) nextTick(() => this.read(0));
369
+ }
370
+ }
371
+ return res;
372
+ };
373
+ Readable.prototype.addListener = Readable.prototype.on;
374
+
375
+ Readable.prototype.removeListener = function (ev, fn) {
376
+ const res = Stream.prototype.removeListener.call(this, ev, fn);
377
+ if (ev === "readable") nextTick(updateReadableListening, this);
378
+ return res;
379
+ };
380
+ Readable.prototype.off = Readable.prototype.removeListener;
381
+
382
+ function updateReadableListening(self) {
383
+ const state = self._readableState;
384
+ state.readableListening = self.listenerCount("readable") > 0;
385
+ if (state.resumeScheduled && state.paused === false) state.flowing = true;
386
+ else if (self.listenerCount("data") > 0) self.resume();
387
+ else if (!state.readableListening) state.flowing = null;
388
+ }
389
+
390
+ Readable.prototype.resume = function () {
391
+ const state = this._readableState;
392
+ if (!state.flowing) {
393
+ state.flowing = !state.readableListening;
394
+ if (!state.resumeScheduled) {
395
+ state.resumeScheduled = true;
396
+ nextTick(() => {
397
+ if (!state.reading) this.read(0);
398
+ state.resumeScheduled = false;
399
+ this.emit("resume");
400
+ flow(this);
401
+ if (state.flowing && !state.reading) this.read(0);
402
+ });
403
+ }
404
+ }
405
+ state.paused = false;
406
+ return this;
407
+ };
408
+
409
+ Readable.prototype.pause = function () {
410
+ const state = this._readableState;
411
+ if (state.flowing !== false) {
412
+ state.flowing = false;
413
+ this.emit("pause");
414
+ }
415
+ state.paused = true;
416
+ return this;
417
+ };
418
+
419
+ function flow(stream) {
420
+ const state = stream._readableState;
421
+ while (state.flowing && stream.read() !== null);
422
+ }
423
+
424
+ function endReadable(stream) {
425
+ const state = stream._readableState;
426
+ if (!state.endEmitted) {
427
+ state.ended = true;
428
+ nextTick(() => {
429
+ if (!state.errored && !state.closeEmitted && !state.endEmitted && state.length === 0) {
430
+ state.endEmitted = true;
431
+ stream.emit("end");
432
+ const ws = stream._writableState;
433
+ const autoDestroy = !ws || (ws.autoDestroy && (ws.finished || ws.writable === false));
434
+ if (state.autoDestroy && autoDestroy) stream.destroy();
435
+ }
436
+ });
437
+ }
438
+ }
439
+
440
+ Readable.prototype.pipe = function (dest, pipeOpts) {
441
+ const state = this._readableState;
442
+ state.pipes.push(dest);
443
+ const doEnd = (!pipeOpts || pipeOpts.end !== false) && dest !== process.stdout && dest !== process.stderr;
444
+ const onend = () => dest.end();
445
+ if (doEnd) this.once("end", onend);
446
+ let ondrain;
447
+ const ondata = (chunk) => {
448
+ const ret = dest.write(chunk);
449
+ if (ret === false) {
450
+ this.pause();
451
+ if (!ondrain) {
452
+ ondrain = () => {
453
+ ondrain = null;
454
+ this.resume();
455
+ };
456
+ dest.once("drain", ondrain);
457
+ }
458
+ }
459
+ };
460
+ this.on("data", ondata);
461
+ const cleanup = () => {
462
+ this.removeListener("data", ondata);
463
+ this.removeListener("end", onend);
464
+ dest.removeListener("close", onclose);
465
+ dest.removeListener("finish", onfinish);
466
+ dest.removeListener("error", onerror);
467
+ };
468
+ const onerror = (er) => {
469
+ this.unpipe(dest);
470
+ dest.removeListener("error", onerror);
471
+ if (dest.listenerCount("error") === 0) {
472
+ const s = dest._writableState || dest._readableState;
473
+ if (s && !s.errorEmitted) errorOrDestroy(dest, er);
474
+ else dest.emit("error", er);
475
+ }
476
+ };
477
+ dest.prependListener("error", onerror);
478
+ const onclose = () => {
479
+ dest.removeListener("finish", onfinish);
480
+ this.unpipe(dest);
481
+ };
482
+ const onfinish = () => {
483
+ dest.removeListener("close", onclose);
484
+ this.unpipe(dest);
485
+ };
486
+ dest.once("close", onclose);
487
+ dest.once("finish", onfinish);
488
+ dest._pipeCleanup = cleanup;
489
+ dest.emit("pipe", this);
490
+ if (dest.writableNeedDrain === true) this.pause();
491
+ else if (!state.flowing) this.resume();
492
+ return dest;
493
+ };
494
+
495
+ Readable.prototype.unpipe = function (dest) {
496
+ const state = this._readableState;
497
+ const dests = dest ? [dest] : state.pipes.slice();
498
+ for (const d of dests) {
499
+ const i = state.pipes.indexOf(d);
500
+ if (i < 0) continue;
501
+ state.pipes.splice(i, 1);
502
+ if (d._pipeCleanup) d._pipeCleanup();
503
+ d.emit("unpipe", this);
504
+ }
505
+ if (state.pipes.length === 0) this.pause();
506
+ return this;
507
+ };
508
+
509
+ Readable.prototype[Symbol.asyncIterator] = function () {
510
+ return createAsyncIterator(this);
511
+ };
512
+
513
+ Readable.prototype.iterator = function (options) {
514
+ return createAsyncIterator(this, options);
515
+ };
516
+
517
+ async function* createAsyncIterator(stream, options) {
518
+ let wake = () => {};
519
+ const next = () => wake();
520
+ stream.on("readable", next);
521
+ let error;
522
+ let done = false;
523
+ finished(stream, { writable: false }, (err) => {
524
+ error = err ? aggregateTwoErrors(error, err) : null;
525
+ done = true;
526
+ wake();
527
+ });
528
+ try {
529
+ for (;;) {
530
+ const chunk = stream.destroyed ? null : stream.read();
531
+ if (chunk !== null) yield chunk;
532
+ else if (error) throw error;
533
+ else if (error === null || done) return;
534
+ else await new Promise((resolve) => (wake = resolve));
535
+ }
536
+ } catch (err) {
537
+ error = aggregateTwoErrors(error, err);
538
+ throw error;
539
+ } finally {
540
+ if ((error || options?.destroyOnReturn !== false) && (error === undefined || stream._readableState.autoDestroy)) destroyImpl(stream, null);
541
+ else stream.off?.("readable", next);
542
+ }
543
+ }
544
+
545
+ function aggregateTwoErrors(inner, outer) {
546
+ return inner || outer;
547
+ }
548
+
549
+ const readableGetters = {
550
+ readable: (s, st) => !!(st.readable !== false && !st.destroyed && !st.errorEmitted && !st.endEmitted),
551
+ readableDidRead: (s, st) => !!st.readableDidRead,
552
+ readableAborted: (s, st) => !!(st.readable !== false && (st.destroyed || st.errored) && !st.endEmitted),
553
+ readableHighWaterMark: (s, st) => st.highWaterMark,
554
+ readableBuffer: (s, st) => st.buffer,
555
+ readableFlowing: (s, st) => st.flowing,
556
+ readableLength: (s, st) => st.length,
557
+ readableObjectMode: (s, st) => st.objectMode,
558
+ readableEncoding: (s, st) => st.encoding,
559
+ readableEnded: (s, st) => st.endEmitted,
560
+ errored: (s, st) => st.errored,
561
+ closed: (s, st) => st.closed,
562
+ destroyed: (s, st) => st.destroyed,
563
+ };
564
+ for (const name of Object.keys(readableGetters)) {
565
+ const get = readableGetters[name];
566
+ Object.defineProperty(Readable.prototype, name, {
567
+ get() {
568
+ const st = this._readableState;
569
+ return st ? get(this, st) : undefined;
570
+ },
571
+ set(v) {
572
+ if (name === "readable" && this._readableState) this._readableState.readable = v;
573
+ else if (name === "destroyed" && this._readableState) this._readableState.destroyed = v;
574
+ else if (name === "readableFlowing" && this._readableState) this._readableState.flowing = v;
575
+ },
576
+ enumerable: false,
577
+ configurable: true,
578
+ });
579
+ }
580
+
581
+ Readable.from = function (iterable, opts) {
582
+ if (typeof iterable === "string" || isUint8(iterable)) {
583
+ return new Readable({
584
+ objectMode: true,
585
+ ...opts,
586
+ read() {
587
+ this.push(iterable);
588
+ this.push(null);
589
+ },
590
+ });
591
+ }
592
+ const iterator = iterable[Symbol.asyncIterator] ? iterable[Symbol.asyncIterator]() : iterable[Symbol.iterator]();
593
+ let reading = false;
594
+ const readable = new Readable({
595
+ objectMode: true,
596
+ highWaterMark: 1,
597
+ ...opts,
598
+ async read() {
599
+ if (reading) return;
600
+ reading = true;
601
+ try {
602
+ for (;;) {
603
+ const { value, done } = await iterator.next();
604
+ if (done) {
605
+ this.push(null);
606
+ break;
607
+ }
608
+ const chunk = value && typeof value.then === "function" ? await value : value;
609
+ if (chunk === null) throw codeError(TypeError, "May not write null values to stream", "ERR_STREAM_NULL_VALUES");
610
+ if (!this.push(chunk)) break;
611
+ }
612
+ } catch (err) {
613
+ this.destroy(err);
614
+ }
615
+ reading = false;
616
+ },
617
+ destroy(error, cb) {
618
+ Promise.resolve(typeof iterator.return === "function" ? iterator.return() : undefined).then(() => cb(error), (e) => cb(e || error));
619
+ },
620
+ });
621
+ return readable;
622
+ };
623
+
624
+ /* Readable.toWeb(readable): a ReadableStream of its chunks (as Uint8Arrays) */
625
+ Readable.toWeb = function (streamReadable) {
626
+ const objectMode = streamReadable.readableObjectMode;
627
+ let controller;
628
+ let closed = false;
629
+ const onData = (chunk) => {
630
+ if (closed) return;
631
+ if (Buffer.isBuffer(chunk) && !objectMode) chunk = new Uint8Array(chunk.buffer, chunk.byteOffset, chunk.byteLength);
632
+ controller.enqueue(chunk);
633
+ if (controller.desiredSize <= 0) streamReadable.pause();
634
+ };
635
+ return new ReadableStream({
636
+ start(c) {
637
+ controller = c;
638
+ streamReadable.on("data", onData);
639
+ finished(streamReadable, (error) => {
640
+ if (closed) return;
641
+ closed = true;
642
+ if (error && error.code !== "ERR_STREAM_PREMATURE_CLOSE") controller.error(error);
643
+ else if (error) controller.error(error);
644
+ else controller.close();
645
+ });
646
+ if (streamReadable.readableEnded) {
647
+ closed = true;
648
+ controller.close();
649
+ }
650
+ },
651
+ pull() {
652
+ streamReadable.resume();
653
+ },
654
+ cancel(reason) {
655
+ closed = true;
656
+ destroyImpl(streamReadable, reason);
657
+ },
658
+ }, { highWaterMark: objectMode ? 16 : 65536, size: objectMode ? undefined : (chunk) => chunk.byteLength });
659
+ };
660
+
661
+ /* Readable.fromWeb(readableStream): a Readable of its chunks */
662
+ Readable.fromWeb = function (readableStream, options) {
663
+ const reader = readableStream.getReader();
664
+ let closed = false;
665
+ const readable = new Readable({
666
+ objectMode: !!(options && options.objectMode),
667
+ highWaterMark: options?.highWaterMark,
668
+ encoding: options?.encoding,
669
+ read() {
670
+ reader.read().then(({ value, done }) => {
671
+ if (done) this.push(null);
672
+ else this.push(value);
673
+ }, (error) => this.destroy(error));
674
+ },
675
+ destroy(error, callback) {
676
+ if (!closed) reader.cancel(error).then(() => callback(error), (e) => callback(e));
677
+ else callback(error);
678
+ },
679
+ });
680
+ reader.closed.then(() => (closed = true), () => (closed = true));
681
+ return readable;
682
+ };
683
+
684
+ /* ---- Writable -------------------------------------------------------------------------------- */
685
+
686
+ class WritableState {
687
+ constructor(options, stream) {
688
+ this.objectMode = !!(options && (options.objectMode || options.writableObjectMode));
689
+ const hwm = options && (options.writableHighWaterMark ?? options.highWaterMark);
690
+ this.highWaterMark = hwm !== undefined ? hwm : this.objectMode ? 16 : 65536;
691
+ this.decodeStrings = !options || options.decodeStrings !== false;
692
+ this.defaultEncoding = (options && options.defaultEncoding) || "utf8";
693
+ this.length = 0;
694
+ this.writing = false;
695
+ this.corked = 0;
696
+ this.buffered = [];
697
+ this.needDrain = false;
698
+ this.ending = false;
699
+ this.ended = false;
700
+ this.finished = false;
701
+ this.finalCalled = false;
702
+ this.prefinished = false;
703
+ this.destroyed = false;
704
+ this.closed = false;
705
+ this.closeEmitted = false;
706
+ this.errored = null;
707
+ this.errorEmitted = false;
708
+ this.emitClose = !options || options.emitClose !== false;
709
+ this.autoDestroy = !options || options.autoDestroy !== false;
710
+ this.pendingcb = 0;
711
+ this.stream = stream;
712
+ }
713
+ }
714
+
715
+ export function Writable(options) {
716
+ /* as Node checks: Duplex first, and without Writable's Symbol.hasInstance (which reads
717
+ * _writableState: a lazy stream, crypto's Hash, would make it while it is being made) */
718
+ if (!(this instanceof Duplex) && !Function.prototype[Symbol.hasInstance].call(Writable, this)) return new Writable(options);
719
+ Stream.call(this, options);
720
+ this._writableState = new WritableState(options, this);
721
+ if (options) {
722
+ if (typeof options.write === "function") this._write = options.write;
723
+ if (typeof options.writev === "function") this._writev = options.writev;
724
+ if (typeof options.destroy === "function") this._destroy = options.destroy;
725
+ if (typeof options.final === "function") this._final = options.final;
726
+ if (options.signal) addAbortSignal(options.signal, this);
727
+ }
728
+ }
729
+ Object.setPrototypeOf(Writable.prototype, Stream.prototype);
730
+ Object.setPrototypeOf(Writable, Stream);
731
+
732
+ Object.defineProperty(Writable, Symbol.hasInstance, {
733
+ value(object) {
734
+ if (Function.prototype[Symbol.hasInstance].call(this, object)) return true;
735
+ if (this !== Writable) return false;
736
+ return !!(object && object._writableState);
737
+ },
738
+ configurable: true,
739
+ });
740
+
741
+ Writable.prototype._write = function (chunk, encoding, cb) {
742
+ if (this._writev) this._writev([{ chunk, encoding }], cb);
743
+ else throw codeError(Error, "The _write() method is not implemented", "ERR_METHOD_NOT_IMPLEMENTED");
744
+ };
745
+
746
+ Writable.prototype.write = function (chunk, encoding, cb) {
747
+ const state = this._writableState;
748
+ if (typeof encoding === "function") {
749
+ cb = encoding;
750
+ encoding = null;
751
+ }
752
+ if (!encoding) encoding = state.defaultEncoding;
753
+ if (typeof cb !== "function") cb = () => {};
754
+ if (chunk === null) throw codeError(TypeError, "May not write null values to stream", "ERR_STREAM_NULL_VALUES");
755
+ if (!state.objectMode) {
756
+ if (typeof chunk === "string") {
757
+ if (state.decodeStrings !== false) {
758
+ chunk = Buffer.from(chunk, encoding);
759
+ encoding = "buffer";
760
+ }
761
+ } else if (isUint8(chunk)) {
762
+ if (!Buffer.isBuffer(chunk)) chunk = Buffer.from(chunk.buffer, chunk.byteOffset, chunk.byteLength);
763
+ encoding = "buffer";
764
+ } else {
765
+ throw codeError(TypeError, 'The "chunk" argument must be of type string or an instance of Buffer or Uint8Array.', "ERR_INVALID_ARG_TYPE");
766
+ }
767
+ }
768
+ let err;
769
+ if (state.ending) err = codeError(Error, "write after end", "ERR_STREAM_WRITE_AFTER_END");
770
+ else if (state.destroyed) err = codeError(Error, "Cannot call write after a stream was destroyed", "ERR_STREAM_DESTROYED");
771
+ if (err) {
772
+ nextTick(cb, err);
773
+ errorOrDestroy(this, err, true);
774
+ return err;
775
+ }
776
+ state.pendingcb++;
777
+ const len = state.objectMode ? 1 : chunk.length;
778
+ state.length += len;
779
+ const ret = state.length < state.highWaterMark;
780
+ if (!ret) state.needDrain = true;
781
+ if (state.writing || state.corked || state.errored) state.buffered.push({ chunk, encoding, callback: cb });
782
+ else doWrite(this, state, len, chunk, encoding, cb);
783
+ return ret && !state.errored && !state.destroyed;
784
+ };
785
+
786
+ function doWrite(stream, state, len, chunk, encoding, cb) {
787
+ state.writelen = len;
788
+ state.writecb = cb;
789
+ state.writing = true;
790
+ state.sync = true;
791
+ if (state.destroyed) onwrite(stream, codeError(Error, "Cannot call write after a stream was destroyed", "ERR_STREAM_DESTROYED"));
792
+ else stream._write(chunk, encoding, (er) => onwrite(stream, er));
793
+ state.sync = false;
794
+ }
795
+
796
+ function onwrite(stream, er) {
797
+ const state = stream._writableState;
798
+ const cb = state.writecb;
799
+ if (typeof cb !== "function") {
800
+ errorOrDestroy(stream, codeError(Error, "Callback called multiple times", "ERR_MULTIPLE_CALLBACK"));
801
+ return;
802
+ }
803
+ state.writing = false;
804
+ state.writecb = null;
805
+ state.length -= state.writelen;
806
+ state.writelen = 0;
807
+ if (er) {
808
+ if (!state.errored) state.errored = er;
809
+ if (state.sync) nextTick(onwriteError, stream, state, er, cb);
810
+ else onwriteError(stream, state, er, cb);
811
+ return;
812
+ }
813
+ if (state.buffered.length > 0) clearBuffer(stream, state);
814
+ if (state.sync) nextTick(afterWrite, stream, state, cb);
815
+ else afterWrite(stream, state, cb);
816
+ }
817
+
818
+ function onwriteError(stream, state, er, cb) {
819
+ --state.pendingcb;
820
+ cb(er);
821
+ errorBuffer(state);
822
+ errorOrDestroy(stream, er);
823
+ }
824
+
825
+ function afterWrite(stream, state, cb) {
826
+ const needDrain = !state.ending && !stream.destroyed && state.length === 0 && state.needDrain;
827
+ if (needDrain) {
828
+ state.needDrain = false;
829
+ stream.emit("drain");
830
+ }
831
+ state.pendingcb--;
832
+ cb(null);
833
+ if (state.destroyed) errorBuffer(state);
834
+ finishMaybe(stream, state);
835
+ }
836
+
837
+ function errorBuffer(state) {
838
+ if (state.writing) return;
839
+ for (const { chunk, callback } of state.buffered) {
840
+ state.length -= state.objectMode ? 1 : chunk.length;
841
+ state.pendingcb--;
842
+ callback(state.errored ?? codeError(Error, "Cannot call write after a stream was destroyed", "ERR_STREAM_DESTROYED"));
843
+ }
844
+ state.buffered = [];
845
+ }
846
+
847
+ function clearBuffer(stream, state) {
848
+ if (state.corked || state.destroyed || state.writing || state.buffered.length === 0) return;
849
+ const { chunk, encoding, callback } = state.buffered.shift();
850
+ doWrite(stream, state, state.objectMode ? 1 : chunk.length, chunk, encoding, callback);
851
+ }
852
+
853
+ Writable.prototype.cork = function () {
854
+ this._writableState.corked++;
855
+ };
856
+
857
+ Writable.prototype.uncork = function () {
858
+ const state = this._writableState;
859
+ if (state.corked) {
860
+ state.corked--;
861
+ if (!state.writing) clearBuffer(this, state);
862
+ }
863
+ };
864
+
865
+ Writable.prototype.setDefaultEncoding = function (encoding) {
866
+ this._writableState.defaultEncoding = encoding;
867
+ return this;
868
+ };
869
+
870
+ Writable.prototype.end = function (chunk, encoding, cb) {
871
+ const state = this._writableState;
872
+ if (typeof chunk === "function") {
873
+ cb = chunk;
874
+ chunk = null;
875
+ encoding = null;
876
+ } else if (typeof encoding === "function") {
877
+ cb = encoding;
878
+ encoding = null;
879
+ }
880
+ let err;
881
+ if (chunk !== null && chunk !== undefined) {
882
+ const ret = this.write(chunk, encoding);
883
+ if (ret instanceof Error) err = ret;
884
+ }
885
+ if (state.corked) {
886
+ state.corked = 1;
887
+ this.uncork();
888
+ }
889
+ if (err) {
890
+ /* already reported */
891
+ } else if (!state.errored && !state.ending) {
892
+ state.ending = true;
893
+ finishMaybe(this, state, true);
894
+ state.ended = true;
895
+ } else if (state.finished) {
896
+ err = codeError(Error, "Cannot call end after a stream was finished", "ERR_STREAM_ALREADY_FINISHED");
897
+ } else if (state.destroyed) {
898
+ err = codeError(Error, "Cannot call end after a stream was destroyed", "ERR_STREAM_DESTROYED");
899
+ }
900
+ if (typeof cb === "function") {
901
+ if (err || state.finished) nextTick(cb, err);
902
+ else (state.finishCallbacks ||= []).push(cb);
903
+ }
904
+ return this;
905
+ };
906
+
907
+ function needFinish(state) {
908
+ return state.ending && !state.destroyed && state.length === 0 && !state.errored && state.buffered.length === 0 &&
909
+ !state.finished && !state.writing && !state.errorEmitted && !state.closeEmitted;
910
+ }
911
+
912
+ function prefinish(stream, state) {
913
+ if (!state.prefinished && !state.finalCalled) {
914
+ if (typeof stream._final === "function" && !state.destroyed) {
915
+ state.finalCalled = true;
916
+ state.sync = true;
917
+ state.pendingcb++;
918
+ let called = false;
919
+ const onFinal = (err) => {
920
+ if (called) return;
921
+ called = true;
922
+ state.pendingcb--;
923
+ if (err) {
924
+ for (const cb of state.finishCallbacks || []) cb(err);
925
+ state.finishCallbacks = [];
926
+ errorOrDestroy(stream, err, state.sync);
927
+ } else if (needFinish(state)) {
928
+ state.prefinished = true;
929
+ stream.emit("prefinish");
930
+ state.pendingcb++;
931
+ nextTick(finish, stream, state);
932
+ }
933
+ };
934
+ try {
935
+ stream._final(onFinal);
936
+ } catch (err) {
937
+ onFinal(err);
938
+ }
939
+ state.sync = false;
940
+ } else {
941
+ state.prefinished = true;
942
+ stream.emit("prefinish");
943
+ }
944
+ }
945
+ }
946
+
947
+ function finishMaybe(stream, state, sync) {
948
+ if (needFinish(state)) {
949
+ prefinish(stream, state);
950
+ if (state.pendingcb === 0) {
951
+ if (sync) {
952
+ state.pendingcb++;
953
+ nextTick(() => {
954
+ if (needFinish(state)) finish(stream, state);
955
+ else state.pendingcb--;
956
+ });
957
+ } else if (needFinish(state)) {
958
+ state.pendingcb++;
959
+ finish(stream, state);
960
+ }
961
+ }
962
+ }
963
+ }
964
+
965
+ function finish(stream, state) {
966
+ state.pendingcb--;
967
+ state.finished = true;
968
+ for (const cb of state.finishCallbacks || []) cb(null);
969
+ state.finishCallbacks = [];
970
+ stream.emit("finish");
971
+ if (state.autoDestroy) {
972
+ const rState = stream._readableState;
973
+ const autoDestroy = !rState || (rState.autoDestroy && (rState.endEmitted || rState.readable === false));
974
+ if (autoDestroy) stream.destroy();
975
+ }
976
+ }
977
+
978
+ const writableGetters = {
979
+ writable: (s, st) => !!(st.writable !== false && !st.destroyed && !st.errored && !st.ending && !st.ended),
980
+ writableFinished: (s, st) => st.finished,
981
+ writableObjectMode: (s, st) => st.objectMode,
982
+ writableBuffer: (s, st) => st.buffered.map((b) => b.chunk),
983
+ writableEnded: (s, st) => st.ending,
984
+ writableNeedDrain: (s, st) => !st.destroyed && !st.ending && st.needDrain,
985
+ writableHighWaterMark: (s, st) => st.highWaterMark,
986
+ writableCorked: (s, st) => st.corked,
987
+ writableLength: (s, st) => st.length,
988
+ writableAborted: (s, st) => !!(st.writable !== false && (st.destroyed || st.errored) && !st.finished),
989
+ };
990
+ for (const name of Object.keys(writableGetters)) {
991
+ const get = writableGetters[name];
992
+ Object.defineProperty(Writable.prototype, name, {
993
+ get() {
994
+ const st = this._writableState;
995
+ return st ? get(this, st) : undefined;
996
+ },
997
+ set(v) {
998
+ if (name === "writable" && this._writableState) this._writableState.writable = v;
999
+ },
1000
+ enumerable: false,
1001
+ configurable: true,
1002
+ });
1003
+ }
1004
+ for (const name of ["destroyed", "errored", "closed"]) {
1005
+ Object.defineProperty(Writable.prototype, name, {
1006
+ get() {
1007
+ const st = this._writableState;
1008
+ return st ? (name === "destroyed" ? st.destroyed : name === "errored" ? st.errored : st.closed) : undefined;
1009
+ },
1010
+ set(v) {
1011
+ if (name === "destroyed" && this._writableState) this._writableState.destroyed = v;
1012
+ },
1013
+ enumerable: false,
1014
+ configurable: true,
1015
+ });
1016
+ }
1017
+
1018
+ Writable.fromWeb = function (writableStream) {
1019
+ const writer = writableStream.getWriter();
1020
+ return new Writable({
1021
+ write(chunk, encoding, cb) {
1022
+ writer.write(chunk).then(() => cb(), cb);
1023
+ },
1024
+ final(cb) {
1025
+ writer.close().then(() => cb(), cb);
1026
+ },
1027
+ });
1028
+ };
1029
+
1030
+ /* ---- destroy --------------------------------------------------------------------------------- */
1031
+
1032
+ function destroyImpl(stream, err, cb) {
1033
+ const r = stream._readableState;
1034
+ const w = stream._writableState;
1035
+ const s = w || r;
1036
+ if ((w && w.destroyed) || (r && r.destroyed)) {
1037
+ if (typeof cb === "function") cb();
1038
+ return stream;
1039
+ }
1040
+ if (err) {
1041
+ if (w && !w.errored) w.errored = err;
1042
+ if (r && !r.errored) r.errored = err;
1043
+ }
1044
+ if (w) w.destroyed = true;
1045
+ if (r) r.destroyed = true;
1046
+ const onDestroy = (er) => {
1047
+ if (er) {
1048
+ if (w && !w.errored) w.errored = er;
1049
+ if (r && !r.errored) r.errored = er;
1050
+ }
1051
+ if (w) w.closed = true;
1052
+ if (r) r.closed = true;
1053
+ if (typeof cb === "function") cb(er);
1054
+ nextTick(() => {
1055
+ if (er) emitErrorNT(stream, er);
1056
+ if ((w && w.emitClose === false) || (r && r.emitClose === false)) return;
1057
+ if (w) w.closeEmitted = true;
1058
+ if (r) r.closeEmitted = true;
1059
+ stream.emit("close");
1060
+ });
1061
+ };
1062
+ try {
1063
+ stream._destroy(err || null, onDestroy);
1064
+ } catch (e) {
1065
+ onDestroy(e);
1066
+ }
1067
+ void s;
1068
+ return stream;
1069
+ }
1070
+
1071
+ function emitErrorNT(stream, err) {
1072
+ const r = stream._readableState;
1073
+ const w = stream._writableState;
1074
+ if ((w && w.errorEmitted) || (r && r.errorEmitted)) return;
1075
+ if (w) w.errorEmitted = true;
1076
+ if (r) r.errorEmitted = true;
1077
+ stream.emit("error", err);
1078
+ }
1079
+
1080
+ function errorOrDestroy(stream, err, sync) {
1081
+ const r = stream._readableState;
1082
+ const w = stream._writableState;
1083
+ if ((w && w.destroyed) || (r && r.destroyed)) return;
1084
+ if ((r && r.autoDestroy) || (w && w.autoDestroy)) stream.destroy(err);
1085
+ else if (err) {
1086
+ if (w && !w.errored) w.errored = err;
1087
+ if (r && !r.errored) r.errored = err;
1088
+ if (sync) nextTick(emitErrorNT, stream, err);
1089
+ else emitErrorNT(stream, err);
1090
+ }
1091
+ }
1092
+
1093
+ Readable.prototype.destroy = function (err, cb) {
1094
+ return destroyImpl(this, err, cb);
1095
+ };
1096
+ Readable.prototype._destroy = function (err, cb) {
1097
+ cb(err);
1098
+ };
1099
+ Writable.prototype.destroy = Readable.prototype.destroy;
1100
+ Writable.prototype._destroy = Readable.prototype._destroy;
1101
+
1102
+ /* ---- Duplex, Transform, PassThrough ---------------------------------------------------------- */
1103
+
1104
+ export function Duplex(options) {
1105
+ if (!(this instanceof Duplex)) return new Duplex(options);
1106
+ Readable.call(this, options);
1107
+ Writable.call(this, options);
1108
+ if (options) {
1109
+ this.allowHalfOpen = options.allowHalfOpen !== false;
1110
+ if (options.readable === false) {
1111
+ this._readableState.readable = false;
1112
+ this._readableState.ended = this._readableState.endEmitted = true;
1113
+ }
1114
+ if (options.writable === false) {
1115
+ this._writableState.writable = false;
1116
+ this._writableState.ending = this._writableState.ended = this._writableState.finished = true;
1117
+ }
1118
+ } else {
1119
+ this.allowHalfOpen = true;
1120
+ }
1121
+ }
1122
+ Object.setPrototypeOf(Duplex.prototype, Readable.prototype);
1123
+ Object.setPrototypeOf(Duplex, Readable);
1124
+ for (const key of Object.getOwnPropertyNames(Writable.prototype)) {
1125
+ if (key === "constructor" || key === "destroy" || key === "_destroy" || Object.prototype.hasOwnProperty.call(Duplex.prototype, key)) continue;
1126
+ if (key === "destroyed" || key === "errored" || key === "closed") continue;
1127
+ Object.defineProperty(Duplex.prototype, key, Object.getOwnPropertyDescriptor(Writable.prototype, key));
1128
+ }
1129
+
1130
+ export function Transform(options) {
1131
+ if (!(this instanceof Transform)) return new Transform(options);
1132
+ Duplex.call(this, options);
1133
+ this._readableState.sync = false;
1134
+ this._transformCallback = null;
1135
+ if (options) {
1136
+ if (typeof options.transform === "function") this._transform = options.transform;
1137
+ if (typeof options.flush === "function") this._flush = options.flush;
1138
+ }
1139
+ }
1140
+ Object.setPrototypeOf(Transform.prototype, Duplex.prototype);
1141
+ Object.setPrototypeOf(Transform, Duplex);
1142
+
1143
+ Transform.prototype._final = function (cb) {
1144
+ if (typeof this._flush === "function" && !this.destroyed) {
1145
+ this._flush((er, data) => {
1146
+ if (er) {
1147
+ cb(er);
1148
+ return;
1149
+ }
1150
+ if (data !== null && data !== undefined) this.push(data);
1151
+ this.push(null);
1152
+ cb();
1153
+ });
1154
+ } else {
1155
+ this.push(null);
1156
+ cb();
1157
+ }
1158
+ };
1159
+
1160
+ Transform.prototype._transform = function () {
1161
+ throw codeError(Error, "The _transform() method is not implemented", "ERR_METHOD_NOT_IMPLEMENTED");
1162
+ };
1163
+
1164
+ Transform.prototype._write = function (chunk, encoding, callback) {
1165
+ const rState = this._readableState;
1166
+ const length = rState.length;
1167
+ this._transform(chunk, encoding, (err, val) => {
1168
+ if (err) {
1169
+ callback(err);
1170
+ return;
1171
+ }
1172
+ if (val !== null && val !== undefined) this.push(val);
1173
+ if (rState.ended || length === rState.length || rState.length < rState.highWaterMark) callback();
1174
+ else this._transformCallback = callback;
1175
+ });
1176
+ };
1177
+
1178
+ Transform.prototype._read = function () {
1179
+ if (this._transformCallback) {
1180
+ const callback = this._transformCallback;
1181
+ this._transformCallback = null;
1182
+ callback();
1183
+ }
1184
+ };
1185
+
1186
+ export function PassThrough(options) {
1187
+ if (!(this instanceof PassThrough)) return new PassThrough(options);
1188
+ Transform.call(this, options);
1189
+ }
1190
+ Object.setPrototypeOf(PassThrough.prototype, Transform.prototype);
1191
+ Object.setPrototypeOf(PassThrough, Transform);
1192
+ PassThrough.prototype._transform = function (chunk, encoding, cb) {
1193
+ cb(null, chunk);
1194
+ };
1195
+
1196
+ /* ---- finished, pipeline, addAbortSignal ------------------------------------------------------ */
1197
+
1198
+ export function finished(stream, options, callback) {
1199
+ if (typeof options === "function") {
1200
+ callback = options;
1201
+ options = {};
1202
+ }
1203
+ options = options || {};
1204
+ let called = false;
1205
+ const done = (err) => {
1206
+ if (called) return;
1207
+ called = true;
1208
+ cleanup();
1209
+ callback.call(stream, err);
1210
+ };
1211
+ const r = stream._readableState;
1212
+ const w = stream._writableState;
1213
+ const readable = options.readable ?? (r !== undefined && r.readable !== false);
1214
+ const writable = options.writable ?? (w !== undefined && w.writable !== false);
1215
+ let readableFinished = !r || r.endEmitted;
1216
+ let writableFinished = !w || w.finished;
1217
+ const onfinish = () => {
1218
+ writableFinished = true;
1219
+ if (!readable || readableFinished) done();
1220
+ };
1221
+ const onend = () => {
1222
+ readableFinished = true;
1223
+ if (!writable || writableFinished) done();
1224
+ };
1225
+ const onerror = (err) => done(err);
1226
+ const onclose = () => {
1227
+ if (readable && !readableFinished && !(r && r.endEmitted)) return done(prematureClose());
1228
+ if (writable && !writableFinished && !(w && w.finished)) return done(prematureClose());
1229
+ done();
1230
+ };
1231
+ const onrequest = () => stream.req && stream.req.on("finish", onfinish);
1232
+ stream.on("end", onend);
1233
+ stream.on("finish", onfinish);
1234
+ stream.on("error", onerror);
1235
+ stream.on("close", onclose);
1236
+ if (stream.req) onrequest();
1237
+ function cleanup() {
1238
+ stream.removeListener("end", onend);
1239
+ stream.removeListener("finish", onfinish);
1240
+ stream.removeListener("error", onerror);
1241
+ stream.removeListener("close", onclose);
1242
+ }
1243
+ const errored = (w && w.errored) || (r && r.errored);
1244
+ if (errored) nextTick(done, errored);
1245
+ else if ((w && w.closeEmitted) || (r && r.closeEmitted)) nextTick(onclose);
1246
+ else if ((!readable || readableFinished) && (!writable || writableFinished) && (r || w)) nextTick(done);
1247
+ return cleanup;
1248
+ }
1249
+
1250
+ export function pipeline(...streams) {
1251
+ const callback = typeof streams[streams.length - 1] === "function" ? streams.pop() : null;
1252
+ if (Array.isArray(streams[0]) && streams.length === 1) streams = streams[0];
1253
+ if (streams.length < 2) throw codeError(TypeError, 'The "streams" argument must be specified', "ERR_MISSING_ARGS");
1254
+ streams = streams.map((s, i) => {
1255
+ if (typeof s === "function") s = s(i === 0 ? undefined : streams[i - 1]);
1256
+ if (s && typeof s.getReader === "function") return Readable.fromWeb(s);
1257
+ if (s && !s._readableState && !s._writableState && (s[Symbol.asyncIterator] || s[Symbol.iterator])) return Readable.from(s);
1258
+ return s;
1259
+ });
1260
+ let error;
1261
+ let remaining = streams.length;
1262
+ const destroys = [];
1263
+ const finish = (err) => {
1264
+ if (err && !error) {
1265
+ error = err;
1266
+ for (const d of destroys) d(err);
1267
+ }
1268
+ if (--remaining === 0 && callback) callback(error);
1269
+ };
1270
+ for (let i = 0; i < streams.length; i++) {
1271
+ const s = streams[i];
1272
+ const reading = i < streams.length - 1;
1273
+ const writing = i > 0;
1274
+ finished(s, { readable: reading, writable: writing }, (err) => finish(err));
1275
+ destroys.push((err) => {
1276
+ if (!s.destroyed) s.destroy(err);
1277
+ });
1278
+ if (reading) s.pipe(streams[i + 1]);
1279
+ }
1280
+ return streams[streams.length - 1];
1281
+ }
1282
+
1283
+ export function addAbortSignal(signal, stream) {
1284
+ const onAbort = () => stream.destroy(Object.assign(new Error("The operation was aborted"), { name: "AbortError", code: "ABORT_ERR", cause: signal.reason }));
1285
+ if (signal.aborted) onAbort();
1286
+ else signal.addEventListener("abort", onAbort, { once: true });
1287
+ return stream;
1288
+ }
1289
+
1290
+ export const promises = {
1291
+ pipeline(...streams) {
1292
+ return new Promise((resolve, reject) => {
1293
+ const last = streams[streams.length - 1];
1294
+ if (last && typeof last === "object" && !last._readableState && !last._writableState && !last.pipe && !last.getReader) streams.pop();
1295
+ pipeline(...streams, (err) => (err ? reject(err) : resolve()));
1296
+ });
1297
+ },
1298
+ finished(stream, opts) {
1299
+ return new Promise((resolve, reject) => finished(stream, opts || {}, (err) => (err ? reject(err) : resolve())));
1300
+ },
1301
+ };
1302
+
1303
+ export function isReadable(stream) {
1304
+ return !!(stream && stream._readableState && stream.readable);
1305
+ }
1306
+ export function isErrored(stream) {
1307
+ return !!(stream && ((stream._readableState && stream._readableState.errored) || (stream._writableState && stream._writableState.errored)));
1308
+ }
1309
+ export function isDisturbed(stream) {
1310
+ return !!(stream && stream._readableState && (stream._readableState.dataEmitted || stream._readableState.endEmitted || stream.readableDidRead));
1311
+ }
1312
+
1313
+ Stream.Stream = Stream;
1314
+ Stream.Readable = Readable;
1315
+ Stream.Writable = Writable;
1316
+ Stream.Duplex = Duplex;
1317
+ Stream.Transform = Transform;
1318
+ Stream.PassThrough = PassThrough;
1319
+ Stream.pipeline = pipeline;
1320
+ Stream.finished = finished;
1321
+ Stream.addAbortSignal = addAbortSignal;
1322
+ Stream.promises = promises;
1323
+ Stream.isReadable = isReadable;
1324
+ Stream.isErrored = isErrored;
1325
+ Stream.isDisturbed = isDisturbed;
1326
+
1327
+ export default Stream;