abtars 0.1.0-alpha.1

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 (312) hide show
  1. package/LICENSE +190 -0
  2. package/README.md +84 -0
  3. package/bundle/_registry.generated-M4WY2MMI.js +35 -0
  4. package/bundle/_registry.generated-M4WY2MMI.js.map +7 -0
  5. package/bundle/abtars-browser.js +162 -0
  6. package/bundle/abtars-browser.js.map +7 -0
  7. package/bundle/abtars-cli.js +1438 -0
  8. package/bundle/abtars-cli.js.map +7 -0
  9. package/bundle/abtars-restart.js +12 -0
  10. package/bundle/abtars-restart.js.map +7 -0
  11. package/bundle/abtars-rss.js +165 -0
  12. package/bundle/abtars-rss.js.map +7 -0
  13. package/bundle/abtars-task.js +258 -0
  14. package/bundle/abtars-task.js.map +7 -0
  15. package/bundle/abtars.js +4072 -0
  16. package/bundle/abtars.js.map +7 -0
  17. package/bundle/agent-api-rate-limit-OQNFMXTZ.js +38 -0
  18. package/bundle/agent-api-rate-limit-OQNFMXTZ.js.map +7 -0
  19. package/bundle/agent-registry-LT4JNQH6.js +18 -0
  20. package/bundle/agent-registry-LT4JNQH6.js.map +7 -0
  21. package/bundle/agents/default.md +29 -0
  22. package/bundle/anthropic-adapter-2APTH3LA.js +40 -0
  23. package/bundle/anthropic-adapter-2APTH3LA.js.map +7 -0
  24. package/bundle/bridge-lock-transport-4AC2G5G6.js +39 -0
  25. package/bundle/bridge-lock-transport-4AC2G5G6.js.map +7 -0
  26. package/bundle/browse-delivery-JXBY36GK.js +17 -0
  27. package/bundle/browse-delivery-JXBY36GK.js.map +7 -0
  28. package/bundle/browser-ELNDVPLC.js +18 -0
  29. package/bundle/browser-ELNDVPLC.js.map +7 -0
  30. package/bundle/capability-CIL3G4FI.js +17 -0
  31. package/bundle/capability-CIL3G4FI.js.map +7 -0
  32. package/bundle/chunk-265TPOPC.js +289 -0
  33. package/bundle/chunk-265TPOPC.js.map +7 -0
  34. package/bundle/chunk-2UENBO6M.js +223 -0
  35. package/bundle/chunk-2UENBO6M.js.map +7 -0
  36. package/bundle/chunk-2UPU3OW6.js +67 -0
  37. package/bundle/chunk-2UPU3OW6.js.map +7 -0
  38. package/bundle/chunk-2XU2X4OI.js +125 -0
  39. package/bundle/chunk-2XU2X4OI.js.map +7 -0
  40. package/bundle/chunk-3B7BBE4F.js +758 -0
  41. package/bundle/chunk-3B7BBE4F.js.map +7 -0
  42. package/bundle/chunk-3E545J66.js +69 -0
  43. package/bundle/chunk-3E545J66.js.map +7 -0
  44. package/bundle/chunk-5R2ANXQ7.js +510 -0
  45. package/bundle/chunk-5R2ANXQ7.js.map +7 -0
  46. package/bundle/chunk-6CPN4IGS.js +507 -0
  47. package/bundle/chunk-6CPN4IGS.js.map +7 -0
  48. package/bundle/chunk-6NR3OHEW.js +88 -0
  49. package/bundle/chunk-6NR3OHEW.js.map +7 -0
  50. package/bundle/chunk-6SETMHNN.js +206 -0
  51. package/bundle/chunk-6SETMHNN.js.map +7 -0
  52. package/bundle/chunk-6UCRKRWR.js +644 -0
  53. package/bundle/chunk-6UCRKRWR.js.map +7 -0
  54. package/bundle/chunk-AR6GO6YC.js +83 -0
  55. package/bundle/chunk-AR6GO6YC.js.map +7 -0
  56. package/bundle/chunk-AZJIODTQ.js +54 -0
  57. package/bundle/chunk-AZJIODTQ.js.map +7 -0
  58. package/bundle/chunk-BHMZ4RCC.js +3706 -0
  59. package/bundle/chunk-BHMZ4RCC.js.map +7 -0
  60. package/bundle/chunk-BQ2L4GMG.js +9175 -0
  61. package/bundle/chunk-BQ2L4GMG.js.map +7 -0
  62. package/bundle/chunk-BSSBCSCL.js +159 -0
  63. package/bundle/chunk-BSSBCSCL.js.map +7 -0
  64. package/bundle/chunk-BUUVFUPO.js +157 -0
  65. package/bundle/chunk-BUUVFUPO.js.map +7 -0
  66. package/bundle/chunk-CEVRHKJY.js +131 -0
  67. package/bundle/chunk-CEVRHKJY.js.map +7 -0
  68. package/bundle/chunk-CWOHNFUV.js +39 -0
  69. package/bundle/chunk-CWOHNFUV.js.map +7 -0
  70. package/bundle/chunk-D2DCBO6M.js +228 -0
  71. package/bundle/chunk-D2DCBO6M.js.map +7 -0
  72. package/bundle/chunk-FMWKEPM7.js +31 -0
  73. package/bundle/chunk-FMWKEPM7.js.map +7 -0
  74. package/bundle/chunk-GRNENTPA.js +145 -0
  75. package/bundle/chunk-GRNENTPA.js.map +7 -0
  76. package/bundle/chunk-GST5T3WZ.js +93 -0
  77. package/bundle/chunk-GST5T3WZ.js.map +7 -0
  78. package/bundle/chunk-GUQVJC3U.js +299 -0
  79. package/bundle/chunk-GUQVJC3U.js.map +7 -0
  80. package/bundle/chunk-HX7Y7EYP.js +3659 -0
  81. package/bundle/chunk-HX7Y7EYP.js.map +7 -0
  82. package/bundle/chunk-JCJS4ZIB.js +296 -0
  83. package/bundle/chunk-JCJS4ZIB.js.map +7 -0
  84. package/bundle/chunk-JW6RU47G.js +184 -0
  85. package/bundle/chunk-JW6RU47G.js.map +7 -0
  86. package/bundle/chunk-LSPKJQCI.js +24 -0
  87. package/bundle/chunk-LSPKJQCI.js.map +7 -0
  88. package/bundle/chunk-M6VBAPNT.js +16 -0
  89. package/bundle/chunk-M6VBAPNT.js.map +7 -0
  90. package/bundle/chunk-MPX525QO.js +129 -0
  91. package/bundle/chunk-MPX525QO.js.map +7 -0
  92. package/bundle/chunk-MW6WDLU7.js +130 -0
  93. package/bundle/chunk-MW6WDLU7.js.map +7 -0
  94. package/bundle/chunk-NT3OBORC.js +215 -0
  95. package/bundle/chunk-NT3OBORC.js.map +7 -0
  96. package/bundle/chunk-NWDBD4PA.js +50 -0
  97. package/bundle/chunk-NWDBD4PA.js.map +7 -0
  98. package/bundle/chunk-OP7BTAWY.js +29 -0
  99. package/bundle/chunk-OP7BTAWY.js.map +7 -0
  100. package/bundle/chunk-PLCY3GFH.js +77 -0
  101. package/bundle/chunk-PLCY3GFH.js.map +7 -0
  102. package/bundle/chunk-PNEDC45Y.js +97 -0
  103. package/bundle/chunk-PNEDC45Y.js.map +7 -0
  104. package/bundle/chunk-QBGBT5QS.js +81 -0
  105. package/bundle/chunk-QBGBT5QS.js.map +7 -0
  106. package/bundle/chunk-RVE2N7FA.js +70 -0
  107. package/bundle/chunk-RVE2N7FA.js.map +7 -0
  108. package/bundle/chunk-TZHIDLDS.js +71910 -0
  109. package/bundle/chunk-TZHIDLDS.js.map +7 -0
  110. package/bundle/chunk-UCQ2WC3B.js +126 -0
  111. package/bundle/chunk-UCQ2WC3B.js.map +7 -0
  112. package/bundle/chunk-UHRP745J.js +214 -0
  113. package/bundle/chunk-UHRP745J.js.map +7 -0
  114. package/bundle/chunk-V76TVMCM.js +58 -0
  115. package/bundle/chunk-V76TVMCM.js.map +7 -0
  116. package/bundle/chunk-VVEDVGCR.js +981 -0
  117. package/bundle/chunk-VVEDVGCR.js.map +7 -0
  118. package/bundle/chunk-W6FAL35D.js +102 -0
  119. package/bundle/chunk-W6FAL35D.js.map +7 -0
  120. package/bundle/chunk-X6TERNVJ.js +15902 -0
  121. package/bundle/chunk-X6TERNVJ.js.map +7 -0
  122. package/bundle/chunk-X76UX47U.js +47 -0
  123. package/bundle/chunk-X76UX47U.js.map +7 -0
  124. package/bundle/chunk-XREWVCUO.js +518 -0
  125. package/bundle/chunk-XREWVCUO.js.map +7 -0
  126. package/bundle/chunk-Y6XAEX2Q.js +408 -0
  127. package/bundle/chunk-Y6XAEX2Q.js.map +7 -0
  128. package/bundle/chunk-YOCTDKKL.js +28 -0
  129. package/bundle/chunk-YOCTDKKL.js.map +7 -0
  130. package/bundle/chunk-ZXPXCDA6.js +160 -0
  131. package/bundle/chunk-ZXPXCDA6.js.map +7 -0
  132. package/bundle/commands-BHVUOU3V.js +31 -0
  133. package/bundle/commands-BHVUOU3V.js.map +7 -0
  134. package/bundle/completion-buffer-P253ONKF.js +13 -0
  135. package/bundle/completion-buffer-P253ONKF.js.map +7 -0
  136. package/bundle/config-RGSDAPZN.js +19 -0
  137. package/bundle/config-RGSDAPZN.js.map +7 -0
  138. package/bundle/config-show-ERTATR6E.js +40 -0
  139. package/bundle/config-show-ERTATR6E.js.map +7 -0
  140. package/bundle/context-HCEGZNDC.js +72 -0
  141. package/bundle/context-HCEGZNDC.js.map +7 -0
  142. package/bundle/delegation-tools-GYTS2D6A.js +27 -0
  143. package/bundle/delegation-tools-GYTS2D6A.js.map +7 -0
  144. package/bundle/deploy-lib-import-32ZFKHWP.js +49 -0
  145. package/bundle/deploy-lib-import-32ZFKHWP.js.map +7 -0
  146. package/bundle/digital-signature-OFCGSHWO.js +13 -0
  147. package/bundle/digital-signature-OFCGSHWO.js.map +7 -0
  148. package/bundle/direct-api-transport-YR7SXXNN.js +860 -0
  149. package/bundle/direct-api-transport-YR7SXXNN.js.map +7 -0
  150. package/bundle/discord-adapter-YYWVMPPU.js +584 -0
  151. package/bundle/discord-adapter-YYWVMPPU.js.map +7 -0
  152. package/bundle/dist-MTMKARCP.js +1969 -0
  153. package/bundle/dist-MTMKARCP.js.map +7 -0
  154. package/bundle/dns-wakeup-27M7D2MR.js +107 -0
  155. package/bundle/dns-wakeup-27M7D2MR.js.map +7 -0
  156. package/bundle/doctor-QNUSDY73.js +248 -0
  157. package/bundle/doctor-QNUSDY73.js.map +7 -0
  158. package/bundle/ensure-invariants-NMXNS476.js +49 -0
  159. package/bundle/ensure-invariants-NMXNS476.js.map +7 -0
  160. package/bundle/env-schema-2KBHBDGN.js +19 -0
  161. package/bundle/env-schema-2KBHBDGN.js.map +7 -0
  162. package/bundle/esm-DDP6NCZG.js +100663 -0
  163. package/bundle/esm-DDP6NCZG.js.map +7 -0
  164. package/bundle/fallback-policy-L4QV2PEJ.js +46 -0
  165. package/bundle/fallback-policy-L4QV2PEJ.js.map +7 -0
  166. package/bundle/health-check-SPA7NT6N.js +56 -0
  167. package/bundle/health-check-SPA7NT6N.js.map +7 -0
  168. package/bundle/hook-system-6Q5YTR53.js +17 -0
  169. package/bundle/hook-system-6Q5YTR53.js.map +7 -0
  170. package/bundle/hotskills-K7BM4YLB.js +12 -0
  171. package/bundle/hotskills-K7BM4YLB.js.map +7 -0
  172. package/bundle/install-6HRZVKUM.js +15 -0
  173. package/bundle/install-6HRZVKUM.js.map +7 -0
  174. package/bundle/install-log-IAPHYKD4.js +28 -0
  175. package/bundle/install-log-IAPHYKD4.js.map +7 -0
  176. package/bundle/install-manifest-SPQRUNXL.js +102 -0
  177. package/bundle/install-manifest-SPQRUNXL.js.map +7 -0
  178. package/bundle/install-validate-PVLZXYLQ.js +53 -0
  179. package/bundle/install-validate-PVLZXYLQ.js.map +7 -0
  180. package/bundle/irc-adapter-OI5UZSQF.js +293 -0
  181. package/bundle/irc-adapter-OI5UZSQF.js.map +7 -0
  182. package/bundle/irc-config-55YO6EGB.js +88 -0
  183. package/bundle/irc-config-55YO6EGB.js.map +7 -0
  184. package/bundle/logs-ZNYXX5PA.js +19 -0
  185. package/bundle/logs-ZNYXX5PA.js.map +7 -0
  186. package/bundle/media-utils-XNNDTYFI.js +4662 -0
  187. package/bundle/media-utils-XNNDTYFI.js.map +7 -0
  188. package/bundle/message-pipeline-LLH5SYMO.js +33 -0
  189. package/bundle/message-pipeline-LLH5SYMO.js.map +7 -0
  190. package/bundle/meta.json +41304 -0
  191. package/bundle/model-health-registry-35LQNVQR.js +11 -0
  192. package/bundle/model-health-registry-35LQNVQR.js.map +7 -0
  193. package/bundle/notification-Y5S5MMLV.js +13 -0
  194. package/bundle/notification-Y5S5MMLV.js.map +7 -0
  195. package/bundle/openrouter-credits-EDY7ETAU.js +32 -0
  196. package/bundle/openrouter-credits-EDY7ETAU.js.map +7 -0
  197. package/bundle/passwd-RRFV4CC5.js +133 -0
  198. package/bundle/passwd-RRFV4CC5.js.map +7 -0
  199. package/bundle/paths-G33RZWZ7.js +17 -0
  200. package/bundle/paths-G33RZWZ7.js.map +7 -0
  201. package/bundle/peer-client-52XYMNI7.js +156 -0
  202. package/bundle/peer-client-52XYMNI7.js.map +7 -0
  203. package/bundle/peer-config-VK6EDLN5.js +16 -0
  204. package/bundle/peer-config-VK6EDLN5.js.map +7 -0
  205. package/bundle/peer-sessions-EAXTNQ36.js +49 -0
  206. package/bundle/peer-sessions-EAXTNQ36.js.map +7 -0
  207. package/bundle/pending-callback-RIMQZ7FJ.js +40 -0
  208. package/bundle/pending-callback-RIMQZ7FJ.js.map +7 -0
  209. package/bundle/phase-transport-KYERDL2O.js +22 -0
  210. package/bundle/phase-transport-KYERDL2O.js.map +7 -0
  211. package/bundle/public/css/dashboard.css +542 -0
  212. package/bundle/public/index.html +180 -0
  213. package/bundle/public/js/app.js +437 -0
  214. package/bundle/public/memory-universe.js +384 -0
  215. package/bundle/responses-adapter-AAQTY3K4.js +30 -0
  216. package/bundle/responses-adapter-AAQTY3K4.js.map +7 -0
  217. package/bundle/restore-ZE3SEPSS.js +46 -0
  218. package/bundle/restore-ZE3SEPSS.js.map +7 -0
  219. package/bundle/self-healer-utils-DMUUXC47.js +43 -0
  220. package/bundle/self-healer-utils-DMUUXC47.js.map +7 -0
  221. package/bundle/skill-stats-LLEXEXLR.js +22 -0
  222. package/bundle/skill-stats-LLEXEXLR.js.map +7 -0
  223. package/bundle/sleep-OYIUOVQD.js +19 -0
  224. package/bundle/sleep-OYIUOVQD.js.map +7 -0
  225. package/bundle/soul-loader-54WCVNLJ.js +16 -0
  226. package/bundle/soul-loader-54WCVNLJ.js.map +7 -0
  227. package/bundle/src-JL4PVO23.js +8 -0
  228. package/bundle/src-JL4PVO23.js.map +7 -0
  229. package/bundle/sse-parser-anthropic-P7CE2MH2.js +72 -0
  230. package/bundle/sse-parser-anthropic-P7CE2MH2.js.map +7 -0
  231. package/bundle/sse-parser-responses-EQQA5FWN.js +63 -0
  232. package/bundle/sse-parser-responses-EQQA5FWN.js.map +7 -0
  233. package/bundle/ssrf-guard-FZCBYIVW.js +64 -0
  234. package/bundle/ssrf-guard-FZCBYIVW.js.map +7 -0
  235. package/bundle/start-FH3GRMJ4.js +35 -0
  236. package/bundle/start-FH3GRMJ4.js.map +7 -0
  237. package/bundle/stream-single-WSG4D53C.js +33 -0
  238. package/bundle/stream-single-WSG4D53C.js.map +7 -0
  239. package/bundle/stt-2UH3RITX.js +14 -0
  240. package/bundle/stt-2UH3RITX.js.map +7 -0
  241. package/bundle/subagent-runtime-LE2ZXH3G.js +12 -0
  242. package/bundle/subagent-runtime-LE2ZXH3G.js.map +7 -0
  243. package/bundle/system-message-T5R3EYYN.js +30 -0
  244. package/bundle/system-message-T5R3EYYN.js.map +7 -0
  245. package/bundle/system-status-KQ6KHFJ6.js +189 -0
  246. package/bundle/system-status-KQ6KHFJ6.js.map +7 -0
  247. package/bundle/task-store-K7CQDEPI.js +22 -0
  248. package/bundle/task-store-K7CQDEPI.js.map +7 -0
  249. package/bundle/telegram-adapter-2V3XUMT5.js +1060 -0
  250. package/bundle/telegram-adapter-2V3XUMT5.js.map +7 -0
  251. package/bundle/tool-registry-MU3OX4UI.js +38 -0
  252. package/bundle/tool-registry-MU3OX4UI.js.map +7 -0
  253. package/bundle/tool-sandbox-VYOK4ZOA.js +20 -0
  254. package/bundle/tool-sandbox-VYOK4ZOA.js.map +7 -0
  255. package/bundle/transport-config-YLXU33RO.js +57 -0
  256. package/bundle/transport-config-YLXU33RO.js.map +7 -0
  257. package/bundle/update-QCW5LXRN.js +13 -0
  258. package/bundle/update-QCW5LXRN.js.map +7 -0
  259. package/bundle/update-check-27KZSAP6.js +12 -0
  260. package/bundle/update-check-27KZSAP6.js.map +7 -0
  261. package/bundle/usage-tracker-OVVEVMOY.js +17 -0
  262. package/bundle/usage-tracker-OVVEVMOY.js.map +7 -0
  263. package/bundle/user-registry-D4SD73UV.js +16 -0
  264. package/bundle/user-registry-D4SD73UV.js.map +7 -0
  265. package/core/professor.json +14 -0
  266. package/core/prompts/browsing_prompt.md +39 -0
  267. package/core/prompts/compaction.md +32 -0
  268. package/core/skills/memory/classification/SKILL.md +37 -0
  269. package/core/skills/memory/memory-anomalies/SKILL.md +39 -0
  270. package/core/skills/memory/memory-search/SKILL.md +48 -0
  271. package/core/skills/memory/topic-save/SKILL.md +44 -0
  272. package/core/skills/ops/cron/SKILL.md +51 -0
  273. package/core/skills/ops/gdrive-backup/SKILL.md +15 -0
  274. package/core/skills/ops/session-start/SKILL.md +11 -0
  275. package/core/skills/ops/skill-authoring/SKILL.md +54 -0
  276. package/core/skills/ops/system-health/SKILL.md +104 -0
  277. package/core/skills/ops/troubleshooting/SKILL.md +48 -0
  278. package/core/skills/ops/trust-gating/SKILL.md +30 -0
  279. package/core/skills/tools/a2a-communication/SKILL.md +68 -0
  280. package/core/skills/tools/browse-delegate/SKILL.md +27 -0
  281. package/core/skills/tools/browser/SKILL.md +36 -0
  282. package/core/skills/tools/clawhub/SKILL.md +44 -0
  283. package/core/skills/tools/delegation/SKILL.md +48 -0
  284. package/core/skills/tools/fxtwitter/SKILL.md +52 -0
  285. package/core/skills/tools/gmail/SKILL.md +44 -0
  286. package/core/skills/tools/irc-chat/SKILL.md +84 -0
  287. package/core/skills/tools/linear/SKILL.md +90 -0
  288. package/core/skills/tools/mcporter/SKILL.md +46 -0
  289. package/core/skills/tools/model-scout/SKILL.md +132 -0
  290. package/core/skills/tools/model-scout/scout-add-model.py +67 -0
  291. package/core/skills/tools/model-scout/scout-ollama.py +116 -0
  292. package/core/skills/tools/model-scout/scout-openrouter.py +85 -0
  293. package/core/skills/tools/nlm/SKILL.md +40 -0
  294. package/core/skills/tools/todo/SKILL.md +30 -0
  295. package/core/skills/tools/twitterX/SKILL.md +52 -0
  296. package/core/skills/tools/twitterX/scripts/abtars-tweet.js +532 -0
  297. package/core/skills/tools/twitterX/scripts/package.json +1 -0
  298. package/core/skills/tools/web-fetch/SKILL.md +29 -0
  299. package/package.json +59 -0
  300. package/scripts/abtars-daemon.service +23 -0
  301. package/scripts/abtars-fetch.sh +42 -0
  302. package/scripts/abtars-watchdog.service +13 -0
  303. package/scripts/abtars.sh +14 -0
  304. package/scripts/abtars@.service +21 -0
  305. package/scripts/browser-patchright.sh +79 -0
  306. package/scripts/com.abtars.daemon.plist +24 -0
  307. package/scripts/com.abtars.watchdog.plist +27 -0
  308. package/scripts/daily-backup.sh +62 -0
  309. package/scripts/doctor.sh +553 -0
  310. package/scripts/hooks/audit-logger.sh +22 -0
  311. package/scripts/upgrade-deps.sh +64 -0
  312. package/scripts/watchdog.sh +309 -0
@@ -0,0 +1,4662 @@
1
+ import { createRequire as __bundleCreateRequire } from 'node:module'; import { fileURLToPath as __bundleFileURLToPath } from 'node:url'; import { dirname as __bundleDirname } from 'node:path'; const require = __bundleCreateRequire(import.meta.url); const __chunk_filename = __bundleFileURLToPath(import.meta.url); const __chunk_dirname = __bundleDirname(__chunk_filename);
2
+ import {
3
+ require_ieee754
4
+ } from "./chunk-PNEDC45Y.js";
5
+ import {
6
+ init_logger,
7
+ logInfo,
8
+ logWarn
9
+ } from "./chunk-BUUVFUPO.js";
10
+ import {
11
+ abtarsHome,
12
+ init_paths
13
+ } from "./chunk-X76UX47U.js";
14
+ import {
15
+ __commonJS,
16
+ __require,
17
+ __toESM
18
+ } from "./chunk-NWDBD4PA.js";
19
+
20
+ // node_modules/ms/index.js
21
+ var require_ms = __commonJS({
22
+ "node_modules/ms/index.js"(exports, module) {
23
+ var s = 1e3;
24
+ var m = s * 60;
25
+ var h = m * 60;
26
+ var d = h * 24;
27
+ var w = d * 7;
28
+ var y = d * 365.25;
29
+ module.exports = function(val, options) {
30
+ options = options || {};
31
+ var type = typeof val;
32
+ if (type === "string" && val.length > 0) {
33
+ return parse(val);
34
+ } else if (type === "number" && isFinite(val)) {
35
+ return options.long ? fmtLong(val) : fmtShort(val);
36
+ }
37
+ throw new Error(
38
+ "val is not a non-empty string or a valid number. val=" + JSON.stringify(val)
39
+ );
40
+ };
41
+ function parse(str) {
42
+ str = String(str);
43
+ if (str.length > 100) {
44
+ return;
45
+ }
46
+ var match = /^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(
47
+ str
48
+ );
49
+ if (!match) {
50
+ return;
51
+ }
52
+ var n = parseFloat(match[1]);
53
+ var type = (match[2] || "ms").toLowerCase();
54
+ switch (type) {
55
+ case "years":
56
+ case "year":
57
+ case "yrs":
58
+ case "yr":
59
+ case "y":
60
+ return n * y;
61
+ case "weeks":
62
+ case "week":
63
+ case "w":
64
+ return n * w;
65
+ case "days":
66
+ case "day":
67
+ case "d":
68
+ return n * d;
69
+ case "hours":
70
+ case "hour":
71
+ case "hrs":
72
+ case "hr":
73
+ case "h":
74
+ return n * h;
75
+ case "minutes":
76
+ case "minute":
77
+ case "mins":
78
+ case "min":
79
+ case "m":
80
+ return n * m;
81
+ case "seconds":
82
+ case "second":
83
+ case "secs":
84
+ case "sec":
85
+ case "s":
86
+ return n * s;
87
+ case "milliseconds":
88
+ case "millisecond":
89
+ case "msecs":
90
+ case "msec":
91
+ case "ms":
92
+ return n;
93
+ default:
94
+ return void 0;
95
+ }
96
+ }
97
+ function fmtShort(ms) {
98
+ var msAbs = Math.abs(ms);
99
+ if (msAbs >= d) {
100
+ return Math.round(ms / d) + "d";
101
+ }
102
+ if (msAbs >= h) {
103
+ return Math.round(ms / h) + "h";
104
+ }
105
+ if (msAbs >= m) {
106
+ return Math.round(ms / m) + "m";
107
+ }
108
+ if (msAbs >= s) {
109
+ return Math.round(ms / s) + "s";
110
+ }
111
+ return ms + "ms";
112
+ }
113
+ function fmtLong(ms) {
114
+ var msAbs = Math.abs(ms);
115
+ if (msAbs >= d) {
116
+ return plural(ms, msAbs, d, "day");
117
+ }
118
+ if (msAbs >= h) {
119
+ return plural(ms, msAbs, h, "hour");
120
+ }
121
+ if (msAbs >= m) {
122
+ return plural(ms, msAbs, m, "minute");
123
+ }
124
+ if (msAbs >= s) {
125
+ return plural(ms, msAbs, s, "second");
126
+ }
127
+ return ms + " ms";
128
+ }
129
+ function plural(ms, msAbs, n, name) {
130
+ var isPlural = msAbs >= n * 1.5;
131
+ return Math.round(ms / n) + " " + name + (isPlural ? "s" : "");
132
+ }
133
+ }
134
+ });
135
+
136
+ // node_modules/debug/src/common.js
137
+ var require_common = __commonJS({
138
+ "node_modules/debug/src/common.js"(exports, module) {
139
+ function setup(env) {
140
+ createDebug.debug = createDebug;
141
+ createDebug.default = createDebug;
142
+ createDebug.coerce = coerce;
143
+ createDebug.disable = disable;
144
+ createDebug.enable = enable;
145
+ createDebug.enabled = enabled;
146
+ createDebug.humanize = require_ms();
147
+ createDebug.destroy = destroy;
148
+ Object.keys(env).forEach((key) => {
149
+ createDebug[key] = env[key];
150
+ });
151
+ createDebug.names = [];
152
+ createDebug.skips = [];
153
+ createDebug.formatters = {};
154
+ function selectColor(namespace) {
155
+ let hash = 0;
156
+ for (let i = 0; i < namespace.length; i++) {
157
+ hash = (hash << 5) - hash + namespace.charCodeAt(i);
158
+ hash |= 0;
159
+ }
160
+ return createDebug.colors[Math.abs(hash) % createDebug.colors.length];
161
+ }
162
+ createDebug.selectColor = selectColor;
163
+ function createDebug(namespace) {
164
+ let prevTime;
165
+ let enableOverride = null;
166
+ let namespacesCache;
167
+ let enabledCache;
168
+ function debug2(...args) {
169
+ if (!debug2.enabled) {
170
+ return;
171
+ }
172
+ const self = debug2;
173
+ const curr = Number(/* @__PURE__ */ new Date());
174
+ const ms = curr - (prevTime || curr);
175
+ self.diff = ms;
176
+ self.prev = prevTime;
177
+ self.curr = curr;
178
+ prevTime = curr;
179
+ args[0] = createDebug.coerce(args[0]);
180
+ if (typeof args[0] !== "string") {
181
+ args.unshift("%O");
182
+ }
183
+ let index = 0;
184
+ args[0] = args[0].replace(/%([a-zA-Z%])/g, (match, format) => {
185
+ if (match === "%%") {
186
+ return "%";
187
+ }
188
+ index++;
189
+ const formatter = createDebug.formatters[format];
190
+ if (typeof formatter === "function") {
191
+ const val = args[index];
192
+ match = formatter.call(self, val);
193
+ args.splice(index, 1);
194
+ index--;
195
+ }
196
+ return match;
197
+ });
198
+ createDebug.formatArgs.call(self, args);
199
+ const logFn = self.log || createDebug.log;
200
+ logFn.apply(self, args);
201
+ }
202
+ debug2.namespace = namespace;
203
+ debug2.useColors = createDebug.useColors();
204
+ debug2.color = createDebug.selectColor(namespace);
205
+ debug2.extend = extend;
206
+ debug2.destroy = createDebug.destroy;
207
+ Object.defineProperty(debug2, "enabled", {
208
+ enumerable: true,
209
+ configurable: false,
210
+ get: () => {
211
+ if (enableOverride !== null) {
212
+ return enableOverride;
213
+ }
214
+ if (namespacesCache !== createDebug.namespaces) {
215
+ namespacesCache = createDebug.namespaces;
216
+ enabledCache = createDebug.enabled(namespace);
217
+ }
218
+ return enabledCache;
219
+ },
220
+ set: (v) => {
221
+ enableOverride = v;
222
+ }
223
+ });
224
+ if (typeof createDebug.init === "function") {
225
+ createDebug.init(debug2);
226
+ }
227
+ return debug2;
228
+ }
229
+ function extend(namespace, delimiter) {
230
+ const newDebug = createDebug(this.namespace + (typeof delimiter === "undefined" ? ":" : delimiter) + namespace);
231
+ newDebug.log = this.log;
232
+ return newDebug;
233
+ }
234
+ function enable(namespaces) {
235
+ createDebug.save(namespaces);
236
+ createDebug.namespaces = namespaces;
237
+ createDebug.names = [];
238
+ createDebug.skips = [];
239
+ const split = (typeof namespaces === "string" ? namespaces : "").trim().replace(/\s+/g, ",").split(",").filter(Boolean);
240
+ for (const ns of split) {
241
+ if (ns[0] === "-") {
242
+ createDebug.skips.push(ns.slice(1));
243
+ } else {
244
+ createDebug.names.push(ns);
245
+ }
246
+ }
247
+ }
248
+ function matchesTemplate(search, template) {
249
+ let searchIndex = 0;
250
+ let templateIndex = 0;
251
+ let starIndex = -1;
252
+ let matchIndex = 0;
253
+ while (searchIndex < search.length) {
254
+ if (templateIndex < template.length && (template[templateIndex] === search[searchIndex] || template[templateIndex] === "*")) {
255
+ if (template[templateIndex] === "*") {
256
+ starIndex = templateIndex;
257
+ matchIndex = searchIndex;
258
+ templateIndex++;
259
+ } else {
260
+ searchIndex++;
261
+ templateIndex++;
262
+ }
263
+ } else if (starIndex !== -1) {
264
+ templateIndex = starIndex + 1;
265
+ matchIndex++;
266
+ searchIndex = matchIndex;
267
+ } else {
268
+ return false;
269
+ }
270
+ }
271
+ while (templateIndex < template.length && template[templateIndex] === "*") {
272
+ templateIndex++;
273
+ }
274
+ return templateIndex === template.length;
275
+ }
276
+ function disable() {
277
+ const namespaces = [
278
+ ...createDebug.names,
279
+ ...createDebug.skips.map((namespace) => "-" + namespace)
280
+ ].join(",");
281
+ createDebug.enable("");
282
+ return namespaces;
283
+ }
284
+ function enabled(name) {
285
+ for (const skip of createDebug.skips) {
286
+ if (matchesTemplate(name, skip)) {
287
+ return false;
288
+ }
289
+ }
290
+ for (const ns of createDebug.names) {
291
+ if (matchesTemplate(name, ns)) {
292
+ return true;
293
+ }
294
+ }
295
+ return false;
296
+ }
297
+ function coerce(val) {
298
+ if (val instanceof Error) {
299
+ return val.stack || val.message;
300
+ }
301
+ return val;
302
+ }
303
+ function destroy() {
304
+ console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.");
305
+ }
306
+ createDebug.enable(createDebug.load());
307
+ return createDebug;
308
+ }
309
+ module.exports = setup;
310
+ }
311
+ });
312
+
313
+ // node_modules/debug/src/browser.js
314
+ var require_browser = __commonJS({
315
+ "node_modules/debug/src/browser.js"(exports, module) {
316
+ exports.formatArgs = formatArgs;
317
+ exports.save = save;
318
+ exports.load = load;
319
+ exports.useColors = useColors;
320
+ exports.storage = localstorage();
321
+ exports.destroy = /* @__PURE__ */ (() => {
322
+ let warned = false;
323
+ return () => {
324
+ if (!warned) {
325
+ warned = true;
326
+ console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.");
327
+ }
328
+ };
329
+ })();
330
+ exports.colors = [
331
+ "#0000CC",
332
+ "#0000FF",
333
+ "#0033CC",
334
+ "#0033FF",
335
+ "#0066CC",
336
+ "#0066FF",
337
+ "#0099CC",
338
+ "#0099FF",
339
+ "#00CC00",
340
+ "#00CC33",
341
+ "#00CC66",
342
+ "#00CC99",
343
+ "#00CCCC",
344
+ "#00CCFF",
345
+ "#3300CC",
346
+ "#3300FF",
347
+ "#3333CC",
348
+ "#3333FF",
349
+ "#3366CC",
350
+ "#3366FF",
351
+ "#3399CC",
352
+ "#3399FF",
353
+ "#33CC00",
354
+ "#33CC33",
355
+ "#33CC66",
356
+ "#33CC99",
357
+ "#33CCCC",
358
+ "#33CCFF",
359
+ "#6600CC",
360
+ "#6600FF",
361
+ "#6633CC",
362
+ "#6633FF",
363
+ "#66CC00",
364
+ "#66CC33",
365
+ "#9900CC",
366
+ "#9900FF",
367
+ "#9933CC",
368
+ "#9933FF",
369
+ "#99CC00",
370
+ "#99CC33",
371
+ "#CC0000",
372
+ "#CC0033",
373
+ "#CC0066",
374
+ "#CC0099",
375
+ "#CC00CC",
376
+ "#CC00FF",
377
+ "#CC3300",
378
+ "#CC3333",
379
+ "#CC3366",
380
+ "#CC3399",
381
+ "#CC33CC",
382
+ "#CC33FF",
383
+ "#CC6600",
384
+ "#CC6633",
385
+ "#CC9900",
386
+ "#CC9933",
387
+ "#CCCC00",
388
+ "#CCCC33",
389
+ "#FF0000",
390
+ "#FF0033",
391
+ "#FF0066",
392
+ "#FF0099",
393
+ "#FF00CC",
394
+ "#FF00FF",
395
+ "#FF3300",
396
+ "#FF3333",
397
+ "#FF3366",
398
+ "#FF3399",
399
+ "#FF33CC",
400
+ "#FF33FF",
401
+ "#FF6600",
402
+ "#FF6633",
403
+ "#FF9900",
404
+ "#FF9933",
405
+ "#FFCC00",
406
+ "#FFCC33"
407
+ ];
408
+ function useColors() {
409
+ if (typeof window !== "undefined" && window.process && (window.process.type === "renderer" || window.process.__nwjs)) {
410
+ return true;
411
+ }
412
+ if (typeof navigator !== "undefined" && navigator.userAgent && navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)) {
413
+ return false;
414
+ }
415
+ let m;
416
+ return typeof document !== "undefined" && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance || // Is firebug? http://stackoverflow.com/a/398120/376773
417
+ typeof window !== "undefined" && window.console && (window.console.firebug || window.console.exception && window.console.table) || // Is firefox >= v31?
418
+ // https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages
419
+ typeof navigator !== "undefined" && navigator.userAgent && (m = navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)) && parseInt(m[1], 10) >= 31 || // Double check webkit in userAgent just in case we are in a worker
420
+ typeof navigator !== "undefined" && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/);
421
+ }
422
+ function formatArgs(args) {
423
+ args[0] = (this.useColors ? "%c" : "") + this.namespace + (this.useColors ? " %c" : " ") + args[0] + (this.useColors ? "%c " : " ") + "+" + module.exports.humanize(this.diff);
424
+ if (!this.useColors) {
425
+ return;
426
+ }
427
+ const c = "color: " + this.color;
428
+ args.splice(1, 0, c, "color: inherit");
429
+ let index = 0;
430
+ let lastC = 0;
431
+ args[0].replace(/%[a-zA-Z%]/g, (match) => {
432
+ if (match === "%%") {
433
+ return;
434
+ }
435
+ index++;
436
+ if (match === "%c") {
437
+ lastC = index;
438
+ }
439
+ });
440
+ args.splice(lastC, 0, c);
441
+ }
442
+ exports.log = console.debug || console.log || (() => {
443
+ });
444
+ function save(namespaces) {
445
+ try {
446
+ if (namespaces) {
447
+ exports.storage.setItem("debug", namespaces);
448
+ } else {
449
+ exports.storage.removeItem("debug");
450
+ }
451
+ } catch (error) {
452
+ }
453
+ }
454
+ function load() {
455
+ let r;
456
+ try {
457
+ r = exports.storage.getItem("debug") || exports.storage.getItem("DEBUG");
458
+ } catch (error) {
459
+ }
460
+ if (!r && typeof process !== "undefined" && "env" in process) {
461
+ r = process.env.DEBUG;
462
+ }
463
+ return r;
464
+ }
465
+ function localstorage() {
466
+ try {
467
+ return localStorage;
468
+ } catch (error) {
469
+ }
470
+ }
471
+ module.exports = require_common()(exports);
472
+ var { formatters } = module.exports;
473
+ formatters.j = function(v) {
474
+ try {
475
+ return JSON.stringify(v);
476
+ } catch (error) {
477
+ return "[UnexpectedJSONParseError]: " + error.message;
478
+ }
479
+ };
480
+ }
481
+ });
482
+
483
+ // node_modules/debug/src/node.js
484
+ var require_node = __commonJS({
485
+ "node_modules/debug/src/node.js"(exports, module) {
486
+ var tty = __require("tty");
487
+ var util = __require("util");
488
+ exports.init = init;
489
+ exports.log = log;
490
+ exports.formatArgs = formatArgs;
491
+ exports.save = save;
492
+ exports.load = load;
493
+ exports.useColors = useColors;
494
+ exports.destroy = util.deprecate(
495
+ () => {
496
+ },
497
+ "Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."
498
+ );
499
+ exports.colors = [6, 2, 3, 4, 5, 1];
500
+ try {
501
+ const supportsColor = __require("supports-color");
502
+ if (supportsColor && (supportsColor.stderr || supportsColor).level >= 2) {
503
+ exports.colors = [
504
+ 20,
505
+ 21,
506
+ 26,
507
+ 27,
508
+ 32,
509
+ 33,
510
+ 38,
511
+ 39,
512
+ 40,
513
+ 41,
514
+ 42,
515
+ 43,
516
+ 44,
517
+ 45,
518
+ 56,
519
+ 57,
520
+ 62,
521
+ 63,
522
+ 68,
523
+ 69,
524
+ 74,
525
+ 75,
526
+ 76,
527
+ 77,
528
+ 78,
529
+ 79,
530
+ 80,
531
+ 81,
532
+ 92,
533
+ 93,
534
+ 98,
535
+ 99,
536
+ 112,
537
+ 113,
538
+ 128,
539
+ 129,
540
+ 134,
541
+ 135,
542
+ 148,
543
+ 149,
544
+ 160,
545
+ 161,
546
+ 162,
547
+ 163,
548
+ 164,
549
+ 165,
550
+ 166,
551
+ 167,
552
+ 168,
553
+ 169,
554
+ 170,
555
+ 171,
556
+ 172,
557
+ 173,
558
+ 178,
559
+ 179,
560
+ 184,
561
+ 185,
562
+ 196,
563
+ 197,
564
+ 198,
565
+ 199,
566
+ 200,
567
+ 201,
568
+ 202,
569
+ 203,
570
+ 204,
571
+ 205,
572
+ 206,
573
+ 207,
574
+ 208,
575
+ 209,
576
+ 214,
577
+ 215,
578
+ 220,
579
+ 221
580
+ ];
581
+ }
582
+ } catch (error) {
583
+ }
584
+ exports.inspectOpts = Object.keys(process.env).filter((key) => {
585
+ return /^debug_/i.test(key);
586
+ }).reduce((obj, key) => {
587
+ const prop = key.substring(6).toLowerCase().replace(/_([a-z])/g, (_, k) => {
588
+ return k.toUpperCase();
589
+ });
590
+ let val = process.env[key];
591
+ if (/^(yes|on|true|enabled)$/i.test(val)) {
592
+ val = true;
593
+ } else if (/^(no|off|false|disabled)$/i.test(val)) {
594
+ val = false;
595
+ } else if (val === "null") {
596
+ val = null;
597
+ } else {
598
+ val = Number(val);
599
+ }
600
+ obj[prop] = val;
601
+ return obj;
602
+ }, {});
603
+ function useColors() {
604
+ return "colors" in exports.inspectOpts ? Boolean(exports.inspectOpts.colors) : tty.isatty(process.stderr.fd);
605
+ }
606
+ function formatArgs(args) {
607
+ const { namespace: name, useColors: useColors2 } = this;
608
+ if (useColors2) {
609
+ const c = this.color;
610
+ const colorCode = "\x1B[3" + (c < 8 ? c : "8;5;" + c);
611
+ const prefix = ` ${colorCode};1m${name} \x1B[0m`;
612
+ args[0] = prefix + args[0].split("\n").join("\n" + prefix);
613
+ args.push(colorCode + "m+" + module.exports.humanize(this.diff) + "\x1B[0m");
614
+ } else {
615
+ args[0] = getDate() + name + " " + args[0];
616
+ }
617
+ }
618
+ function getDate() {
619
+ if (exports.inspectOpts.hideDate) {
620
+ return "";
621
+ }
622
+ return (/* @__PURE__ */ new Date()).toISOString() + " ";
623
+ }
624
+ function log(...args) {
625
+ return process.stderr.write(util.formatWithOptions(exports.inspectOpts, ...args) + "\n");
626
+ }
627
+ function save(namespaces) {
628
+ if (namespaces) {
629
+ process.env.DEBUG = namespaces;
630
+ } else {
631
+ delete process.env.DEBUG;
632
+ }
633
+ }
634
+ function load() {
635
+ return process.env.DEBUG;
636
+ }
637
+ function init(debug2) {
638
+ debug2.inspectOpts = {};
639
+ const keys = Object.keys(exports.inspectOpts);
640
+ for (let i = 0; i < keys.length; i++) {
641
+ debug2.inspectOpts[keys[i]] = exports.inspectOpts[keys[i]];
642
+ }
643
+ }
644
+ module.exports = require_common()(exports);
645
+ var { formatters } = module.exports;
646
+ formatters.o = function(v) {
647
+ this.inspectOpts.colors = this.useColors;
648
+ return util.inspect(v, this.inspectOpts).split("\n").map((str) => str.trim()).join(" ");
649
+ };
650
+ formatters.O = function(v) {
651
+ this.inspectOpts.colors = this.useColors;
652
+ return util.inspect(v, this.inspectOpts);
653
+ };
654
+ }
655
+ });
656
+
657
+ // node_modules/debug/src/index.js
658
+ var require_src = __commonJS({
659
+ "node_modules/debug/src/index.js"(exports, module) {
660
+ if (typeof process === "undefined" || process.type === "renderer" || process.browser === true || process.__nwjs) {
661
+ module.exports = require_browser();
662
+ } else {
663
+ module.exports = require_node();
664
+ }
665
+ }
666
+ });
667
+
668
+ // src/components/media-utils.ts
669
+ init_paths();
670
+ import { existsSync, mkdirSync, writeFileSync, readdirSync, statSync, unlinkSync } from "node:fs";
671
+ import { join } from "node:path";
672
+ import { randomBytes } from "node:crypto";
673
+
674
+ // node_modules/token-types/lib/index.js
675
+ var ieee754 = __toESM(require_ieee754(), 1);
676
+
677
+ // node_modules/@borewit/text-codec/lib/index.js
678
+ var WINDOWS_1252_EXTRA = {
679
+ 128: "\u20AC",
680
+ 130: "\u201A",
681
+ 131: "\u0192",
682
+ 132: "\u201E",
683
+ 133: "\u2026",
684
+ 134: "\u2020",
685
+ 135: "\u2021",
686
+ 136: "\u02C6",
687
+ 137: "\u2030",
688
+ 138: "\u0160",
689
+ 139: "\u2039",
690
+ 140: "\u0152",
691
+ 142: "\u017D",
692
+ 145: "\u2018",
693
+ 146: "\u2019",
694
+ 147: "\u201C",
695
+ 148: "\u201D",
696
+ 149: "\u2022",
697
+ 150: "\u2013",
698
+ 151: "\u2014",
699
+ 152: "\u02DC",
700
+ 153: "\u2122",
701
+ 154: "\u0161",
702
+ 155: "\u203A",
703
+ 156: "\u0153",
704
+ 158: "\u017E",
705
+ 159: "\u0178"
706
+ };
707
+ var WINDOWS_1252_REVERSE = {};
708
+ for (const [code, char] of Object.entries(WINDOWS_1252_EXTRA)) {
709
+ WINDOWS_1252_REVERSE[char] = Number.parseInt(code, 10);
710
+ }
711
+ var _utf8Decoder;
712
+ function utf8Decoder() {
713
+ if (typeof globalThis.TextDecoder === "undefined")
714
+ return void 0;
715
+ return _utf8Decoder !== null && _utf8Decoder !== void 0 ? _utf8Decoder : _utf8Decoder = new globalThis.TextDecoder("utf-8");
716
+ }
717
+ var CHUNK = 32 * 1024;
718
+ var REPLACEMENT = 65533;
719
+ function textDecode(bytes, encoding = "utf-8") {
720
+ switch (encoding.toLowerCase()) {
721
+ case "utf-8":
722
+ case "utf8": {
723
+ const dec = utf8Decoder();
724
+ return dec ? dec.decode(bytes) : decodeUTF8(bytes);
725
+ }
726
+ case "utf-16le":
727
+ return decodeUTF16LE(bytes);
728
+ case "us-ascii":
729
+ case "ascii":
730
+ return decodeASCII(bytes);
731
+ case "latin1":
732
+ case "iso-8859-1":
733
+ return decodeLatin1(bytes);
734
+ case "windows-1252":
735
+ return decodeWindows1252(bytes);
736
+ default:
737
+ throw new RangeError(`Encoding '${encoding}' not supported`);
738
+ }
739
+ }
740
+ function flushChunk(parts, chunk) {
741
+ if (chunk.length === 0)
742
+ return;
743
+ parts.push(String.fromCharCode.apply(null, chunk));
744
+ chunk.length = 0;
745
+ }
746
+ function pushCodeUnit(parts, chunk, codeUnit) {
747
+ chunk.push(codeUnit);
748
+ if (chunk.length >= CHUNK)
749
+ flushChunk(parts, chunk);
750
+ }
751
+ function pushCodePoint(parts, chunk, cp) {
752
+ if (cp <= 65535) {
753
+ pushCodeUnit(parts, chunk, cp);
754
+ return;
755
+ }
756
+ cp -= 65536;
757
+ pushCodeUnit(parts, chunk, 55296 + (cp >> 10));
758
+ pushCodeUnit(parts, chunk, 56320 + (cp & 1023));
759
+ }
760
+ function decodeUTF8(bytes) {
761
+ const parts = [];
762
+ const chunk = [];
763
+ let i = 0;
764
+ if (bytes.length >= 3 && bytes[0] === 239 && bytes[1] === 187 && bytes[2] === 191) {
765
+ i = 3;
766
+ }
767
+ while (i < bytes.length) {
768
+ const b1 = bytes[i];
769
+ if (b1 <= 127) {
770
+ pushCodeUnit(parts, chunk, b1);
771
+ i++;
772
+ continue;
773
+ }
774
+ if (b1 < 194 || b1 > 244) {
775
+ pushCodeUnit(parts, chunk, REPLACEMENT);
776
+ i++;
777
+ continue;
778
+ }
779
+ if (b1 <= 223) {
780
+ if (i + 1 >= bytes.length) {
781
+ pushCodeUnit(parts, chunk, REPLACEMENT);
782
+ i++;
783
+ continue;
784
+ }
785
+ const b22 = bytes[i + 1];
786
+ if ((b22 & 192) !== 128) {
787
+ pushCodeUnit(parts, chunk, REPLACEMENT);
788
+ i++;
789
+ continue;
790
+ }
791
+ const cp2 = (b1 & 31) << 6 | b22 & 63;
792
+ pushCodeUnit(parts, chunk, cp2);
793
+ i += 2;
794
+ continue;
795
+ }
796
+ if (b1 <= 239) {
797
+ if (i + 2 >= bytes.length) {
798
+ pushCodeUnit(parts, chunk, REPLACEMENT);
799
+ i++;
800
+ continue;
801
+ }
802
+ const b22 = bytes[i + 1];
803
+ const b32 = bytes[i + 2];
804
+ const valid2 = (b22 & 192) === 128 && (b32 & 192) === 128 && !(b1 === 224 && b22 < 160) && // overlong
805
+ !(b1 === 237 && b22 >= 160);
806
+ if (!valid2) {
807
+ pushCodeUnit(parts, chunk, REPLACEMENT);
808
+ i++;
809
+ continue;
810
+ }
811
+ const cp2 = (b1 & 15) << 12 | (b22 & 63) << 6 | b32 & 63;
812
+ pushCodeUnit(parts, chunk, cp2);
813
+ i += 3;
814
+ continue;
815
+ }
816
+ if (i + 3 >= bytes.length) {
817
+ pushCodeUnit(parts, chunk, REPLACEMENT);
818
+ i++;
819
+ continue;
820
+ }
821
+ const b2 = bytes[i + 1];
822
+ const b3 = bytes[i + 2];
823
+ const b4 = bytes[i + 3];
824
+ const valid = (b2 & 192) === 128 && (b3 & 192) === 128 && (b4 & 192) === 128 && !(b1 === 240 && b2 < 144) && // overlong
825
+ !(b1 === 244 && b2 > 143);
826
+ if (!valid) {
827
+ pushCodeUnit(parts, chunk, REPLACEMENT);
828
+ i++;
829
+ continue;
830
+ }
831
+ const cp = (b1 & 7) << 18 | (b2 & 63) << 12 | (b3 & 63) << 6 | b4 & 63;
832
+ pushCodePoint(parts, chunk, cp);
833
+ i += 4;
834
+ }
835
+ flushChunk(parts, chunk);
836
+ return parts.join("");
837
+ }
838
+ function decodeUTF16LE(bytes) {
839
+ const parts = [];
840
+ const chunk = [];
841
+ const len = bytes.length;
842
+ let i = 0;
843
+ while (i + 1 < len) {
844
+ const u1 = bytes[i] | bytes[i + 1] << 8;
845
+ i += 2;
846
+ if (u1 >= 55296 && u1 <= 56319) {
847
+ if (i + 1 < len) {
848
+ const u2 = bytes[i] | bytes[i + 1] << 8;
849
+ if (u2 >= 56320 && u2 <= 57343) {
850
+ pushCodeUnit(parts, chunk, u1);
851
+ pushCodeUnit(parts, chunk, u2);
852
+ i += 2;
853
+ } else {
854
+ pushCodeUnit(parts, chunk, REPLACEMENT);
855
+ }
856
+ } else {
857
+ pushCodeUnit(parts, chunk, REPLACEMENT);
858
+ }
859
+ continue;
860
+ }
861
+ if (u1 >= 56320 && u1 <= 57343) {
862
+ pushCodeUnit(parts, chunk, REPLACEMENT);
863
+ continue;
864
+ }
865
+ pushCodeUnit(parts, chunk, u1);
866
+ }
867
+ if (i < len) {
868
+ pushCodeUnit(parts, chunk, REPLACEMENT);
869
+ }
870
+ flushChunk(parts, chunk);
871
+ return parts.join("");
872
+ }
873
+ function decodeASCII(bytes) {
874
+ const parts = [];
875
+ for (let i = 0; i < bytes.length; i += CHUNK) {
876
+ const end = Math.min(bytes.length, i + CHUNK);
877
+ const codes = new Array(end - i);
878
+ for (let j = i, k = 0; j < end; j++, k++) {
879
+ codes[k] = bytes[j] & 127;
880
+ }
881
+ parts.push(String.fromCharCode.apply(null, codes));
882
+ }
883
+ return parts.join("");
884
+ }
885
+ function decodeLatin1(bytes) {
886
+ const parts = [];
887
+ for (let i = 0; i < bytes.length; i += CHUNK) {
888
+ const end = Math.min(bytes.length, i + CHUNK);
889
+ const codes = new Array(end - i);
890
+ for (let j = i, k = 0; j < end; j++, k++) {
891
+ codes[k] = bytes[j];
892
+ }
893
+ parts.push(String.fromCharCode.apply(null, codes));
894
+ }
895
+ return parts.join("");
896
+ }
897
+ function decodeWindows1252(bytes) {
898
+ const parts = [];
899
+ let out = "";
900
+ for (let i = 0; i < bytes.length; i++) {
901
+ const b = bytes[i];
902
+ const extra = b >= 128 && b <= 159 ? WINDOWS_1252_EXTRA[b] : void 0;
903
+ out += extra !== null && extra !== void 0 ? extra : String.fromCharCode(b);
904
+ if (out.length >= CHUNK) {
905
+ parts.push(out);
906
+ out = "";
907
+ }
908
+ }
909
+ if (out)
910
+ parts.push(out);
911
+ return parts.join("");
912
+ }
913
+
914
+ // node_modules/token-types/lib/index.js
915
+ function dv(array) {
916
+ return new DataView(array.buffer, array.byteOffset);
917
+ }
918
+ var UINT8 = {
919
+ len: 1,
920
+ get(array, offset) {
921
+ return dv(array).getUint8(offset);
922
+ },
923
+ put(array, offset, value) {
924
+ dv(array).setUint8(offset, value);
925
+ return offset + 1;
926
+ }
927
+ };
928
+ var UINT16_LE = {
929
+ len: 2,
930
+ get(array, offset) {
931
+ return dv(array).getUint16(offset, true);
932
+ },
933
+ put(array, offset, value) {
934
+ dv(array).setUint16(offset, value, true);
935
+ return offset + 2;
936
+ }
937
+ };
938
+ var UINT16_BE = {
939
+ len: 2,
940
+ get(array, offset) {
941
+ return dv(array).getUint16(offset);
942
+ },
943
+ put(array, offset, value) {
944
+ dv(array).setUint16(offset, value);
945
+ return offset + 2;
946
+ }
947
+ };
948
+ var UINT32_LE = {
949
+ len: 4,
950
+ get(array, offset) {
951
+ return dv(array).getUint32(offset, true);
952
+ },
953
+ put(array, offset, value) {
954
+ dv(array).setUint32(offset, value, true);
955
+ return offset + 4;
956
+ }
957
+ };
958
+ var UINT32_BE = {
959
+ len: 4,
960
+ get(array, offset) {
961
+ return dv(array).getUint32(offset);
962
+ },
963
+ put(array, offset, value) {
964
+ dv(array).setUint32(offset, value);
965
+ return offset + 4;
966
+ }
967
+ };
968
+ var INT32_BE = {
969
+ len: 4,
970
+ get(array, offset) {
971
+ return dv(array).getInt32(offset);
972
+ },
973
+ put(array, offset, value) {
974
+ dv(array).setInt32(offset, value);
975
+ return offset + 4;
976
+ }
977
+ };
978
+ var UINT64_LE = {
979
+ len: 8,
980
+ get(array, offset) {
981
+ return dv(array).getBigUint64(offset, true);
982
+ },
983
+ put(array, offset, value) {
984
+ dv(array).setBigUint64(offset, value, true);
985
+ return offset + 8;
986
+ }
987
+ };
988
+ var StringType = class {
989
+ constructor(len, encoding) {
990
+ this.len = len;
991
+ this.encoding = encoding;
992
+ }
993
+ get(data, offset = 0) {
994
+ const bytes = data.subarray(offset, offset + this.len);
995
+ return textDecode(bytes, this.encoding);
996
+ }
997
+ };
998
+
999
+ // node_modules/strtok3/lib/stream/Errors.js
1000
+ var defaultMessages = "End-Of-Stream";
1001
+ var EndOfStreamError = class extends Error {
1002
+ constructor() {
1003
+ super(defaultMessages);
1004
+ this.name = "EndOfStreamError";
1005
+ }
1006
+ };
1007
+ var AbortError = class extends Error {
1008
+ constructor(message = "The operation was aborted") {
1009
+ super(message);
1010
+ this.name = "AbortError";
1011
+ }
1012
+ };
1013
+
1014
+ // node_modules/strtok3/lib/stream/AbstractStreamReader.js
1015
+ var AbstractStreamReader = class {
1016
+ constructor() {
1017
+ this.endOfStream = false;
1018
+ this.interrupted = false;
1019
+ this.peekQueue = [];
1020
+ }
1021
+ async peek(uint8Array, mayBeLess = false) {
1022
+ const bytesRead = await this.read(uint8Array, mayBeLess);
1023
+ this.peekQueue.push(uint8Array.subarray(0, bytesRead));
1024
+ return bytesRead;
1025
+ }
1026
+ async read(buffer, mayBeLess = false) {
1027
+ if (buffer.length === 0) {
1028
+ return 0;
1029
+ }
1030
+ let bytesRead = this.readFromPeekBuffer(buffer);
1031
+ if (!this.endOfStream) {
1032
+ bytesRead += await this.readRemainderFromStream(buffer.subarray(bytesRead), mayBeLess);
1033
+ }
1034
+ if (bytesRead === 0 && !mayBeLess) {
1035
+ throw new EndOfStreamError();
1036
+ }
1037
+ return bytesRead;
1038
+ }
1039
+ /**
1040
+ * Read chunk from stream
1041
+ * @param buffer - Target Uint8Array (or Buffer) to store data read from stream in
1042
+ * @returns Number of bytes read
1043
+ */
1044
+ readFromPeekBuffer(buffer) {
1045
+ let remaining = buffer.length;
1046
+ let bytesRead = 0;
1047
+ while (this.peekQueue.length > 0 && remaining > 0) {
1048
+ const peekData = this.peekQueue.pop();
1049
+ if (!peekData)
1050
+ throw new Error("peekData should be defined");
1051
+ const lenCopy = Math.min(peekData.length, remaining);
1052
+ buffer.set(peekData.subarray(0, lenCopy), bytesRead);
1053
+ bytesRead += lenCopy;
1054
+ remaining -= lenCopy;
1055
+ if (lenCopy < peekData.length) {
1056
+ this.peekQueue.push(peekData.subarray(lenCopy));
1057
+ }
1058
+ }
1059
+ return bytesRead;
1060
+ }
1061
+ async readRemainderFromStream(buffer, mayBeLess) {
1062
+ let bytesRead = 0;
1063
+ while (bytesRead < buffer.length && !this.endOfStream) {
1064
+ if (this.interrupted) {
1065
+ throw new AbortError();
1066
+ }
1067
+ const chunkLen = await this.readFromStream(buffer.subarray(bytesRead), mayBeLess);
1068
+ if (chunkLen === 0)
1069
+ break;
1070
+ bytesRead += chunkLen;
1071
+ }
1072
+ if (!mayBeLess && bytesRead < buffer.length) {
1073
+ throw new EndOfStreamError();
1074
+ }
1075
+ return bytesRead;
1076
+ }
1077
+ };
1078
+
1079
+ // node_modules/strtok3/lib/stream/WebStreamReader.js
1080
+ var WebStreamReader = class extends AbstractStreamReader {
1081
+ constructor(reader) {
1082
+ super();
1083
+ this.reader = reader;
1084
+ }
1085
+ async abort() {
1086
+ return this.close();
1087
+ }
1088
+ async close() {
1089
+ this.reader.releaseLock();
1090
+ }
1091
+ };
1092
+
1093
+ // node_modules/strtok3/lib/stream/WebStreamByobReader.js
1094
+ var WebStreamByobReader = class extends WebStreamReader {
1095
+ /**
1096
+ * Read from stream
1097
+ * @param buffer - Target Uint8Array (or Buffer) to store data read from stream in
1098
+ * @param mayBeLess - If true, may fill the buffer partially
1099
+ * @protected Bytes read
1100
+ */
1101
+ async readFromStream(buffer, mayBeLess) {
1102
+ if (buffer.length === 0)
1103
+ return 0;
1104
+ const result = await this.reader.read(new Uint8Array(buffer.length), { min: mayBeLess ? void 0 : buffer.length });
1105
+ if (result.done) {
1106
+ this.endOfStream = result.done;
1107
+ }
1108
+ if (result.value) {
1109
+ buffer.set(result.value);
1110
+ return result.value.length;
1111
+ }
1112
+ return 0;
1113
+ }
1114
+ };
1115
+
1116
+ // node_modules/strtok3/lib/stream/WebStreamDefaultReader.js
1117
+ var WebStreamDefaultReader = class extends AbstractStreamReader {
1118
+ constructor(reader) {
1119
+ super();
1120
+ this.reader = reader;
1121
+ this.buffer = null;
1122
+ }
1123
+ /**
1124
+ * Copy chunk to target, and store the remainder in this.buffer
1125
+ */
1126
+ writeChunk(target, chunk) {
1127
+ const written = Math.min(chunk.length, target.length);
1128
+ target.set(chunk.subarray(0, written));
1129
+ if (written < chunk.length) {
1130
+ this.buffer = chunk.subarray(written);
1131
+ } else {
1132
+ this.buffer = null;
1133
+ }
1134
+ return written;
1135
+ }
1136
+ /**
1137
+ * Read from stream
1138
+ * @param buffer - Target Uint8Array (or Buffer) to store data read from stream in
1139
+ * @param mayBeLess - If true, may fill the buffer partially
1140
+ * @protected Bytes read
1141
+ */
1142
+ async readFromStream(buffer, mayBeLess) {
1143
+ if (buffer.length === 0)
1144
+ return 0;
1145
+ let totalBytesRead = 0;
1146
+ if (this.buffer) {
1147
+ totalBytesRead += this.writeChunk(buffer, this.buffer);
1148
+ }
1149
+ while (totalBytesRead < buffer.length && !this.endOfStream) {
1150
+ const result = await this.reader.read();
1151
+ if (result.done) {
1152
+ this.endOfStream = true;
1153
+ break;
1154
+ }
1155
+ if (result.value) {
1156
+ totalBytesRead += this.writeChunk(buffer.subarray(totalBytesRead), result.value);
1157
+ }
1158
+ }
1159
+ if (!mayBeLess && totalBytesRead === 0 && this.endOfStream) {
1160
+ throw new EndOfStreamError();
1161
+ }
1162
+ return totalBytesRead;
1163
+ }
1164
+ abort() {
1165
+ this.interrupted = true;
1166
+ return this.reader.cancel();
1167
+ }
1168
+ async close() {
1169
+ await this.abort();
1170
+ this.reader.releaseLock();
1171
+ }
1172
+ };
1173
+
1174
+ // node_modules/strtok3/lib/stream/WebStreamReaderFactory.js
1175
+ function makeWebStreamReader(stream) {
1176
+ try {
1177
+ const reader = stream.getReader({ mode: "byob" });
1178
+ if (reader instanceof ReadableStreamDefaultReader) {
1179
+ return new WebStreamDefaultReader(reader);
1180
+ }
1181
+ return new WebStreamByobReader(reader);
1182
+ } catch (error) {
1183
+ if (error instanceof TypeError) {
1184
+ return new WebStreamDefaultReader(stream.getReader());
1185
+ }
1186
+ throw error;
1187
+ }
1188
+ }
1189
+
1190
+ // node_modules/strtok3/lib/AbstractTokenizer.js
1191
+ var AbstractTokenizer = class {
1192
+ /**
1193
+ * Constructor
1194
+ * @param options Tokenizer options
1195
+ * @protected
1196
+ */
1197
+ constructor(options) {
1198
+ this.numBuffer = new Uint8Array(8);
1199
+ this.position = 0;
1200
+ this.onClose = options?.onClose;
1201
+ if (options?.abortSignal) {
1202
+ options.abortSignal.addEventListener("abort", () => {
1203
+ this.abort();
1204
+ });
1205
+ }
1206
+ }
1207
+ /**
1208
+ * Read a token from the tokenizer-stream
1209
+ * @param token - The token to read
1210
+ * @param position - If provided, the desired position in the tokenizer-stream
1211
+ * @returns Promise with token data
1212
+ */
1213
+ async readToken(token, position = this.position) {
1214
+ const uint8Array = new Uint8Array(token.len);
1215
+ const len = await this.readBuffer(uint8Array, { position });
1216
+ if (len < token.len)
1217
+ throw new EndOfStreamError();
1218
+ return token.get(uint8Array, 0);
1219
+ }
1220
+ /**
1221
+ * Peek a token from the tokenizer-stream.
1222
+ * @param token - Token to peek from the tokenizer-stream.
1223
+ * @param position - Offset where to begin reading within the file. If position is null, data will be read from the current file position.
1224
+ * @returns Promise with token data
1225
+ */
1226
+ async peekToken(token, position = this.position) {
1227
+ const uint8Array = new Uint8Array(token.len);
1228
+ const len = await this.peekBuffer(uint8Array, { position });
1229
+ if (len < token.len)
1230
+ throw new EndOfStreamError();
1231
+ return token.get(uint8Array, 0);
1232
+ }
1233
+ /**
1234
+ * Read a numeric token from the stream
1235
+ * @param token - Numeric token
1236
+ * @returns Promise with number
1237
+ */
1238
+ async readNumber(token) {
1239
+ const len = await this.readBuffer(this.numBuffer, { length: token.len });
1240
+ if (len < token.len)
1241
+ throw new EndOfStreamError();
1242
+ return token.get(this.numBuffer, 0);
1243
+ }
1244
+ /**
1245
+ * Read a numeric token from the stream
1246
+ * @param token - Numeric token
1247
+ * @returns Promise with number
1248
+ */
1249
+ async peekNumber(token) {
1250
+ const len = await this.peekBuffer(this.numBuffer, { length: token.len });
1251
+ if (len < token.len)
1252
+ throw new EndOfStreamError();
1253
+ return token.get(this.numBuffer, 0);
1254
+ }
1255
+ /**
1256
+ * Ignore number of bytes, advances the pointer in under tokenizer-stream.
1257
+ * @param length - Number of bytes to ignore. Must be ≥ 0.
1258
+ * @return resolves the number of bytes ignored, equals length if this available, otherwise the number of bytes available
1259
+ */
1260
+ async ignore(length) {
1261
+ if (length < 0) {
1262
+ throw new RangeError("ignore length must be \u2265 0 bytes");
1263
+ }
1264
+ if (this.fileInfo.size !== void 0) {
1265
+ const bytesLeft = this.fileInfo.size - this.position;
1266
+ if (length > bytesLeft) {
1267
+ this.position += bytesLeft;
1268
+ return bytesLeft;
1269
+ }
1270
+ }
1271
+ this.position += length;
1272
+ return length;
1273
+ }
1274
+ async close() {
1275
+ await this.abort();
1276
+ await this.onClose?.();
1277
+ }
1278
+ normalizeOptions(uint8Array, options) {
1279
+ if (!this.supportsRandomAccess() && options && options.position !== void 0 && options.position < this.position) {
1280
+ throw new Error("`options.position` must be equal or greater than `tokenizer.position`");
1281
+ }
1282
+ return {
1283
+ ...{
1284
+ mayBeLess: false,
1285
+ offset: 0,
1286
+ length: uint8Array.length,
1287
+ position: this.position
1288
+ },
1289
+ ...options
1290
+ };
1291
+ }
1292
+ abort() {
1293
+ return Promise.resolve();
1294
+ }
1295
+ };
1296
+
1297
+ // node_modules/strtok3/lib/ReadStreamTokenizer.js
1298
+ var maxBufferSize = 256e3;
1299
+ var ReadStreamTokenizer = class extends AbstractTokenizer {
1300
+ /**
1301
+ * Constructor
1302
+ * @param streamReader stream-reader to read from
1303
+ * @param options Tokenizer options
1304
+ */
1305
+ constructor(streamReader, options) {
1306
+ super(options);
1307
+ this.streamReader = streamReader;
1308
+ this.fileInfo = options?.fileInfo ?? {};
1309
+ }
1310
+ /**
1311
+ * Read buffer from tokenizer
1312
+ * @param uint8Array - Target Uint8Array to fill with data read from the tokenizer-stream
1313
+ * @param options - Read behaviour options
1314
+ * @returns Promise with number of bytes read
1315
+ */
1316
+ async readBuffer(uint8Array, options) {
1317
+ const normOptions = this.normalizeOptions(uint8Array, options);
1318
+ const skipBytes = normOptions.position - this.position;
1319
+ if (skipBytes > 0) {
1320
+ await this.ignore(skipBytes);
1321
+ return this.readBuffer(uint8Array, options);
1322
+ }
1323
+ if (skipBytes < 0) {
1324
+ throw new Error("`options.position` must be equal or greater than `tokenizer.position`");
1325
+ }
1326
+ if (normOptions.length === 0) {
1327
+ return 0;
1328
+ }
1329
+ const bytesRead = await this.streamReader.read(uint8Array.subarray(0, normOptions.length), normOptions.mayBeLess);
1330
+ this.position += bytesRead;
1331
+ if ((!options || !options.mayBeLess) && bytesRead < normOptions.length) {
1332
+ throw new EndOfStreamError();
1333
+ }
1334
+ return bytesRead;
1335
+ }
1336
+ /**
1337
+ * Peek (read ahead) buffer from tokenizer
1338
+ * @param uint8Array - Uint8Array (or Buffer) to write data to
1339
+ * @param options - Read behaviour options
1340
+ * @returns Promise with number of bytes peeked
1341
+ */
1342
+ async peekBuffer(uint8Array, options) {
1343
+ const normOptions = this.normalizeOptions(uint8Array, options);
1344
+ let bytesRead = 0;
1345
+ if (normOptions.position) {
1346
+ const skipBytes = normOptions.position - this.position;
1347
+ if (skipBytes > 0) {
1348
+ const skipBuffer = new Uint8Array(normOptions.length + skipBytes);
1349
+ bytesRead = await this.peekBuffer(skipBuffer, { mayBeLess: normOptions.mayBeLess });
1350
+ uint8Array.set(skipBuffer.subarray(skipBytes));
1351
+ return bytesRead - skipBytes;
1352
+ }
1353
+ if (skipBytes < 0) {
1354
+ throw new Error("Cannot peek from a negative offset in a stream");
1355
+ }
1356
+ }
1357
+ if (normOptions.length > 0) {
1358
+ try {
1359
+ bytesRead = await this.streamReader.peek(uint8Array.subarray(0, normOptions.length), normOptions.mayBeLess);
1360
+ } catch (err) {
1361
+ if (options?.mayBeLess && err instanceof EndOfStreamError) {
1362
+ return 0;
1363
+ }
1364
+ throw err;
1365
+ }
1366
+ if (!normOptions.mayBeLess && bytesRead < normOptions.length) {
1367
+ throw new EndOfStreamError();
1368
+ }
1369
+ }
1370
+ return bytesRead;
1371
+ }
1372
+ /**
1373
+ * @param length Number of bytes to ignore. Must be ≥ 0.
1374
+ */
1375
+ async ignore(length) {
1376
+ if (length < 0) {
1377
+ throw new RangeError("ignore length must be \u2265 0 bytes");
1378
+ }
1379
+ const bufSize = Math.min(maxBufferSize, length);
1380
+ const buf = new Uint8Array(bufSize);
1381
+ let totBytesRead = 0;
1382
+ while (totBytesRead < length) {
1383
+ const remaining = length - totBytesRead;
1384
+ const bytesRead = await this.readBuffer(buf, { length: Math.min(bufSize, remaining) });
1385
+ if (bytesRead < 0) {
1386
+ return bytesRead;
1387
+ }
1388
+ totBytesRead += bytesRead;
1389
+ }
1390
+ return totBytesRead;
1391
+ }
1392
+ abort() {
1393
+ return this.streamReader.abort();
1394
+ }
1395
+ async close() {
1396
+ return this.streamReader.close();
1397
+ }
1398
+ supportsRandomAccess() {
1399
+ return false;
1400
+ }
1401
+ };
1402
+
1403
+ // node_modules/strtok3/lib/BufferTokenizer.js
1404
+ var BufferTokenizer = class extends AbstractTokenizer {
1405
+ /**
1406
+ * Construct BufferTokenizer
1407
+ * @param uint8Array - Uint8Array to tokenize
1408
+ * @param options Tokenizer options
1409
+ */
1410
+ constructor(uint8Array, options) {
1411
+ super(options);
1412
+ this.uint8Array = uint8Array;
1413
+ this.fileInfo = { ...options?.fileInfo ?? {}, ...{ size: uint8Array.length } };
1414
+ }
1415
+ /**
1416
+ * Read buffer from tokenizer
1417
+ * @param uint8Array - Uint8Array to tokenize
1418
+ * @param options - Read behaviour options
1419
+ * @returns {Promise<number>}
1420
+ */
1421
+ async readBuffer(uint8Array, options) {
1422
+ if (options?.position) {
1423
+ this.position = options.position;
1424
+ }
1425
+ const bytesRead = await this.peekBuffer(uint8Array, options);
1426
+ this.position += bytesRead;
1427
+ return bytesRead;
1428
+ }
1429
+ /**
1430
+ * Peek (read ahead) buffer from tokenizer
1431
+ * @param uint8Array
1432
+ * @param options - Read behaviour options
1433
+ * @returns {Promise<number>}
1434
+ */
1435
+ async peekBuffer(uint8Array, options) {
1436
+ const normOptions = this.normalizeOptions(uint8Array, options);
1437
+ const bytes2read = Math.min(this.uint8Array.length - normOptions.position, normOptions.length);
1438
+ if (!normOptions.mayBeLess && bytes2read < normOptions.length) {
1439
+ throw new EndOfStreamError();
1440
+ }
1441
+ uint8Array.set(this.uint8Array.subarray(normOptions.position, normOptions.position + bytes2read));
1442
+ return bytes2read;
1443
+ }
1444
+ close() {
1445
+ return super.close();
1446
+ }
1447
+ supportsRandomAccess() {
1448
+ return true;
1449
+ }
1450
+ setPosition(position) {
1451
+ this.position = position;
1452
+ }
1453
+ };
1454
+
1455
+ // node_modules/strtok3/lib/BlobTokenizer.js
1456
+ var BlobTokenizer = class extends AbstractTokenizer {
1457
+ /**
1458
+ * Construct BufferTokenizer
1459
+ * @param blob - Uint8Array to tokenize
1460
+ * @param options Tokenizer options
1461
+ */
1462
+ constructor(blob, options) {
1463
+ super(options);
1464
+ this.blob = blob;
1465
+ this.fileInfo = { ...options?.fileInfo ?? {}, ...{ size: blob.size, mimeType: blob.type } };
1466
+ }
1467
+ /**
1468
+ * Read buffer from tokenizer
1469
+ * @param uint8Array - Uint8Array to tokenize
1470
+ * @param options - Read behaviour options
1471
+ * @returns {Promise<number>}
1472
+ */
1473
+ async readBuffer(uint8Array, options) {
1474
+ if (options?.position) {
1475
+ this.position = options.position;
1476
+ }
1477
+ const bytesRead = await this.peekBuffer(uint8Array, options);
1478
+ this.position += bytesRead;
1479
+ return bytesRead;
1480
+ }
1481
+ /**
1482
+ * Peek (read ahead) buffer from tokenizer
1483
+ * @param buffer
1484
+ * @param options - Read behaviour options
1485
+ * @returns {Promise<number>}
1486
+ */
1487
+ async peekBuffer(buffer, options) {
1488
+ const normOptions = this.normalizeOptions(buffer, options);
1489
+ const bytes2read = Math.min(this.blob.size - normOptions.position, normOptions.length);
1490
+ if (!normOptions.mayBeLess && bytes2read < normOptions.length) {
1491
+ throw new EndOfStreamError();
1492
+ }
1493
+ const arrayBuffer = await this.blob.slice(normOptions.position, normOptions.position + bytes2read).arrayBuffer();
1494
+ buffer.set(new Uint8Array(arrayBuffer));
1495
+ return bytes2read;
1496
+ }
1497
+ close() {
1498
+ return super.close();
1499
+ }
1500
+ supportsRandomAccess() {
1501
+ return true;
1502
+ }
1503
+ setPosition(position) {
1504
+ this.position = position;
1505
+ }
1506
+ };
1507
+
1508
+ // node_modules/strtok3/lib/core.js
1509
+ function fromWebStream(webStream, options) {
1510
+ const webStreamReader = makeWebStreamReader(webStream);
1511
+ const _options = options ?? {};
1512
+ const chainedClose = _options.onClose;
1513
+ _options.onClose = async () => {
1514
+ await webStreamReader.close();
1515
+ if (chainedClose) {
1516
+ return chainedClose();
1517
+ }
1518
+ };
1519
+ return new ReadStreamTokenizer(webStreamReader, _options);
1520
+ }
1521
+ function fromBuffer(uint8Array, options) {
1522
+ return new BufferTokenizer(uint8Array, options);
1523
+ }
1524
+ function fromBlob(blob, options) {
1525
+ return new BlobTokenizer(blob, options);
1526
+ }
1527
+
1528
+ // node_modules/@tokenizer/inflate/lib/ZipHandler.js
1529
+ var import_debug = __toESM(require_src(), 1);
1530
+
1531
+ // node_modules/@tokenizer/inflate/lib/ZipToken.js
1532
+ var Signature = {
1533
+ LocalFileHeader: 67324752,
1534
+ DataDescriptor: 134695760,
1535
+ CentralFileHeader: 33639248,
1536
+ EndOfCentralDirectory: 101010256
1537
+ };
1538
+ var DataDescriptor = {
1539
+ get(array) {
1540
+ return {
1541
+ signature: UINT32_LE.get(array, 0),
1542
+ compressedSize: UINT32_LE.get(array, 8),
1543
+ uncompressedSize: UINT32_LE.get(array, 12)
1544
+ };
1545
+ },
1546
+ len: 16
1547
+ };
1548
+ var LocalFileHeaderToken = {
1549
+ get(array) {
1550
+ const flags = UINT16_LE.get(array, 6);
1551
+ return {
1552
+ signature: UINT32_LE.get(array, 0),
1553
+ minVersion: UINT16_LE.get(array, 4),
1554
+ dataDescriptor: !!(flags & 8),
1555
+ compressedMethod: UINT16_LE.get(array, 8),
1556
+ compressedSize: UINT32_LE.get(array, 18),
1557
+ uncompressedSize: UINT32_LE.get(array, 22),
1558
+ filenameLength: UINT16_LE.get(array, 26),
1559
+ extraFieldLength: UINT16_LE.get(array, 28),
1560
+ filename: null
1561
+ };
1562
+ },
1563
+ len: 30
1564
+ };
1565
+ var EndOfCentralDirectoryRecordToken = {
1566
+ get(array) {
1567
+ return {
1568
+ signature: UINT32_LE.get(array, 0),
1569
+ nrOfThisDisk: UINT16_LE.get(array, 4),
1570
+ nrOfThisDiskWithTheStart: UINT16_LE.get(array, 6),
1571
+ nrOfEntriesOnThisDisk: UINT16_LE.get(array, 8),
1572
+ nrOfEntriesOfSize: UINT16_LE.get(array, 10),
1573
+ sizeOfCd: UINT32_LE.get(array, 12),
1574
+ offsetOfStartOfCd: UINT32_LE.get(array, 16),
1575
+ zipFileCommentLength: UINT16_LE.get(array, 20)
1576
+ };
1577
+ },
1578
+ len: 22
1579
+ };
1580
+ var FileHeader = {
1581
+ get(array) {
1582
+ const flags = UINT16_LE.get(array, 8);
1583
+ return {
1584
+ signature: UINT32_LE.get(array, 0),
1585
+ minVersion: UINT16_LE.get(array, 6),
1586
+ dataDescriptor: !!(flags & 8),
1587
+ compressedMethod: UINT16_LE.get(array, 10),
1588
+ compressedSize: UINT32_LE.get(array, 20),
1589
+ uncompressedSize: UINT32_LE.get(array, 24),
1590
+ filenameLength: UINT16_LE.get(array, 28),
1591
+ extraFieldLength: UINT16_LE.get(array, 30),
1592
+ fileCommentLength: UINT16_LE.get(array, 32),
1593
+ relativeOffsetOfLocalHeader: UINT32_LE.get(array, 42),
1594
+ filename: null
1595
+ };
1596
+ },
1597
+ len: 46
1598
+ };
1599
+
1600
+ // node_modules/@tokenizer/inflate/lib/ZipHandler.js
1601
+ function signatureToArray(signature) {
1602
+ const signatureBytes = new Uint8Array(UINT32_LE.len);
1603
+ UINT32_LE.put(signatureBytes, 0, signature);
1604
+ return signatureBytes;
1605
+ }
1606
+ var debug = (0, import_debug.default)("tokenizer:inflate");
1607
+ var syncBufferSize = 256 * 1024;
1608
+ var ddSignatureArray = signatureToArray(Signature.DataDescriptor);
1609
+ var eocdSignatureBytes = signatureToArray(Signature.EndOfCentralDirectory);
1610
+ var ZipHandler = class _ZipHandler {
1611
+ constructor(tokenizer) {
1612
+ this.tokenizer = tokenizer;
1613
+ this.syncBuffer = new Uint8Array(syncBufferSize);
1614
+ }
1615
+ async isZip() {
1616
+ return await this.peekSignature() === Signature.LocalFileHeader;
1617
+ }
1618
+ peekSignature() {
1619
+ return this.tokenizer.peekToken(UINT32_LE);
1620
+ }
1621
+ async findEndOfCentralDirectoryLocator() {
1622
+ const randomReadTokenizer = this.tokenizer;
1623
+ const chunkLength = Math.min(16 * 1024, randomReadTokenizer.fileInfo.size);
1624
+ const buffer = this.syncBuffer.subarray(0, chunkLength);
1625
+ await this.tokenizer.readBuffer(buffer, { position: randomReadTokenizer.fileInfo.size - chunkLength });
1626
+ for (let i = buffer.length - 4; i >= 0; i--) {
1627
+ if (buffer[i] === eocdSignatureBytes[0] && buffer[i + 1] === eocdSignatureBytes[1] && buffer[i + 2] === eocdSignatureBytes[2] && buffer[i + 3] === eocdSignatureBytes[3]) {
1628
+ return randomReadTokenizer.fileInfo.size - chunkLength + i;
1629
+ }
1630
+ }
1631
+ return -1;
1632
+ }
1633
+ async readCentralDirectory() {
1634
+ if (!this.tokenizer.supportsRandomAccess()) {
1635
+ debug("Cannot reading central-directory without random-read support");
1636
+ return;
1637
+ }
1638
+ debug("Reading central-directory...");
1639
+ const pos = this.tokenizer.position;
1640
+ const offset = await this.findEndOfCentralDirectoryLocator();
1641
+ if (offset > 0) {
1642
+ debug("Central-directory 32-bit signature found");
1643
+ const eocdHeader = await this.tokenizer.readToken(EndOfCentralDirectoryRecordToken, offset);
1644
+ const files = [];
1645
+ this.tokenizer.setPosition(eocdHeader.offsetOfStartOfCd);
1646
+ for (let n = 0; n < eocdHeader.nrOfEntriesOfSize; ++n) {
1647
+ const entry = await this.tokenizer.readToken(FileHeader);
1648
+ if (entry.signature !== Signature.CentralFileHeader) {
1649
+ throw new Error("Expected Central-File-Header signature");
1650
+ }
1651
+ entry.filename = await this.tokenizer.readToken(new StringType(entry.filenameLength, "utf-8"));
1652
+ await this.tokenizer.ignore(entry.extraFieldLength);
1653
+ await this.tokenizer.ignore(entry.fileCommentLength);
1654
+ files.push(entry);
1655
+ debug(`Add central-directory file-entry: n=${n + 1}/${files.length}: filename=${files[n].filename}`);
1656
+ }
1657
+ this.tokenizer.setPosition(pos);
1658
+ return files;
1659
+ }
1660
+ this.tokenizer.setPosition(pos);
1661
+ }
1662
+ async unzip(fileCb) {
1663
+ const entries = await this.readCentralDirectory();
1664
+ if (entries) {
1665
+ return this.iterateOverCentralDirectory(entries, fileCb);
1666
+ }
1667
+ let stop = false;
1668
+ do {
1669
+ const zipHeader = await this.readLocalFileHeader();
1670
+ if (!zipHeader)
1671
+ break;
1672
+ const next = fileCb(zipHeader);
1673
+ stop = !!next.stop;
1674
+ let fileData;
1675
+ await this.tokenizer.ignore(zipHeader.extraFieldLength);
1676
+ if (zipHeader.dataDescriptor && zipHeader.compressedSize === 0) {
1677
+ const chunks = [];
1678
+ let len = syncBufferSize;
1679
+ debug("Compressed-file-size unknown, scanning for next data-descriptor-signature....");
1680
+ let nextHeaderIndex = -1;
1681
+ while (nextHeaderIndex < 0 && len === syncBufferSize) {
1682
+ len = await this.tokenizer.peekBuffer(this.syncBuffer, { mayBeLess: true });
1683
+ nextHeaderIndex = indexOf(this.syncBuffer.subarray(0, len), ddSignatureArray);
1684
+ const size = nextHeaderIndex >= 0 ? nextHeaderIndex : len;
1685
+ if (next.handler) {
1686
+ const data = new Uint8Array(size);
1687
+ await this.tokenizer.readBuffer(data);
1688
+ chunks.push(data);
1689
+ } else {
1690
+ await this.tokenizer.ignore(size);
1691
+ }
1692
+ }
1693
+ debug(`Found data-descriptor-signature at pos=${this.tokenizer.position}`);
1694
+ if (next.handler) {
1695
+ await this.inflate(zipHeader, mergeArrays(chunks), next.handler);
1696
+ }
1697
+ } else {
1698
+ if (next.handler) {
1699
+ debug(`Reading compressed-file-data: ${zipHeader.compressedSize} bytes`);
1700
+ fileData = new Uint8Array(zipHeader.compressedSize);
1701
+ await this.tokenizer.readBuffer(fileData);
1702
+ await this.inflate(zipHeader, fileData, next.handler);
1703
+ } else {
1704
+ debug(`Ignoring compressed-file-data: ${zipHeader.compressedSize} bytes`);
1705
+ await this.tokenizer.ignore(zipHeader.compressedSize);
1706
+ }
1707
+ }
1708
+ debug(`Reading data-descriptor at pos=${this.tokenizer.position}`);
1709
+ if (zipHeader.dataDescriptor) {
1710
+ const dataDescriptor = await this.tokenizer.readToken(DataDescriptor);
1711
+ if (dataDescriptor.signature !== 134695760) {
1712
+ throw new Error(`Expected data-descriptor-signature at position ${this.tokenizer.position - DataDescriptor.len}`);
1713
+ }
1714
+ }
1715
+ } while (!stop);
1716
+ }
1717
+ async iterateOverCentralDirectory(entries, fileCb) {
1718
+ for (const fileHeader of entries) {
1719
+ const next = fileCb(fileHeader);
1720
+ if (next.handler) {
1721
+ this.tokenizer.setPosition(fileHeader.relativeOffsetOfLocalHeader);
1722
+ const zipHeader = await this.readLocalFileHeader();
1723
+ if (zipHeader) {
1724
+ await this.tokenizer.ignore(zipHeader.extraFieldLength);
1725
+ const fileData = new Uint8Array(fileHeader.compressedSize);
1726
+ await this.tokenizer.readBuffer(fileData);
1727
+ await this.inflate(zipHeader, fileData, next.handler);
1728
+ }
1729
+ }
1730
+ if (next.stop)
1731
+ break;
1732
+ }
1733
+ }
1734
+ async inflate(zipHeader, fileData, cb) {
1735
+ if (zipHeader.compressedMethod === 0) {
1736
+ return cb(fileData);
1737
+ }
1738
+ if (zipHeader.compressedMethod !== 8) {
1739
+ throw new Error(`Unsupported ZIP compression method: ${zipHeader.compressedMethod}`);
1740
+ }
1741
+ debug(`Decompress filename=${zipHeader.filename}, compressed-size=${fileData.length}`);
1742
+ const uncompressedData = await _ZipHandler.decompressDeflateRaw(fileData);
1743
+ return cb(uncompressedData);
1744
+ }
1745
+ static async decompressDeflateRaw(data) {
1746
+ const input = new ReadableStream({
1747
+ start(controller) {
1748
+ controller.enqueue(data);
1749
+ controller.close();
1750
+ }
1751
+ });
1752
+ const ds = new DecompressionStream("deflate-raw");
1753
+ const output = input.pipeThrough(ds);
1754
+ try {
1755
+ const response = new Response(output);
1756
+ const buffer = await response.arrayBuffer();
1757
+ return new Uint8Array(buffer);
1758
+ } catch (err) {
1759
+ const message = err instanceof Error ? `Failed to deflate ZIP entry: ${err.message}` : "Unknown decompression error in ZIP entry";
1760
+ throw new TypeError(message);
1761
+ }
1762
+ }
1763
+ async readLocalFileHeader() {
1764
+ const signature = await this.tokenizer.peekToken(UINT32_LE);
1765
+ if (signature === Signature.LocalFileHeader) {
1766
+ const header = await this.tokenizer.readToken(LocalFileHeaderToken);
1767
+ header.filename = await this.tokenizer.readToken(new StringType(header.filenameLength, "utf-8"));
1768
+ return header;
1769
+ }
1770
+ if (signature === Signature.CentralFileHeader) {
1771
+ return false;
1772
+ }
1773
+ if (signature === 3759263696) {
1774
+ throw new Error("Encrypted ZIP");
1775
+ }
1776
+ throw new Error("Unexpected signature");
1777
+ }
1778
+ };
1779
+ function indexOf(buffer, portion) {
1780
+ const bufferLength = buffer.length;
1781
+ const portionLength = portion.length;
1782
+ if (portionLength > bufferLength)
1783
+ return -1;
1784
+ for (let i = 0; i <= bufferLength - portionLength; i++) {
1785
+ let found = true;
1786
+ for (let j = 0; j < portionLength; j++) {
1787
+ if (buffer[i + j] !== portion[j]) {
1788
+ found = false;
1789
+ break;
1790
+ }
1791
+ }
1792
+ if (found) {
1793
+ return i;
1794
+ }
1795
+ }
1796
+ return -1;
1797
+ }
1798
+ function mergeArrays(chunks) {
1799
+ const totalLength = chunks.reduce((acc, curr) => acc + curr.length, 0);
1800
+ const mergedArray = new Uint8Array(totalLength);
1801
+ let offset = 0;
1802
+ for (const chunk of chunks) {
1803
+ mergedArray.set(chunk, offset);
1804
+ offset += chunk.length;
1805
+ }
1806
+ return mergedArray;
1807
+ }
1808
+
1809
+ // node_modules/@tokenizer/inflate/lib/GzipHandler.js
1810
+ var GzipHandler = class {
1811
+ constructor(tokenizer) {
1812
+ this.tokenizer = tokenizer;
1813
+ }
1814
+ inflate() {
1815
+ const tokenizer = this.tokenizer;
1816
+ return new ReadableStream({
1817
+ async pull(controller) {
1818
+ const buffer = new Uint8Array(1024);
1819
+ const size = await tokenizer.readBuffer(buffer, { mayBeLess: true });
1820
+ if (size === 0) {
1821
+ controller.close();
1822
+ return;
1823
+ }
1824
+ controller.enqueue(buffer.subarray(0, size));
1825
+ }
1826
+ }).pipeThrough(new DecompressionStream("gzip"));
1827
+ }
1828
+ };
1829
+
1830
+ // node_modules/uint8array-extras/index.js
1831
+ var objectToString = Object.prototype.toString;
1832
+ var uint8ArrayStringified = "[object Uint8Array]";
1833
+ function isType(value, typeConstructor, typeStringified) {
1834
+ if (!value) {
1835
+ return false;
1836
+ }
1837
+ if (value.constructor === typeConstructor) {
1838
+ return true;
1839
+ }
1840
+ return objectToString.call(value) === typeStringified;
1841
+ }
1842
+ function isUint8Array(value) {
1843
+ return isType(value, Uint8Array, uint8ArrayStringified);
1844
+ }
1845
+ function assertUint8Array(value) {
1846
+ if (!isUint8Array(value)) {
1847
+ throw new TypeError(`Expected \`Uint8Array\`, got \`${typeof value}\``);
1848
+ }
1849
+ }
1850
+ function concatUint8Arrays(arrays, totalLength) {
1851
+ if (arrays.length === 0) {
1852
+ return new Uint8Array(0);
1853
+ }
1854
+ totalLength ??= arrays.reduce((accumulator, currentValue) => accumulator + currentValue.length, 0);
1855
+ const returnValue = new Uint8Array(totalLength);
1856
+ let offset = 0;
1857
+ for (const array of arrays) {
1858
+ assertUint8Array(array);
1859
+ returnValue.set(array, offset);
1860
+ offset += array.length;
1861
+ }
1862
+ return returnValue;
1863
+ }
1864
+ var cachedDecoders = {
1865
+ utf8: new globalThis.TextDecoder("utf8")
1866
+ };
1867
+ var cachedEncoder = new globalThis.TextEncoder();
1868
+ var byteToHexLookupTable = Array.from({ length: 256 }, (_, index) => index.toString(16).padStart(2, "0"));
1869
+ function getUintBE(view) {
1870
+ const { byteLength } = view;
1871
+ if (byteLength === 6) {
1872
+ return view.getUint16(0) * 2 ** 32 + view.getUint32(2);
1873
+ }
1874
+ if (byteLength === 5) {
1875
+ return view.getUint8(0) * 2 ** 32 + view.getUint32(1);
1876
+ }
1877
+ if (byteLength === 4) {
1878
+ return view.getUint32(0);
1879
+ }
1880
+ if (byteLength === 3) {
1881
+ return view.getUint8(0) * 2 ** 16 + view.getUint16(1);
1882
+ }
1883
+ if (byteLength === 2) {
1884
+ return view.getUint16(0);
1885
+ }
1886
+ if (byteLength === 1) {
1887
+ return view.getUint8(0);
1888
+ }
1889
+ }
1890
+
1891
+ // node_modules/file-type/source/tokens.js
1892
+ function stringToBytes(string, encoding) {
1893
+ if (encoding === "utf-16le") {
1894
+ const bytes = [];
1895
+ for (let index = 0; index < string.length; index++) {
1896
+ const code = string.charCodeAt(index);
1897
+ bytes.push(code & 255, code >> 8 & 255);
1898
+ }
1899
+ return bytes;
1900
+ }
1901
+ if (encoding === "utf-16be") {
1902
+ const bytes = [];
1903
+ for (let index = 0; index < string.length; index++) {
1904
+ const code = string.charCodeAt(index);
1905
+ bytes.push(code >> 8 & 255, code & 255);
1906
+ }
1907
+ return bytes;
1908
+ }
1909
+ return [...string].map((character) => character.charCodeAt(0));
1910
+ }
1911
+ function tarHeaderChecksumMatches(arrayBuffer, offset = 0) {
1912
+ const readSum = Number.parseInt(new StringType(6).get(arrayBuffer, 148).replace(/\0.*$/v, "").trim(), 8);
1913
+ if (Number.isNaN(readSum)) {
1914
+ return false;
1915
+ }
1916
+ let sum = 8 * 32;
1917
+ for (let index = offset; index < offset + 148; index++) {
1918
+ sum += arrayBuffer[index];
1919
+ }
1920
+ for (let index = offset + 156; index < offset + 512; index++) {
1921
+ sum += arrayBuffer[index];
1922
+ }
1923
+ return readSum === sum;
1924
+ }
1925
+ var uint32SyncSafeToken = {
1926
+ get: (buffer, offset) => buffer[offset + 3] & 127 | (buffer[offset + 2] & 127) << 7 | (buffer[offset + 1] & 127) << 14 | (buffer[offset] & 127) << 21,
1927
+ len: 4
1928
+ };
1929
+
1930
+ // node_modules/file-type/source/supported.js
1931
+ var extensions = [
1932
+ "jpg",
1933
+ "png",
1934
+ "apng",
1935
+ "gif",
1936
+ "webp",
1937
+ "flif",
1938
+ "xcf",
1939
+ "cr2",
1940
+ "cr3",
1941
+ "orf",
1942
+ "arw",
1943
+ "dng",
1944
+ "nef",
1945
+ "rw2",
1946
+ "raf",
1947
+ "tif",
1948
+ "bmp",
1949
+ "icns",
1950
+ "jxr",
1951
+ "psd",
1952
+ "indd",
1953
+ "zip",
1954
+ "tar",
1955
+ "rar",
1956
+ "gz",
1957
+ "bz2",
1958
+ "7z",
1959
+ "dmg",
1960
+ "mp4",
1961
+ "mid",
1962
+ "mkv",
1963
+ "webm",
1964
+ "mov",
1965
+ "avi",
1966
+ "mpg",
1967
+ "mp2",
1968
+ "mp3",
1969
+ "m4a",
1970
+ "oga",
1971
+ "ogg",
1972
+ "ogv",
1973
+ "opus",
1974
+ "flac",
1975
+ "wav",
1976
+ "spx",
1977
+ "amr",
1978
+ "pdf",
1979
+ "epub",
1980
+ "elf",
1981
+ "macho",
1982
+ "exe",
1983
+ "swf",
1984
+ "rtf",
1985
+ "wasm",
1986
+ "woff",
1987
+ "woff2",
1988
+ "eot",
1989
+ "ttf",
1990
+ "otf",
1991
+ "ttc",
1992
+ "ico",
1993
+ "flv",
1994
+ "ps",
1995
+ "xz",
1996
+ "sqlite",
1997
+ "nes",
1998
+ "crx",
1999
+ "xpi",
2000
+ "cab",
2001
+ "deb",
2002
+ "ar",
2003
+ "rpm",
2004
+ "Z",
2005
+ "lz",
2006
+ "cfb",
2007
+ "mxf",
2008
+ "mts",
2009
+ "blend",
2010
+ "bpg",
2011
+ "docx",
2012
+ "pptx",
2013
+ "xlsx",
2014
+ "3gp",
2015
+ "3g2",
2016
+ "j2c",
2017
+ "jp2",
2018
+ "jpm",
2019
+ "jpx",
2020
+ "mj2",
2021
+ "aif",
2022
+ "qcp",
2023
+ "odt",
2024
+ "ods",
2025
+ "odp",
2026
+ "xml",
2027
+ "mobi",
2028
+ "heic",
2029
+ "cur",
2030
+ "ktx",
2031
+ "ape",
2032
+ "wv",
2033
+ "dcm",
2034
+ "ics",
2035
+ "glb",
2036
+ "pcap",
2037
+ "dsf",
2038
+ "lnk",
2039
+ "alias",
2040
+ "voc",
2041
+ "ac3",
2042
+ "m4v",
2043
+ "m4p",
2044
+ "m4b",
2045
+ "f4v",
2046
+ "f4p",
2047
+ "f4b",
2048
+ "f4a",
2049
+ "mie",
2050
+ "asf",
2051
+ "ogm",
2052
+ "ogx",
2053
+ "mpc",
2054
+ "arrow",
2055
+ "shp",
2056
+ "aac",
2057
+ "mp1",
2058
+ "it",
2059
+ "s3m",
2060
+ "xm",
2061
+ "skp",
2062
+ "avif",
2063
+ "eps",
2064
+ "lzh",
2065
+ "pgp",
2066
+ "asar",
2067
+ "stl",
2068
+ "chm",
2069
+ "3mf",
2070
+ "zst",
2071
+ "jxl",
2072
+ "vcf",
2073
+ "jls",
2074
+ "pst",
2075
+ "dwg",
2076
+ "parquet",
2077
+ "class",
2078
+ "arj",
2079
+ "cpio",
2080
+ "ace",
2081
+ "avro",
2082
+ "icc",
2083
+ "fbx",
2084
+ "vsdx",
2085
+ "vtt",
2086
+ "apk",
2087
+ "drc",
2088
+ "lz4",
2089
+ "potx",
2090
+ "xltx",
2091
+ "dotx",
2092
+ "xltm",
2093
+ "ott",
2094
+ "ots",
2095
+ "otp",
2096
+ "odg",
2097
+ "otg",
2098
+ "xlsm",
2099
+ "docm",
2100
+ "dotm",
2101
+ "potm",
2102
+ "pptm",
2103
+ "jar",
2104
+ "jmp",
2105
+ "rm",
2106
+ "sav",
2107
+ "ppsm",
2108
+ "ppsx",
2109
+ "tar.gz",
2110
+ "reg",
2111
+ "dat",
2112
+ "key",
2113
+ "numbers",
2114
+ "pages"
2115
+ ];
2116
+ var mimeTypes = [
2117
+ "image/jpeg",
2118
+ "image/png",
2119
+ "image/gif",
2120
+ "image/webp",
2121
+ "image/flif",
2122
+ "image/x-xcf",
2123
+ "image/x-canon-cr2",
2124
+ "image/x-canon-cr3",
2125
+ "image/tiff",
2126
+ "image/bmp",
2127
+ "image/vnd.ms-photo",
2128
+ "image/vnd.adobe.photoshop",
2129
+ "application/x-indesign",
2130
+ "application/epub+zip",
2131
+ "application/x-xpinstall",
2132
+ "application/vnd.ms-powerpoint.slideshow.macroenabled.12",
2133
+ "application/vnd.oasis.opendocument.text",
2134
+ "application/vnd.oasis.opendocument.spreadsheet",
2135
+ "application/vnd.oasis.opendocument.presentation",
2136
+ "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
2137
+ "application/vnd.openxmlformats-officedocument.presentationml.presentation",
2138
+ "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
2139
+ "application/vnd.openxmlformats-officedocument.presentationml.slideshow",
2140
+ "application/zip",
2141
+ "application/x-tar",
2142
+ "application/x-rar-compressed",
2143
+ "application/gzip",
2144
+ "application/x-bzip2",
2145
+ "application/x-7z-compressed",
2146
+ "application/x-apple-diskimage",
2147
+ "application/vnd.apache.arrow.file",
2148
+ "video/mp4",
2149
+ "audio/midi",
2150
+ "video/matroska",
2151
+ "video/webm",
2152
+ "video/quicktime",
2153
+ "video/vnd.avi",
2154
+ "audio/wav",
2155
+ "audio/qcelp",
2156
+ "audio/x-ms-asf",
2157
+ "video/x-ms-asf",
2158
+ "application/vnd.ms-asf",
2159
+ "video/mpeg",
2160
+ "video/3gpp",
2161
+ "audio/mpeg",
2162
+ "audio/mp4",
2163
+ // RFC 4337
2164
+ "video/ogg",
2165
+ "audio/ogg",
2166
+ "audio/ogg; codecs=opus",
2167
+ "application/ogg",
2168
+ "audio/flac",
2169
+ "audio/ape",
2170
+ "audio/wavpack",
2171
+ "audio/amr",
2172
+ "application/pdf",
2173
+ "application/x-elf",
2174
+ "application/x-mach-binary",
2175
+ "application/x-msdownload",
2176
+ "application/x-shockwave-flash",
2177
+ "application/rtf",
2178
+ "application/wasm",
2179
+ "font/woff",
2180
+ "font/woff2",
2181
+ "application/vnd.ms-fontobject",
2182
+ "font/ttf",
2183
+ "font/otf",
2184
+ "font/collection",
2185
+ "image/x-icon",
2186
+ "video/x-flv",
2187
+ "application/postscript",
2188
+ "application/eps",
2189
+ "application/x-xz",
2190
+ "application/x-sqlite3",
2191
+ "application/x-nintendo-nes-rom",
2192
+ "application/x-google-chrome-extension",
2193
+ "application/vnd.ms-cab-compressed",
2194
+ "application/x-deb",
2195
+ "application/x-unix-archive",
2196
+ "application/x-rpm",
2197
+ "application/x-compress",
2198
+ "application/lzip",
2199
+ "application/x-cfb",
2200
+ "application/x-mie",
2201
+ "application/mxf",
2202
+ "video/mp2t",
2203
+ "application/x-blender",
2204
+ "image/bpg",
2205
+ "image/j2c",
2206
+ "image/jp2",
2207
+ "image/jpx",
2208
+ "image/jpm",
2209
+ "image/mj2",
2210
+ "audio/aiff",
2211
+ "application/xml",
2212
+ "application/x-mobipocket-ebook",
2213
+ "image/heif",
2214
+ "image/heif-sequence",
2215
+ "image/heic",
2216
+ "image/heic-sequence",
2217
+ "image/icns",
2218
+ "image/ktx",
2219
+ "application/dicom",
2220
+ "audio/x-musepack",
2221
+ "text/calendar",
2222
+ "text/vcard",
2223
+ "text/vtt",
2224
+ "model/gltf-binary",
2225
+ "application/vnd.tcpdump.pcap",
2226
+ "audio/x-dsf",
2227
+ // Non-standard
2228
+ "application/x-ms-shortcut",
2229
+ // Informal, used by freedesktop.org shared-mime-info
2230
+ "application/x-ft-apple.alias",
2231
+ "audio/x-voc",
2232
+ "audio/vnd.dolby.dd-raw",
2233
+ "audio/x-m4a",
2234
+ "image/apng",
2235
+ "image/x-olympus-orf",
2236
+ "image/x-sony-arw",
2237
+ "image/x-adobe-dng",
2238
+ "image/x-nikon-nef",
2239
+ "image/x-panasonic-rw2",
2240
+ "image/x-fujifilm-raf",
2241
+ "video/x-m4v",
2242
+ "video/3gpp2",
2243
+ "application/x-esri-shape",
2244
+ "audio/aac",
2245
+ "audio/x-it",
2246
+ "audio/x-s3m",
2247
+ "audio/x-xm",
2248
+ "video/MP1S",
2249
+ "video/MP2P",
2250
+ "application/vnd.sketchup.skp",
2251
+ "image/avif",
2252
+ "application/x-lzh-compressed",
2253
+ "application/pgp-encrypted",
2254
+ "application/x-asar",
2255
+ "model/stl",
2256
+ "application/vnd.ms-htmlhelp",
2257
+ "model/3mf",
2258
+ "image/jxl",
2259
+ "application/zstd",
2260
+ "image/jls",
2261
+ "application/vnd.ms-outlook",
2262
+ "image/vnd.dwg",
2263
+ "application/vnd.apache.parquet",
2264
+ "application/java-vm",
2265
+ "application/x-arj",
2266
+ "application/x-cpio",
2267
+ "application/x-ace-compressed",
2268
+ "application/avro",
2269
+ "application/vnd.iccprofile",
2270
+ "application/x-ft-fbx",
2271
+ "application/vnd.visio",
2272
+ "application/vnd.android.package-archive",
2273
+ "application/x-ft-draco",
2274
+ "application/x-lz4",
2275
+ // Informal, used by freedesktop.org shared-mime-info
2276
+ "application/vnd.openxmlformats-officedocument.presentationml.template",
2277
+ "application/vnd.openxmlformats-officedocument.spreadsheetml.template",
2278
+ "application/vnd.openxmlformats-officedocument.wordprocessingml.template",
2279
+ "application/vnd.ms-excel.template.macroenabled.12",
2280
+ "application/vnd.oasis.opendocument.text-template",
2281
+ "application/vnd.oasis.opendocument.spreadsheet-template",
2282
+ "application/vnd.oasis.opendocument.presentation-template",
2283
+ "application/vnd.oasis.opendocument.graphics",
2284
+ "application/vnd.oasis.opendocument.graphics-template",
2285
+ "application/vnd.ms-excel.sheet.macroenabled.12",
2286
+ "application/vnd.ms-word.document.macroenabled.12",
2287
+ "application/vnd.ms-word.template.macroenabled.12",
2288
+ "application/vnd.ms-powerpoint.template.macroenabled.12",
2289
+ "application/vnd.ms-powerpoint.presentation.macroenabled.12",
2290
+ "application/java-archive",
2291
+ "application/vnd.rn-realmedia",
2292
+ "application/x-spss-sav",
2293
+ "application/x-ms-regedit",
2294
+ "application/x-ft-windows-registry-hive",
2295
+ "application/x-jmp-data",
2296
+ "application/vnd.apple.keynote",
2297
+ "application/vnd.apple.numbers",
2298
+ "application/vnd.apple.pages"
2299
+ ];
2300
+
2301
+ // node_modules/file-type/source/parser.js
2302
+ var maximumUntrustedSkipSizeInBytes = 16 * 1024 * 1024;
2303
+ var ParserHardLimitError = class extends Error {
2304
+ };
2305
+ function getSafeBound(value, maximum, reason) {
2306
+ if (!Number.isFinite(value) || value < 0 || value > maximum) {
2307
+ throw new ParserHardLimitError(`${reason} has invalid size ${value} (maximum ${maximum} bytes)`);
2308
+ }
2309
+ return value;
2310
+ }
2311
+ async function safeIgnore(tokenizer, length, { maximumLength = maximumUntrustedSkipSizeInBytes, reason = "skip" } = {}) {
2312
+ const safeLength = getSafeBound(length, maximumLength, reason);
2313
+ await tokenizer.ignore(safeLength);
2314
+ }
2315
+ async function safeReadBuffer(tokenizer, buffer, options, { maximumLength = buffer.length, reason = "read" } = {}) {
2316
+ const length = options?.length ?? buffer.length;
2317
+ const safeLength = getSafeBound(length, maximumLength, reason);
2318
+ return tokenizer.readBuffer(buffer, {
2319
+ ...options,
2320
+ length: safeLength
2321
+ });
2322
+ }
2323
+ function checkBytes(buffer, headers, options) {
2324
+ options = {
2325
+ offset: 0,
2326
+ ...options
2327
+ };
2328
+ for (const [index, header] of headers.entries()) {
2329
+ if (options.mask) {
2330
+ if (header !== (options.mask[index] & buffer[index + options.offset])) {
2331
+ return false;
2332
+ }
2333
+ } else if (header !== buffer[index + options.offset]) {
2334
+ return false;
2335
+ }
2336
+ }
2337
+ return true;
2338
+ }
2339
+ function hasUnknownFileSize(tokenizer) {
2340
+ const fileSize = tokenizer.fileInfo.size;
2341
+ return !Number.isFinite(fileSize) || fileSize === Number.MAX_SAFE_INTEGER;
2342
+ }
2343
+ function hasExceededUnknownSizeScanBudget(tokenizer, startOffset, maximumBytes) {
2344
+ return hasUnknownFileSize(tokenizer) && tokenizer.position - startOffset > maximumBytes;
2345
+ }
2346
+
2347
+ // node_modules/file-type/source/detectors/zip.js
2348
+ var maximumZipEntrySizeInBytes = 1024 * 1024;
2349
+ var maximumZipEntryCount = 1024;
2350
+ var maximumZipBufferedReadSizeInBytes = 2 ** 31 - 1;
2351
+ var maximumZipTextEntrySizeInBytes = maximumZipEntrySizeInBytes;
2352
+ var recoverableZipErrorMessages = /* @__PURE__ */ new Set([
2353
+ "Unexpected signature",
2354
+ "Encrypted ZIP",
2355
+ "Expected Central-File-Header signature"
2356
+ ]);
2357
+ var recoverableZipErrorMessagePrefixes = [
2358
+ "ZIP entry count exceeds ",
2359
+ "Unsupported ZIP compression method:",
2360
+ "ZIP entry compressed data exceeds ",
2361
+ "ZIP entry decompressed data exceeds ",
2362
+ "Expected data-descriptor-signature at position "
2363
+ ];
2364
+ var recoverableZipErrorCodes = /* @__PURE__ */ new Set([
2365
+ "Z_BUF_ERROR",
2366
+ "Z_DATA_ERROR",
2367
+ "ERR_INVALID_STATE"
2368
+ ]);
2369
+ async function decompressDeflateRawWithLimit(data, { maximumLength = maximumZipEntrySizeInBytes } = {}) {
2370
+ const input = new ReadableStream({
2371
+ start(controller) {
2372
+ controller.enqueue(data);
2373
+ controller.close();
2374
+ }
2375
+ });
2376
+ const output = input.pipeThrough(new DecompressionStream("deflate-raw"));
2377
+ const reader = output.getReader();
2378
+ const chunks = [];
2379
+ let totalLength = 0;
2380
+ try {
2381
+ for (; ; ) {
2382
+ const { done, value } = await reader.read();
2383
+ if (done) {
2384
+ break;
2385
+ }
2386
+ totalLength += value.length;
2387
+ if (totalLength > maximumLength) {
2388
+ await reader.cancel();
2389
+ throw new Error(`ZIP entry decompressed data exceeds ${maximumLength} bytes`);
2390
+ }
2391
+ chunks.push(value);
2392
+ }
2393
+ } finally {
2394
+ reader.releaseLock();
2395
+ }
2396
+ const uncompressedData = new Uint8Array(totalLength);
2397
+ let offset = 0;
2398
+ for (const chunk of chunks) {
2399
+ uncompressedData.set(chunk, offset);
2400
+ offset += chunk.length;
2401
+ }
2402
+ return uncompressedData;
2403
+ }
2404
+ function mergeByteChunks(chunks, totalLength) {
2405
+ const merged = new Uint8Array(totalLength);
2406
+ let offset = 0;
2407
+ for (const chunk of chunks) {
2408
+ merged.set(chunk, offset);
2409
+ offset += chunk.length;
2410
+ }
2411
+ return merged;
2412
+ }
2413
+ function getMaximumZipBufferedReadLength(tokenizer) {
2414
+ const fileSize = tokenizer.fileInfo.size;
2415
+ const remainingBytes = Number.isFinite(fileSize) ? Math.max(0, fileSize - tokenizer.position) : Number.MAX_SAFE_INTEGER;
2416
+ return Math.min(remainingBytes, maximumZipBufferedReadSizeInBytes);
2417
+ }
2418
+ function isRecoverableZipError(error) {
2419
+ if (error instanceof EndOfStreamError) {
2420
+ return true;
2421
+ }
2422
+ if (error instanceof ParserHardLimitError) {
2423
+ return true;
2424
+ }
2425
+ if (!(error instanceof Error)) {
2426
+ return false;
2427
+ }
2428
+ if (recoverableZipErrorMessages.has(error.message)) {
2429
+ return true;
2430
+ }
2431
+ if (recoverableZipErrorCodes.has(error.code)) {
2432
+ return true;
2433
+ }
2434
+ for (const prefix of recoverableZipErrorMessagePrefixes) {
2435
+ if (error.message.startsWith(prefix)) {
2436
+ return true;
2437
+ }
2438
+ }
2439
+ return false;
2440
+ }
2441
+ function canReadZipEntryForDetection(zipHeader, maximumSize = maximumZipEntrySizeInBytes) {
2442
+ const sizes = [zipHeader.compressedSize, zipHeader.uncompressedSize];
2443
+ for (const size of sizes) {
2444
+ if (!Number.isFinite(size) || size < 0 || size > maximumSize) {
2445
+ return false;
2446
+ }
2447
+ }
2448
+ return true;
2449
+ }
2450
+ function createIWorkZipDetectionState() {
2451
+ return {
2452
+ hasDocumentEntry: false,
2453
+ hasMasterSlideEntry: false,
2454
+ hasTablesEntry: false,
2455
+ hasCalculationEngineEntry: false
2456
+ };
2457
+ }
2458
+ function updateIWorkZipDetectionStateFromFilename(iWorkState, filename) {
2459
+ if (filename === "Index/Document.iwa") {
2460
+ iWorkState.hasDocumentEntry = true;
2461
+ }
2462
+ if (filename.startsWith("Index/MasterSlide")) {
2463
+ iWorkState.hasMasterSlideEntry = true;
2464
+ }
2465
+ if (filename.startsWith("Index/Tables/")) {
2466
+ iWorkState.hasTablesEntry = true;
2467
+ }
2468
+ if (filename === "Index/CalculationEngine.iwa") {
2469
+ iWorkState.hasCalculationEngineEntry = true;
2470
+ }
2471
+ }
2472
+ function getIWorkFileTypeFromZipEntries(iWorkState) {
2473
+ if (!iWorkState.hasDocumentEntry) {
2474
+ return;
2475
+ }
2476
+ if (iWorkState.hasMasterSlideEntry) {
2477
+ return { ext: "key", mime: "application/vnd.apple.keynote" };
2478
+ }
2479
+ if (iWorkState.hasTablesEntry) {
2480
+ return { ext: "numbers", mime: "application/vnd.apple.numbers" };
2481
+ }
2482
+ return { ext: "pages", mime: "application/vnd.apple.pages" };
2483
+ }
2484
+ function getFileTypeFromMimeType(mimeType) {
2485
+ mimeType = mimeType.toLowerCase();
2486
+ switch (mimeType) {
2487
+ case "application/epub+zip":
2488
+ return { ext: "epub", mime: mimeType };
2489
+ case "application/vnd.oasis.opendocument.text":
2490
+ return { ext: "odt", mime: mimeType };
2491
+ case "application/vnd.oasis.opendocument.text-template":
2492
+ return { ext: "ott", mime: mimeType };
2493
+ case "application/vnd.oasis.opendocument.spreadsheet":
2494
+ return { ext: "ods", mime: mimeType };
2495
+ case "application/vnd.oasis.opendocument.spreadsheet-template":
2496
+ return { ext: "ots", mime: mimeType };
2497
+ case "application/vnd.oasis.opendocument.presentation":
2498
+ return { ext: "odp", mime: mimeType };
2499
+ case "application/vnd.oasis.opendocument.presentation-template":
2500
+ return { ext: "otp", mime: mimeType };
2501
+ case "application/vnd.oasis.opendocument.graphics":
2502
+ return { ext: "odg", mime: mimeType };
2503
+ case "application/vnd.oasis.opendocument.graphics-template":
2504
+ return { ext: "otg", mime: mimeType };
2505
+ case "application/vnd.openxmlformats-officedocument.presentationml.slideshow":
2506
+ return { ext: "ppsx", mime: mimeType };
2507
+ case "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":
2508
+ return { ext: "xlsx", mime: mimeType };
2509
+ case "application/vnd.ms-excel.sheet.macroenabled":
2510
+ return { ext: "xlsm", mime: "application/vnd.ms-excel.sheet.macroenabled.12" };
2511
+ case "application/vnd.openxmlformats-officedocument.spreadsheetml.template":
2512
+ return { ext: "xltx", mime: mimeType };
2513
+ case "application/vnd.ms-excel.template.macroenabled":
2514
+ return { ext: "xltm", mime: "application/vnd.ms-excel.template.macroenabled.12" };
2515
+ case "application/vnd.ms-powerpoint.slideshow.macroenabled":
2516
+ return { ext: "ppsm", mime: "application/vnd.ms-powerpoint.slideshow.macroenabled.12" };
2517
+ case "application/vnd.openxmlformats-officedocument.wordprocessingml.document":
2518
+ return { ext: "docx", mime: mimeType };
2519
+ case "application/vnd.ms-word.document.macroenabled":
2520
+ return { ext: "docm", mime: "application/vnd.ms-word.document.macroenabled.12" };
2521
+ case "application/vnd.openxmlformats-officedocument.wordprocessingml.template":
2522
+ return { ext: "dotx", mime: mimeType };
2523
+ case "application/vnd.ms-word.template.macroenabledtemplate":
2524
+ return { ext: "dotm", mime: "application/vnd.ms-word.template.macroenabled.12" };
2525
+ case "application/vnd.openxmlformats-officedocument.presentationml.template":
2526
+ return { ext: "potx", mime: mimeType };
2527
+ case "application/vnd.ms-powerpoint.template.macroenabled":
2528
+ return { ext: "potm", mime: "application/vnd.ms-powerpoint.template.macroenabled.12" };
2529
+ case "application/vnd.openxmlformats-officedocument.presentationml.presentation":
2530
+ return { ext: "pptx", mime: mimeType };
2531
+ case "application/vnd.ms-powerpoint.presentation.macroenabled":
2532
+ return { ext: "pptm", mime: "application/vnd.ms-powerpoint.presentation.macroenabled.12" };
2533
+ case "application/vnd.ms-visio.drawing":
2534
+ return { ext: "vsdx", mime: "application/vnd.visio" };
2535
+ case "application/vnd.ms-package.3dmanufacturing-3dmodel+xml":
2536
+ return { ext: "3mf", mime: "model/3mf" };
2537
+ default:
2538
+ }
2539
+ }
2540
+ function createOpenXmlZipDetectionState() {
2541
+ return {
2542
+ hasContentTypesEntry: false,
2543
+ hasParsedContentTypesEntry: false,
2544
+ isParsingContentTypes: false,
2545
+ hasUnparseableContentTypes: false,
2546
+ hasWordDirectory: false,
2547
+ hasPresentationDirectory: false,
2548
+ hasSpreadsheetDirectory: false,
2549
+ hasThreeDimensionalModelEntry: false
2550
+ };
2551
+ }
2552
+ function updateOpenXmlZipDetectionStateFromFilename(openXmlState, filename) {
2553
+ if (filename.startsWith("word/")) {
2554
+ openXmlState.hasWordDirectory = true;
2555
+ }
2556
+ if (filename.startsWith("ppt/")) {
2557
+ openXmlState.hasPresentationDirectory = true;
2558
+ }
2559
+ if (filename.startsWith("xl/")) {
2560
+ openXmlState.hasSpreadsheetDirectory = true;
2561
+ }
2562
+ if (filename.startsWith("3D/") && filename.endsWith(".model")) {
2563
+ openXmlState.hasThreeDimensionalModelEntry = true;
2564
+ }
2565
+ }
2566
+ function getOpenXmlFileTypeFromDirectoryNames(openXmlState) {
2567
+ if (openXmlState.hasWordDirectory) {
2568
+ return {
2569
+ ext: "docx",
2570
+ mime: "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
2571
+ };
2572
+ }
2573
+ if (openXmlState.hasPresentationDirectory) {
2574
+ return {
2575
+ ext: "pptx",
2576
+ mime: "application/vnd.openxmlformats-officedocument.presentationml.presentation"
2577
+ };
2578
+ }
2579
+ if (openXmlState.hasSpreadsheetDirectory) {
2580
+ return {
2581
+ ext: "xlsx",
2582
+ mime: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
2583
+ };
2584
+ }
2585
+ if (openXmlState.hasThreeDimensionalModelEntry) {
2586
+ return {
2587
+ ext: "3mf",
2588
+ mime: "model/3mf"
2589
+ };
2590
+ }
2591
+ }
2592
+ function getOpenXmlFileTypeFromZipEntries(openXmlState) {
2593
+ if (!openXmlState.hasContentTypesEntry || openXmlState.hasUnparseableContentTypes || openXmlState.isParsingContentTypes || openXmlState.hasParsedContentTypesEntry) {
2594
+ return;
2595
+ }
2596
+ return getOpenXmlFileTypeFromDirectoryNames(openXmlState);
2597
+ }
2598
+ function getOpenXmlMimeTypeFromContentTypesXml(xmlContent) {
2599
+ const endPosition = xmlContent.indexOf('.main+xml"');
2600
+ if (endPosition === -1) {
2601
+ const mimeType = "application/vnd.ms-package.3dmanufacturing-3dmodel+xml";
2602
+ if (xmlContent.includes(`ContentType="${mimeType}"`)) {
2603
+ return mimeType;
2604
+ }
2605
+ return;
2606
+ }
2607
+ const truncatedContent = xmlContent.slice(0, endPosition);
2608
+ const firstQuotePosition = truncatedContent.lastIndexOf('"');
2609
+ return truncatedContent.slice(firstQuotePosition + 1);
2610
+ }
2611
+ var zipDataDescriptorSignature = 134695760;
2612
+ var zipDataDescriptorLengthInBytes = 16;
2613
+ var zipDataDescriptorOverlapLengthInBytes = zipDataDescriptorLengthInBytes - 1;
2614
+ function findZipDataDescriptorOffset(buffer, bytesConsumed) {
2615
+ if (buffer.length < zipDataDescriptorLengthInBytes) {
2616
+ return -1;
2617
+ }
2618
+ const lastPossibleDescriptorOffset = buffer.length - zipDataDescriptorLengthInBytes;
2619
+ for (let index = 0; index <= lastPossibleDescriptorOffset; index++) {
2620
+ if (UINT32_LE.get(buffer, index) === zipDataDescriptorSignature && UINT32_LE.get(buffer, index + 8) === bytesConsumed + index) {
2621
+ return index;
2622
+ }
2623
+ }
2624
+ return -1;
2625
+ }
2626
+ async function readZipDataDescriptorEntryWithLimit(zipHandler, { shouldBuffer, maximumLength = maximumZipEntrySizeInBytes } = {}) {
2627
+ const { syncBuffer } = zipHandler;
2628
+ const { length: syncBufferLength } = syncBuffer;
2629
+ const chunks = [];
2630
+ let bytesConsumed = 0;
2631
+ for (; ; ) {
2632
+ const length = await zipHandler.tokenizer.peekBuffer(syncBuffer, { mayBeLess: true });
2633
+ const dataDescriptorOffset = findZipDataDescriptorOffset(syncBuffer.subarray(0, length), bytesConsumed);
2634
+ const retainedLength = dataDescriptorOffset >= 0 ? 0 : length === syncBufferLength ? Math.min(zipDataDescriptorOverlapLengthInBytes, length - 1) : 0;
2635
+ const chunkLength = dataDescriptorOffset >= 0 ? dataDescriptorOffset : length - retainedLength;
2636
+ if (chunkLength === 0) {
2637
+ break;
2638
+ }
2639
+ bytesConsumed += chunkLength;
2640
+ if (bytesConsumed > maximumLength) {
2641
+ throw new Error(`ZIP entry compressed data exceeds ${maximumLength} bytes`);
2642
+ }
2643
+ if (shouldBuffer) {
2644
+ const data = new Uint8Array(chunkLength);
2645
+ await zipHandler.tokenizer.readBuffer(data);
2646
+ chunks.push(data);
2647
+ } else {
2648
+ await zipHandler.tokenizer.ignore(chunkLength);
2649
+ }
2650
+ if (dataDescriptorOffset >= 0) {
2651
+ break;
2652
+ }
2653
+ }
2654
+ if (!hasUnknownFileSize(zipHandler.tokenizer)) {
2655
+ zipHandler.knownSizeDescriptorScannedBytes += bytesConsumed;
2656
+ }
2657
+ if (!shouldBuffer) {
2658
+ return;
2659
+ }
2660
+ return mergeByteChunks(chunks, bytesConsumed);
2661
+ }
2662
+ function getRemainingZipScanBudget(zipHandler, startOffset) {
2663
+ if (hasUnknownFileSize(zipHandler.tokenizer)) {
2664
+ return Math.max(0, maximumUntrustedSkipSizeInBytes - (zipHandler.tokenizer.position - startOffset));
2665
+ }
2666
+ return Math.max(0, maximumZipEntrySizeInBytes - zipHandler.knownSizeDescriptorScannedBytes);
2667
+ }
2668
+ async function readZipEntryData(zipHandler, zipHeader, { shouldBuffer, maximumDescriptorLength = maximumZipEntrySizeInBytes } = {}) {
2669
+ if (zipHeader.dataDescriptor && zipHeader.compressedSize === 0) {
2670
+ return readZipDataDescriptorEntryWithLimit(zipHandler, {
2671
+ shouldBuffer,
2672
+ maximumLength: maximumDescriptorLength
2673
+ });
2674
+ }
2675
+ if (!shouldBuffer) {
2676
+ await safeIgnore(zipHandler.tokenizer, zipHeader.compressedSize, {
2677
+ maximumLength: hasUnknownFileSize(zipHandler.tokenizer) ? maximumZipEntrySizeInBytes : zipHandler.tokenizer.fileInfo.size,
2678
+ reason: "ZIP entry compressed data"
2679
+ });
2680
+ return;
2681
+ }
2682
+ const maximumLength = getMaximumZipBufferedReadLength(zipHandler.tokenizer);
2683
+ if (!Number.isFinite(zipHeader.compressedSize) || zipHeader.compressedSize < 0 || zipHeader.compressedSize > maximumLength) {
2684
+ throw new Error(`ZIP entry compressed data exceeds ${maximumLength} bytes`);
2685
+ }
2686
+ const fileData = new Uint8Array(zipHeader.compressedSize);
2687
+ await zipHandler.tokenizer.readBuffer(fileData);
2688
+ return fileData;
2689
+ }
2690
+ ZipHandler.prototype.inflate = async function(zipHeader, fileData, callback) {
2691
+ if (zipHeader.compressedMethod === 0) {
2692
+ return callback(fileData);
2693
+ }
2694
+ if (zipHeader.compressedMethod !== 8) {
2695
+ throw new Error(`Unsupported ZIP compression method: ${zipHeader.compressedMethod}`);
2696
+ }
2697
+ const uncompressedData = await decompressDeflateRawWithLimit(fileData, { maximumLength: maximumZipEntrySizeInBytes });
2698
+ return callback(uncompressedData);
2699
+ };
2700
+ ZipHandler.prototype.unzip = async function(fileCallback) {
2701
+ let stop = false;
2702
+ let zipEntryCount = 0;
2703
+ const zipScanStart = this.tokenizer.position;
2704
+ this.knownSizeDescriptorScannedBytes = 0;
2705
+ do {
2706
+ if (hasExceededUnknownSizeScanBudget(this.tokenizer, zipScanStart, maximumUntrustedSkipSizeInBytes)) {
2707
+ throw new ParserHardLimitError(`ZIP stream probing exceeds ${maximumUntrustedSkipSizeInBytes} bytes`);
2708
+ }
2709
+ const zipHeader = await this.readLocalFileHeader();
2710
+ if (!zipHeader) {
2711
+ break;
2712
+ }
2713
+ zipEntryCount++;
2714
+ if (zipEntryCount > maximumZipEntryCount) {
2715
+ throw new Error(`ZIP entry count exceeds ${maximumZipEntryCount}`);
2716
+ }
2717
+ const next = fileCallback(zipHeader);
2718
+ stop = Boolean(next.stop);
2719
+ await this.tokenizer.ignore(zipHeader.extraFieldLength);
2720
+ const fileData = await readZipEntryData(this, zipHeader, {
2721
+ shouldBuffer: Boolean(next.handler),
2722
+ maximumDescriptorLength: Math.min(maximumZipEntrySizeInBytes, getRemainingZipScanBudget(this, zipScanStart))
2723
+ });
2724
+ if (next.handler) {
2725
+ await this.inflate(zipHeader, fileData, next.handler);
2726
+ }
2727
+ if (zipHeader.dataDescriptor) {
2728
+ const dataDescriptor = new Uint8Array(zipDataDescriptorLengthInBytes);
2729
+ await this.tokenizer.readBuffer(dataDescriptor);
2730
+ if (UINT32_LE.get(dataDescriptor, 0) !== zipDataDescriptorSignature) {
2731
+ throw new Error(`Expected data-descriptor-signature at position ${this.tokenizer.position - dataDescriptor.length}`);
2732
+ }
2733
+ }
2734
+ if (hasExceededUnknownSizeScanBudget(this.tokenizer, zipScanStart, maximumUntrustedSkipSizeInBytes)) {
2735
+ throw new ParserHardLimitError(`ZIP stream probing exceeds ${maximumUntrustedSkipSizeInBytes} bytes`);
2736
+ }
2737
+ } while (!stop);
2738
+ };
2739
+ async function detectZip(tokenizer) {
2740
+ let fileType;
2741
+ const openXmlState = createOpenXmlZipDetectionState();
2742
+ const iWorkState = createIWorkZipDetectionState();
2743
+ try {
2744
+ await new ZipHandler(tokenizer).unzip((zipHeader) => {
2745
+ updateOpenXmlZipDetectionStateFromFilename(openXmlState, zipHeader.filename);
2746
+ updateIWorkZipDetectionStateFromFilename(iWorkState, zipHeader.filename);
2747
+ if (iWorkState.hasDocumentEntry && (iWorkState.hasMasterSlideEntry || iWorkState.hasTablesEntry)) {
2748
+ fileType = getIWorkFileTypeFromZipEntries(iWorkState);
2749
+ return { stop: true };
2750
+ }
2751
+ const isOpenXmlContentTypesEntry = zipHeader.filename === "[Content_Types].xml";
2752
+ const openXmlFileTypeFromEntries = getOpenXmlFileTypeFromZipEntries(openXmlState);
2753
+ if (!isOpenXmlContentTypesEntry && openXmlFileTypeFromEntries) {
2754
+ fileType = openXmlFileTypeFromEntries;
2755
+ return {
2756
+ stop: true
2757
+ };
2758
+ }
2759
+ switch (zipHeader.filename) {
2760
+ case "META-INF/mozilla.rsa":
2761
+ fileType = {
2762
+ ext: "xpi",
2763
+ mime: "application/x-xpinstall"
2764
+ };
2765
+ return {
2766
+ stop: true
2767
+ };
2768
+ case "META-INF/MANIFEST.MF":
2769
+ fileType = {
2770
+ ext: "jar",
2771
+ mime: "application/java-archive"
2772
+ };
2773
+ return {
2774
+ stop: true
2775
+ };
2776
+ case "mimetype":
2777
+ if (!canReadZipEntryForDetection(zipHeader, maximumZipTextEntrySizeInBytes)) {
2778
+ return {};
2779
+ }
2780
+ return {
2781
+ async handler(fileData) {
2782
+ const mimeType = new TextDecoder("utf-8").decode(fileData).trim();
2783
+ fileType = getFileTypeFromMimeType(mimeType);
2784
+ },
2785
+ stop: true
2786
+ };
2787
+ case "[Content_Types].xml": {
2788
+ openXmlState.hasContentTypesEntry = true;
2789
+ if (!canReadZipEntryForDetection(zipHeader, maximumZipTextEntrySizeInBytes)) {
2790
+ openXmlState.hasUnparseableContentTypes = true;
2791
+ return {};
2792
+ }
2793
+ openXmlState.isParsingContentTypes = true;
2794
+ return {
2795
+ async handler(fileData) {
2796
+ const xmlContent = new TextDecoder("utf-8").decode(fileData);
2797
+ const mimeType = getOpenXmlMimeTypeFromContentTypesXml(xmlContent);
2798
+ if (mimeType) {
2799
+ fileType = getFileTypeFromMimeType(mimeType);
2800
+ }
2801
+ openXmlState.hasParsedContentTypesEntry = true;
2802
+ openXmlState.isParsingContentTypes = false;
2803
+ },
2804
+ stop: true
2805
+ };
2806
+ }
2807
+ default:
2808
+ if (/classes\d*\.dex/v.test(zipHeader.filename)) {
2809
+ fileType = {
2810
+ ext: "apk",
2811
+ mime: "application/vnd.android.package-archive"
2812
+ };
2813
+ return { stop: true };
2814
+ }
2815
+ return {};
2816
+ }
2817
+ });
2818
+ } catch (error) {
2819
+ if (!isRecoverableZipError(error)) {
2820
+ throw error;
2821
+ }
2822
+ if (openXmlState.isParsingContentTypes) {
2823
+ openXmlState.isParsingContentTypes = false;
2824
+ openXmlState.hasUnparseableContentTypes = true;
2825
+ }
2826
+ if (!fileType && error instanceof EndOfStreamError && !openXmlState.hasContentTypesEntry) {
2827
+ fileType = getOpenXmlFileTypeFromDirectoryNames(openXmlState);
2828
+ }
2829
+ }
2830
+ const iWorkFileType = hasUnknownFileSize(tokenizer) && iWorkState.hasDocumentEntry && !iWorkState.hasMasterSlideEntry && !iWorkState.hasTablesEntry && !iWorkState.hasCalculationEngineEntry ? void 0 : getIWorkFileTypeFromZipEntries(iWorkState);
2831
+ return fileType ?? getOpenXmlFileTypeFromZipEntries(openXmlState) ?? iWorkFileType ?? {
2832
+ ext: "zip",
2833
+ mime: "application/zip"
2834
+ };
2835
+ }
2836
+
2837
+ // node_modules/file-type/source/detectors/ebml.js
2838
+ var maximumEbmlDocumentTypeSizeInBytes = 64;
2839
+ var maximumEbmlElementPayloadSizeInBytes = 1024 * 1024;
2840
+ var maximumEbmlElementCount = 256;
2841
+ async function detectEbml(tokenizer) {
2842
+ async function readField() {
2843
+ const msb = await tokenizer.peekNumber(UINT8);
2844
+ let mask = 128;
2845
+ let ic = 0;
2846
+ while ((msb & mask) === 0 && mask !== 0) {
2847
+ ++ic;
2848
+ mask >>= 1;
2849
+ }
2850
+ const id = new Uint8Array(ic + 1);
2851
+ await safeReadBuffer(tokenizer, id, void 0, {
2852
+ maximumLength: id.length,
2853
+ reason: "EBML field"
2854
+ });
2855
+ return id;
2856
+ }
2857
+ async function readElement() {
2858
+ const idField = await readField();
2859
+ const lengthField = await readField();
2860
+ lengthField[0] ^= 128 >> lengthField.length - 1;
2861
+ const nrLength = Math.min(6, lengthField.length);
2862
+ const idView = new DataView(idField.buffer);
2863
+ const lengthView = new DataView(lengthField.buffer, lengthField.length - nrLength, nrLength);
2864
+ return {
2865
+ id: getUintBE(idView),
2866
+ len: getUintBE(lengthView)
2867
+ };
2868
+ }
2869
+ async function readChildren(children) {
2870
+ let ebmlElementCount = 0;
2871
+ while (children > 0) {
2872
+ ebmlElementCount++;
2873
+ if (ebmlElementCount > maximumEbmlElementCount) {
2874
+ return;
2875
+ }
2876
+ if (hasExceededUnknownSizeScanBudget(tokenizer, ebmlScanStart, maximumUntrustedSkipSizeInBytes)) {
2877
+ return;
2878
+ }
2879
+ const previousPosition = tokenizer.position;
2880
+ const element = await readElement();
2881
+ if (element.id === 17026) {
2882
+ if (element.len > maximumEbmlDocumentTypeSizeInBytes) {
2883
+ return;
2884
+ }
2885
+ const documentTypeLength = getSafeBound(element.len, maximumEbmlDocumentTypeSizeInBytes, "EBML DocType");
2886
+ const rawValue = await tokenizer.readToken(new StringType(documentTypeLength));
2887
+ return rawValue.replaceAll(/\0.*$/gv, "");
2888
+ }
2889
+ if (hasUnknownFileSize(tokenizer) && (!Number.isFinite(element.len) || element.len < 0 || element.len > maximumEbmlElementPayloadSizeInBytes)) {
2890
+ return;
2891
+ }
2892
+ await safeIgnore(tokenizer, element.len, {
2893
+ maximumLength: hasUnknownFileSize(tokenizer) ? maximumEbmlElementPayloadSizeInBytes : tokenizer.fileInfo.size,
2894
+ reason: "EBML payload"
2895
+ });
2896
+ --children;
2897
+ if (tokenizer.position <= previousPosition) {
2898
+ return;
2899
+ }
2900
+ }
2901
+ }
2902
+ const rootElement = await readElement();
2903
+ const ebmlScanStart = tokenizer.position;
2904
+ const documentType = await readChildren(rootElement.len);
2905
+ switch (documentType) {
2906
+ case "webm":
2907
+ return {
2908
+ ext: "webm",
2909
+ mime: "video/webm"
2910
+ };
2911
+ case "matroska":
2912
+ return {
2913
+ ext: "mkv",
2914
+ mime: "video/matroska"
2915
+ };
2916
+ default:
2917
+ }
2918
+ }
2919
+
2920
+ // node_modules/file-type/source/detectors/png.js
2921
+ var maximumPngChunkCount = 512;
2922
+ var maximumPngStreamScanBudgetInBytes = 16 * 1024 * 1024;
2923
+ var maximumPngChunkSizeInBytes = 1024 * 1024;
2924
+ function isPngAncillaryChunk(type) {
2925
+ return (type.codePointAt(0) & 32) !== 0;
2926
+ }
2927
+ async function detectPng(tokenizer) {
2928
+ const pngFileType = {
2929
+ ext: "png",
2930
+ mime: "image/png"
2931
+ };
2932
+ const apngFileType = {
2933
+ ext: "apng",
2934
+ mime: "image/apng"
2935
+ };
2936
+ await tokenizer.ignore(8);
2937
+ async function readChunkHeader() {
2938
+ return {
2939
+ length: await tokenizer.readToken(INT32_BE),
2940
+ type: await tokenizer.readToken(new StringType(4, "latin1"))
2941
+ };
2942
+ }
2943
+ const isUnknownPngStream = hasUnknownFileSize(tokenizer);
2944
+ const pngScanStart = tokenizer.position;
2945
+ let pngChunkCount = 0;
2946
+ let hasSeenImageHeader = false;
2947
+ do {
2948
+ pngChunkCount++;
2949
+ if (pngChunkCount > maximumPngChunkCount) {
2950
+ break;
2951
+ }
2952
+ if (hasExceededUnknownSizeScanBudget(tokenizer, pngScanStart, maximumPngStreamScanBudgetInBytes)) {
2953
+ break;
2954
+ }
2955
+ const previousPosition = tokenizer.position;
2956
+ const chunk = await readChunkHeader();
2957
+ if (chunk.length < 0) {
2958
+ return;
2959
+ }
2960
+ if (chunk.type === "IHDR") {
2961
+ if (chunk.length !== 13) {
2962
+ return;
2963
+ }
2964
+ hasSeenImageHeader = true;
2965
+ }
2966
+ switch (chunk.type) {
2967
+ case "IDAT":
2968
+ return pngFileType;
2969
+ case "acTL":
2970
+ return apngFileType;
2971
+ default:
2972
+ if (!hasSeenImageHeader && chunk.type !== "CgBI") {
2973
+ return;
2974
+ }
2975
+ if (isUnknownPngStream && chunk.length > maximumPngChunkSizeInBytes) {
2976
+ return hasSeenImageHeader && isPngAncillaryChunk(chunk.type) ? pngFileType : void 0;
2977
+ }
2978
+ try {
2979
+ await safeIgnore(tokenizer, chunk.length + 4, {
2980
+ maximumLength: isUnknownPngStream ? maximumPngChunkSizeInBytes + 4 : tokenizer.fileInfo.size,
2981
+ reason: "PNG chunk payload"
2982
+ });
2983
+ } catch (error) {
2984
+ if (!isUnknownPngStream && (error instanceof ParserHardLimitError || error instanceof EndOfStreamError)) {
2985
+ return pngFileType;
2986
+ }
2987
+ throw error;
2988
+ }
2989
+ }
2990
+ if (tokenizer.position <= previousPosition) {
2991
+ break;
2992
+ }
2993
+ } while (tokenizer.position + 8 < tokenizer.fileInfo.size);
2994
+ return pngFileType;
2995
+ }
2996
+
2997
+ // node_modules/file-type/source/detectors/asf.js
2998
+ var maximumAsfHeaderObjectCount = 512;
2999
+ var maximumAsfHeaderPayloadSizeInBytes = 1024 * 1024;
3000
+ async function detectAsf(tokenizer) {
3001
+ let isMalformedAsf = false;
3002
+ try {
3003
+ async function readHeader() {
3004
+ const guid = new Uint8Array(16);
3005
+ await safeReadBuffer(tokenizer, guid, void 0, {
3006
+ maximumLength: guid.length,
3007
+ reason: "ASF header GUID"
3008
+ });
3009
+ return {
3010
+ id: guid,
3011
+ size: Number(await tokenizer.readToken(UINT64_LE))
3012
+ };
3013
+ }
3014
+ await safeIgnore(tokenizer, 30, {
3015
+ maximumLength: 30,
3016
+ reason: "ASF header prelude"
3017
+ });
3018
+ const isUnknownFileSize = hasUnknownFileSize(tokenizer);
3019
+ const asfHeaderScanStart = tokenizer.position;
3020
+ let asfHeaderObjectCount = 0;
3021
+ while (tokenizer.position + 24 < tokenizer.fileInfo.size) {
3022
+ asfHeaderObjectCount++;
3023
+ if (asfHeaderObjectCount > maximumAsfHeaderObjectCount) {
3024
+ break;
3025
+ }
3026
+ if (hasExceededUnknownSizeScanBudget(tokenizer, asfHeaderScanStart, maximumUntrustedSkipSizeInBytes)) {
3027
+ break;
3028
+ }
3029
+ const previousPosition = tokenizer.position;
3030
+ const header = await readHeader();
3031
+ let payload = header.size - 24;
3032
+ if (!Number.isFinite(payload) || payload < 0) {
3033
+ isMalformedAsf = true;
3034
+ break;
3035
+ }
3036
+ if (checkBytes(header.id, [145, 7, 220, 183, 183, 169, 207, 17, 142, 230, 0, 192, 12, 32, 83, 101])) {
3037
+ const typeId = new Uint8Array(16);
3038
+ payload -= await safeReadBuffer(tokenizer, typeId, void 0, {
3039
+ maximumLength: typeId.length,
3040
+ reason: "ASF stream type GUID"
3041
+ });
3042
+ if (checkBytes(typeId, [64, 158, 105, 248, 77, 91, 207, 17, 168, 253, 0, 128, 95, 92, 68, 43])) {
3043
+ return {
3044
+ ext: "asf",
3045
+ mime: "audio/x-ms-asf"
3046
+ };
3047
+ }
3048
+ if (checkBytes(typeId, [192, 239, 25, 188, 77, 91, 207, 17, 168, 253, 0, 128, 95, 92, 68, 43])) {
3049
+ return {
3050
+ ext: "asf",
3051
+ mime: "video/x-ms-asf"
3052
+ };
3053
+ }
3054
+ break;
3055
+ }
3056
+ if (isUnknownFileSize && payload > maximumAsfHeaderPayloadSizeInBytes) {
3057
+ isMalformedAsf = true;
3058
+ break;
3059
+ }
3060
+ await safeIgnore(tokenizer, payload, {
3061
+ maximumLength: isUnknownFileSize ? maximumAsfHeaderPayloadSizeInBytes : tokenizer.fileInfo.size,
3062
+ reason: "ASF header payload"
3063
+ });
3064
+ if (tokenizer.position <= previousPosition) {
3065
+ isMalformedAsf = true;
3066
+ break;
3067
+ }
3068
+ }
3069
+ } catch (error) {
3070
+ if (error instanceof EndOfStreamError || error instanceof ParserHardLimitError) {
3071
+ if (hasUnknownFileSize(tokenizer)) {
3072
+ isMalformedAsf = true;
3073
+ }
3074
+ } else {
3075
+ throw error;
3076
+ }
3077
+ }
3078
+ if (isMalformedAsf) {
3079
+ return;
3080
+ }
3081
+ return {
3082
+ ext: "asf",
3083
+ mime: "application/vnd.ms-asf"
3084
+ };
3085
+ }
3086
+
3087
+ // node_modules/file-type/source/index.js
3088
+ var reasonableDetectionSizeInBytes = 4100;
3089
+ var maximumMpegOffsetTolerance = reasonableDetectionSizeInBytes - 2;
3090
+ var maximumNestedGzipDetectionSizeInBytes = maximumUntrustedSkipSizeInBytes;
3091
+ var maximumNestedGzipProbeDepth = 1;
3092
+ var unknownSizeGzipProbeTimeoutInMilliseconds = 100;
3093
+ var maximumId3HeaderSizeInBytes = maximumUntrustedSkipSizeInBytes;
3094
+ var maximumTiffTagCount = 512;
3095
+ var maximumDetectionReentryCount = 256;
3096
+ var maximumTiffStreamIfdOffsetInBytes = 1024 * 1024;
3097
+ var maximumTiffIfdOffsetInBytes = maximumUntrustedSkipSizeInBytes;
3098
+ function normalizeSampleSize(sampleSize) {
3099
+ if (!Number.isFinite(sampleSize)) {
3100
+ return reasonableDetectionSizeInBytes;
3101
+ }
3102
+ return Math.max(1, Math.trunc(sampleSize));
3103
+ }
3104
+ function normalizeMpegOffsetTolerance(mpegOffsetTolerance) {
3105
+ if (!Number.isFinite(mpegOffsetTolerance)) {
3106
+ return 0;
3107
+ }
3108
+ return Math.max(0, Math.min(maximumMpegOffsetTolerance, Math.trunc(mpegOffsetTolerance)));
3109
+ }
3110
+ function getKnownFileSizeOrMaximum(fileSize) {
3111
+ if (!Number.isFinite(fileSize)) {
3112
+ return Number.MAX_SAFE_INTEGER;
3113
+ }
3114
+ return Math.max(0, fileSize);
3115
+ }
3116
+ function importAtRuntime(specifier) {
3117
+ return import(specifier);
3118
+ }
3119
+ function toDefaultStream(stream) {
3120
+ return stream.pipeThrough(new TransformStream());
3121
+ }
3122
+ function readWithSignal(reader, signal) {
3123
+ if (signal === void 0) {
3124
+ return reader.read();
3125
+ }
3126
+ signal.throwIfAborted();
3127
+ return Promise.race([
3128
+ reader.read(),
3129
+ new Promise((_resolve, reject) => {
3130
+ signal.addEventListener("abort", () => {
3131
+ reject(signal.reason);
3132
+ reader.cancel(signal.reason).catch(() => {
3133
+ });
3134
+ }, { once: true });
3135
+ })
3136
+ ]);
3137
+ }
3138
+ function createByteLimitedReadableStream(stream, maximumBytes) {
3139
+ const reader = stream.getReader();
3140
+ let emittedBytes = 0;
3141
+ let sourceDone = false;
3142
+ let sourceCanceled = false;
3143
+ const cancelSource = async (reason) => {
3144
+ if (sourceDone || sourceCanceled) {
3145
+ return;
3146
+ }
3147
+ sourceCanceled = true;
3148
+ await reader.cancel(reason);
3149
+ };
3150
+ return new ReadableStream({
3151
+ async pull(controller) {
3152
+ if (emittedBytes >= maximumBytes) {
3153
+ controller.close();
3154
+ await cancelSource();
3155
+ return;
3156
+ }
3157
+ const { done, value } = await reader.read();
3158
+ if (done || !value) {
3159
+ sourceDone = true;
3160
+ controller.close();
3161
+ return;
3162
+ }
3163
+ const remainingBytes = maximumBytes - emittedBytes;
3164
+ if (value.length > remainingBytes) {
3165
+ controller.enqueue(value.subarray(0, remainingBytes));
3166
+ emittedBytes += remainingBytes;
3167
+ controller.close();
3168
+ await cancelSource();
3169
+ return;
3170
+ }
3171
+ controller.enqueue(value);
3172
+ emittedBytes += value.length;
3173
+ },
3174
+ async cancel(reason) {
3175
+ await cancelSource(reason);
3176
+ }
3177
+ });
3178
+ }
3179
+ async function fileTypeFromBuffer(input, options) {
3180
+ return new FileTypeParser(options).fromBuffer(input);
3181
+ }
3182
+ var FileTypeParser = class _FileTypeParser {
3183
+ constructor(options) {
3184
+ const normalizedMpegOffsetTolerance = normalizeMpegOffsetTolerance(options?.mpegOffsetTolerance);
3185
+ this.options = {
3186
+ ...options,
3187
+ mpegOffsetTolerance: normalizedMpegOffsetTolerance
3188
+ };
3189
+ this.detectors = [
3190
+ ...this.options.customDetectors ?? [],
3191
+ { id: "core", detect: this.detectConfident },
3192
+ { id: "core.imprecise", detect: this.detectImprecise }
3193
+ ];
3194
+ this.tokenizerOptions = {
3195
+ abortSignal: this.options.signal
3196
+ };
3197
+ this.gzipProbeDepth = 0;
3198
+ }
3199
+ getTokenizerOptions() {
3200
+ return {
3201
+ ...this.tokenizerOptions
3202
+ };
3203
+ }
3204
+ createTokenizerFromWebStream(stream) {
3205
+ return fromWebStream(toDefaultStream(stream), this.getTokenizerOptions());
3206
+ }
3207
+ async parseTokenizer(tokenizer, detectionReentryCount = 0) {
3208
+ this.detectionReentryCount = detectionReentryCount;
3209
+ const initialPosition = tokenizer.position;
3210
+ for (const detector of this.detectors) {
3211
+ let fileType;
3212
+ try {
3213
+ fileType = await detector.detect(tokenizer);
3214
+ } catch (error) {
3215
+ if (error instanceof EndOfStreamError) {
3216
+ return;
3217
+ }
3218
+ if (error instanceof ParserHardLimitError) {
3219
+ return;
3220
+ }
3221
+ throw error;
3222
+ }
3223
+ if (fileType) {
3224
+ return fileType;
3225
+ }
3226
+ if (initialPosition !== tokenizer.position) {
3227
+ return void 0;
3228
+ }
3229
+ }
3230
+ }
3231
+ async fromTokenizer(tokenizer) {
3232
+ try {
3233
+ return await this.parseTokenizer(tokenizer);
3234
+ } finally {
3235
+ await tokenizer.close();
3236
+ }
3237
+ }
3238
+ async fromBuffer(input) {
3239
+ if (!(input instanceof Uint8Array || input instanceof ArrayBuffer)) {
3240
+ throw new TypeError(`Expected the \`input\` argument to be of type \`Uint8Array\` or \`ArrayBuffer\`, got \`${typeof input}\``);
3241
+ }
3242
+ const buffer = input instanceof Uint8Array ? input : new Uint8Array(input);
3243
+ if (!(buffer?.length > 1)) {
3244
+ return;
3245
+ }
3246
+ return this.fromTokenizer(fromBuffer(buffer, this.getTokenizerOptions()));
3247
+ }
3248
+ async fromBlob(blob) {
3249
+ this.options.signal?.throwIfAborted();
3250
+ const tokenizer = fromBlob(blob, this.getTokenizerOptions());
3251
+ return this.fromTokenizer(tokenizer);
3252
+ }
3253
+ async fromStream(stream) {
3254
+ this.options.signal?.throwIfAborted();
3255
+ const tokenizer = this.createTokenizerFromWebStream(stream);
3256
+ return this.fromTokenizer(tokenizer);
3257
+ }
3258
+ async fromFile(path) {
3259
+ this.options.signal?.throwIfAborted();
3260
+ const [{ default: fsPromises }, { FileTokenizer }] = await Promise.all([
3261
+ importAtRuntime("node:fs/promises"),
3262
+ importAtRuntime("strtok3")
3263
+ ]);
3264
+ const fileHandle = await fsPromises.open(path, fsPromises.constants.O_RDONLY | fsPromises.constants.O_NONBLOCK);
3265
+ const fileStat = await fileHandle.stat();
3266
+ if (!fileStat.isFile()) {
3267
+ await fileHandle.close();
3268
+ return;
3269
+ }
3270
+ const tokenizer = new FileTokenizer(fileHandle, {
3271
+ ...this.getTokenizerOptions(),
3272
+ fileInfo: { path, size: fileStat.size }
3273
+ });
3274
+ return this.fromTokenizer(tokenizer);
3275
+ }
3276
+ async toDetectionStream(stream, options) {
3277
+ this.options.signal?.throwIfAborted();
3278
+ const sampleSize = normalizeSampleSize(options?.sampleSize ?? reasonableDetectionSizeInBytes);
3279
+ let detectedFileType;
3280
+ let streamEnded = false;
3281
+ const reader = stream.getReader();
3282
+ const chunks = [];
3283
+ let totalSize = 0;
3284
+ try {
3285
+ while (totalSize < sampleSize) {
3286
+ const { value, done } = await readWithSignal(reader, this.options.signal);
3287
+ if (done || !value) {
3288
+ streamEnded = true;
3289
+ break;
3290
+ }
3291
+ chunks.push(value);
3292
+ totalSize += value.length;
3293
+ }
3294
+ if (!streamEnded && totalSize === sampleSize) {
3295
+ const { value, done } = await readWithSignal(reader, this.options.signal);
3296
+ if (done || !value) {
3297
+ streamEnded = true;
3298
+ } else {
3299
+ chunks.push(value);
3300
+ totalSize += value.length;
3301
+ }
3302
+ }
3303
+ } finally {
3304
+ reader.releaseLock();
3305
+ }
3306
+ if (totalSize > 0) {
3307
+ const sample = chunks.length === 1 ? chunks[0] : concatUint8Arrays(chunks);
3308
+ try {
3309
+ detectedFileType = await this.fromBuffer(sample.subarray(0, sampleSize));
3310
+ } catch (error) {
3311
+ if (!(error instanceof EndOfStreamError)) {
3312
+ throw error;
3313
+ }
3314
+ detectedFileType = void 0;
3315
+ }
3316
+ if (!streamEnded && detectedFileType?.ext === "pages") {
3317
+ detectedFileType = {
3318
+ ext: "zip",
3319
+ mime: "application/zip"
3320
+ };
3321
+ }
3322
+ }
3323
+ const transformStream = new TransformStream({
3324
+ start(controller) {
3325
+ for (const chunk of chunks) {
3326
+ controller.enqueue(chunk);
3327
+ }
3328
+ },
3329
+ transform(chunk, controller) {
3330
+ controller.enqueue(chunk);
3331
+ }
3332
+ });
3333
+ const newStream = stream.pipeThrough(transformStream);
3334
+ newStream.fileType = detectedFileType;
3335
+ return newStream;
3336
+ }
3337
+ async detectGzip(tokenizer) {
3338
+ if (this.gzipProbeDepth >= maximumNestedGzipProbeDepth) {
3339
+ return {
3340
+ ext: "gz",
3341
+ mime: "application/gzip"
3342
+ };
3343
+ }
3344
+ const gzipHandler = new GzipHandler(tokenizer);
3345
+ const limitedInflatedStream = createByteLimitedReadableStream(gzipHandler.inflate(), maximumNestedGzipDetectionSizeInBytes);
3346
+ const hasUnknownSize = hasUnknownFileSize(tokenizer);
3347
+ let timeout;
3348
+ let probeSignal;
3349
+ let probeParser;
3350
+ let compressedFileType;
3351
+ if (hasUnknownSize) {
3352
+ const timeoutController = new AbortController();
3353
+ timeout = setTimeout(() => {
3354
+ timeoutController.abort(new DOMException(`Operation timed out after ${unknownSizeGzipProbeTimeoutInMilliseconds} ms`, "TimeoutError"));
3355
+ }, unknownSizeGzipProbeTimeoutInMilliseconds);
3356
+ probeSignal = this.options.signal === void 0 ? timeoutController.signal : AbortSignal.any([this.options.signal, timeoutController.signal]);
3357
+ probeParser = new _FileTypeParser({
3358
+ ...this.options,
3359
+ signal: probeSignal
3360
+ });
3361
+ probeParser.gzipProbeDepth = this.gzipProbeDepth + 1;
3362
+ } else {
3363
+ this.gzipProbeDepth++;
3364
+ }
3365
+ try {
3366
+ compressedFileType = await (probeParser ?? this).fromStream(limitedInflatedStream);
3367
+ } catch (error) {
3368
+ if (error?.name === "AbortError" && probeSignal?.reason?.name !== "TimeoutError") {
3369
+ throw error;
3370
+ }
3371
+ } finally {
3372
+ clearTimeout(timeout);
3373
+ if (!hasUnknownSize) {
3374
+ this.gzipProbeDepth--;
3375
+ }
3376
+ }
3377
+ if (compressedFileType?.ext === "tar") {
3378
+ return {
3379
+ ext: "tar.gz",
3380
+ mime: "application/gzip"
3381
+ };
3382
+ }
3383
+ return {
3384
+ ext: "gz",
3385
+ mime: "application/gzip"
3386
+ };
3387
+ }
3388
+ check(header, options) {
3389
+ return checkBytes(this.buffer, header, options);
3390
+ }
3391
+ checkString(header, options) {
3392
+ return this.check(stringToBytes(header, options?.encoding), options);
3393
+ }
3394
+ // Detections with a high degree of certainty in identifying the correct file type
3395
+ detectConfident = async (tokenizer) => {
3396
+ this.buffer = new Uint8Array(reasonableDetectionSizeInBytes);
3397
+ if (tokenizer.fileInfo.size === void 0) {
3398
+ tokenizer.fileInfo.size = Number.MAX_SAFE_INTEGER;
3399
+ }
3400
+ this.tokenizer = tokenizer;
3401
+ if (hasUnknownFileSize(tokenizer)) {
3402
+ await tokenizer.peekBuffer(this.buffer, { length: 3, mayBeLess: true });
3403
+ if (this.check([31, 139, 8])) {
3404
+ return this.detectGzip(tokenizer);
3405
+ }
3406
+ }
3407
+ await tokenizer.peekBuffer(this.buffer, { length: 32, mayBeLess: true });
3408
+ if (this.check([66, 77])) {
3409
+ return {
3410
+ ext: "bmp",
3411
+ mime: "image/bmp"
3412
+ };
3413
+ }
3414
+ if (this.check([11, 119])) {
3415
+ return {
3416
+ ext: "ac3",
3417
+ mime: "audio/vnd.dolby.dd-raw"
3418
+ };
3419
+ }
3420
+ if (this.check([120, 1])) {
3421
+ return {
3422
+ ext: "dmg",
3423
+ mime: "application/x-apple-diskimage"
3424
+ };
3425
+ }
3426
+ if (this.check([77, 90])) {
3427
+ return {
3428
+ ext: "exe",
3429
+ mime: "application/x-msdownload"
3430
+ };
3431
+ }
3432
+ if (this.check([37, 33])) {
3433
+ await tokenizer.peekBuffer(this.buffer, { length: 24, mayBeLess: true });
3434
+ if (this.checkString("PS-Adobe-", { offset: 2 }) && this.checkString(" EPSF-", { offset: 14 })) {
3435
+ return {
3436
+ ext: "eps",
3437
+ mime: "application/eps"
3438
+ };
3439
+ }
3440
+ return {
3441
+ ext: "ps",
3442
+ mime: "application/postscript"
3443
+ };
3444
+ }
3445
+ if (this.check([31, 160]) || this.check([31, 157])) {
3446
+ return {
3447
+ ext: "Z",
3448
+ mime: "application/x-compress"
3449
+ };
3450
+ }
3451
+ if (this.check([199, 113])) {
3452
+ return {
3453
+ ext: "cpio",
3454
+ mime: "application/x-cpio"
3455
+ };
3456
+ }
3457
+ if (this.check([96, 234])) {
3458
+ return {
3459
+ ext: "arj",
3460
+ mime: "application/x-arj"
3461
+ };
3462
+ }
3463
+ if (this.check([239, 187, 191])) {
3464
+ if (this.detectionReentryCount >= maximumDetectionReentryCount) {
3465
+ return;
3466
+ }
3467
+ this.detectionReentryCount++;
3468
+ await this.tokenizer.ignore(3);
3469
+ return this.detectConfident(tokenizer);
3470
+ }
3471
+ if (this.check([71, 73, 70])) {
3472
+ return {
3473
+ ext: "gif",
3474
+ mime: "image/gif"
3475
+ };
3476
+ }
3477
+ if (this.check([73, 73, 188])) {
3478
+ return {
3479
+ ext: "jxr",
3480
+ mime: "image/vnd.ms-photo"
3481
+ };
3482
+ }
3483
+ if (this.check([31, 139, 8])) {
3484
+ return this.detectGzip(tokenizer);
3485
+ }
3486
+ if (this.check([66, 90, 104])) {
3487
+ return {
3488
+ ext: "bz2",
3489
+ mime: "application/x-bzip2"
3490
+ };
3491
+ }
3492
+ if (this.checkString("ID3")) {
3493
+ await safeIgnore(tokenizer, 6, {
3494
+ maximumLength: 6,
3495
+ reason: "ID3 header prefix"
3496
+ });
3497
+ const id3HeaderLength = await tokenizer.readToken(uint32SyncSafeToken);
3498
+ const isUnknownFileSize = hasUnknownFileSize(tokenizer);
3499
+ if (!Number.isFinite(id3HeaderLength) || id3HeaderLength < 0 || isUnknownFileSize && (id3HeaderLength > maximumId3HeaderSizeInBytes || tokenizer.position + id3HeaderLength > maximumId3HeaderSizeInBytes)) {
3500
+ return;
3501
+ }
3502
+ if (tokenizer.position + id3HeaderLength > tokenizer.fileInfo.size) {
3503
+ if (isUnknownFileSize) {
3504
+ return;
3505
+ }
3506
+ return {
3507
+ ext: "mp3",
3508
+ mime: "audio/mpeg"
3509
+ };
3510
+ }
3511
+ try {
3512
+ await safeIgnore(tokenizer, id3HeaderLength, {
3513
+ maximumLength: isUnknownFileSize ? maximumId3HeaderSizeInBytes : tokenizer.fileInfo.size,
3514
+ reason: "ID3 payload"
3515
+ });
3516
+ } catch (error) {
3517
+ if (error instanceof EndOfStreamError) {
3518
+ return;
3519
+ }
3520
+ throw error;
3521
+ }
3522
+ if (this.detectionReentryCount >= maximumDetectionReentryCount) {
3523
+ return;
3524
+ }
3525
+ this.detectionReentryCount++;
3526
+ return this.parseTokenizer(tokenizer, this.detectionReentryCount);
3527
+ }
3528
+ if (this.checkString("MP+")) {
3529
+ return {
3530
+ ext: "mpc",
3531
+ mime: "audio/x-musepack"
3532
+ };
3533
+ }
3534
+ if ((this.buffer[0] === 67 || this.buffer[0] === 70) && this.check([87, 83], { offset: 1 })) {
3535
+ return {
3536
+ ext: "swf",
3537
+ mime: "application/x-shockwave-flash"
3538
+ };
3539
+ }
3540
+ if (this.check([255, 216, 255])) {
3541
+ if (this.check([247], { offset: 3 })) {
3542
+ return {
3543
+ ext: "jls",
3544
+ mime: "image/jls"
3545
+ };
3546
+ }
3547
+ return {
3548
+ ext: "jpg",
3549
+ mime: "image/jpeg"
3550
+ };
3551
+ }
3552
+ if (this.check([79, 98, 106, 1])) {
3553
+ return {
3554
+ ext: "avro",
3555
+ mime: "application/avro"
3556
+ };
3557
+ }
3558
+ if (this.checkString("FLIF")) {
3559
+ return {
3560
+ ext: "flif",
3561
+ mime: "image/flif"
3562
+ };
3563
+ }
3564
+ if (this.checkString("8BPS")) {
3565
+ return {
3566
+ ext: "psd",
3567
+ mime: "image/vnd.adobe.photoshop"
3568
+ };
3569
+ }
3570
+ if (this.checkString("MPCK")) {
3571
+ return {
3572
+ ext: "mpc",
3573
+ mime: "audio/x-musepack"
3574
+ };
3575
+ }
3576
+ if (this.checkString("FORM")) {
3577
+ return {
3578
+ ext: "aif",
3579
+ mime: "audio/aiff"
3580
+ };
3581
+ }
3582
+ if (this.checkString("icns", { offset: 0 })) {
3583
+ return {
3584
+ ext: "icns",
3585
+ mime: "image/icns"
3586
+ };
3587
+ }
3588
+ if (this.check([80, 75, 3, 4])) {
3589
+ return detectZip(tokenizer);
3590
+ }
3591
+ if (this.checkString("OggS")) {
3592
+ await tokenizer.ignore(28);
3593
+ const type = new Uint8Array(8);
3594
+ await tokenizer.readBuffer(type);
3595
+ if (checkBytes(type, [79, 112, 117, 115, 72, 101, 97, 100])) {
3596
+ return {
3597
+ ext: "opus",
3598
+ mime: "audio/ogg; codecs=opus"
3599
+ };
3600
+ }
3601
+ if (checkBytes(type, [128, 116, 104, 101, 111, 114, 97])) {
3602
+ return {
3603
+ ext: "ogv",
3604
+ mime: "video/ogg"
3605
+ };
3606
+ }
3607
+ if (checkBytes(type, [1, 118, 105, 100, 101, 111, 0])) {
3608
+ return {
3609
+ ext: "ogm",
3610
+ mime: "video/ogg"
3611
+ };
3612
+ }
3613
+ if (checkBytes(type, [127, 70, 76, 65, 67])) {
3614
+ return {
3615
+ ext: "oga",
3616
+ mime: "audio/ogg"
3617
+ };
3618
+ }
3619
+ if (checkBytes(type, [83, 112, 101, 101, 120, 32, 32])) {
3620
+ return {
3621
+ ext: "spx",
3622
+ mime: "audio/ogg"
3623
+ };
3624
+ }
3625
+ if (checkBytes(type, [1, 118, 111, 114, 98, 105, 115])) {
3626
+ return {
3627
+ ext: "ogg",
3628
+ mime: "audio/ogg"
3629
+ };
3630
+ }
3631
+ return {
3632
+ ext: "ogx",
3633
+ mime: "application/ogg"
3634
+ };
3635
+ }
3636
+ if (this.check([80, 75]) && (this.buffer[2] === 3 || this.buffer[2] === 5 || this.buffer[2] === 7) && (this.buffer[3] === 4 || this.buffer[3] === 6 || this.buffer[3] === 8)) {
3637
+ return {
3638
+ ext: "zip",
3639
+ mime: "application/zip"
3640
+ };
3641
+ }
3642
+ if (this.checkString("MThd")) {
3643
+ return {
3644
+ ext: "mid",
3645
+ mime: "audio/midi"
3646
+ };
3647
+ }
3648
+ if (this.checkString("wOFF") && (this.check([0, 1, 0, 0], { offset: 4 }) || this.checkString("OTTO", { offset: 4 }))) {
3649
+ return {
3650
+ ext: "woff",
3651
+ mime: "font/woff"
3652
+ };
3653
+ }
3654
+ if (this.checkString("wOF2") && (this.check([0, 1, 0, 0], { offset: 4 }) || this.checkString("OTTO", { offset: 4 }))) {
3655
+ return {
3656
+ ext: "woff2",
3657
+ mime: "font/woff2"
3658
+ };
3659
+ }
3660
+ if (this.check([212, 195, 178, 161]) || this.check([161, 178, 195, 212])) {
3661
+ return {
3662
+ ext: "pcap",
3663
+ mime: "application/vnd.tcpdump.pcap"
3664
+ };
3665
+ }
3666
+ if (this.checkString("DSD ")) {
3667
+ return {
3668
+ ext: "dsf",
3669
+ mime: "audio/x-dsf"
3670
+ // Non-standard
3671
+ };
3672
+ }
3673
+ if (this.checkString("LZIP")) {
3674
+ return {
3675
+ ext: "lz",
3676
+ mime: "application/lzip"
3677
+ };
3678
+ }
3679
+ if (this.checkString("fLaC")) {
3680
+ return {
3681
+ ext: "flac",
3682
+ mime: "audio/flac"
3683
+ };
3684
+ }
3685
+ if (this.check([66, 80, 71, 251])) {
3686
+ return {
3687
+ ext: "bpg",
3688
+ mime: "image/bpg"
3689
+ };
3690
+ }
3691
+ if (this.checkString("wvpk")) {
3692
+ return {
3693
+ ext: "wv",
3694
+ mime: "audio/wavpack"
3695
+ };
3696
+ }
3697
+ if (this.checkString("%PDF")) {
3698
+ return {
3699
+ ext: "pdf",
3700
+ mime: "application/pdf"
3701
+ };
3702
+ }
3703
+ if (this.check([0, 97, 115, 109])) {
3704
+ return {
3705
+ ext: "wasm",
3706
+ mime: "application/wasm"
3707
+ };
3708
+ }
3709
+ if (this.check([73, 73])) {
3710
+ const fileType = await this.readTiffHeader(false);
3711
+ if (fileType) {
3712
+ return fileType;
3713
+ }
3714
+ }
3715
+ if (this.check([77, 77])) {
3716
+ const fileType = await this.readTiffHeader(true);
3717
+ if (fileType) {
3718
+ return fileType;
3719
+ }
3720
+ }
3721
+ if (this.checkString("MAC ")) {
3722
+ return {
3723
+ ext: "ape",
3724
+ mime: "audio/ape"
3725
+ };
3726
+ }
3727
+ if (this.check([26, 69, 223, 163])) {
3728
+ return detectEbml(tokenizer);
3729
+ }
3730
+ if (this.checkString("SQLi")) {
3731
+ return {
3732
+ ext: "sqlite",
3733
+ mime: "application/x-sqlite3"
3734
+ };
3735
+ }
3736
+ if (this.check([78, 69, 83, 26])) {
3737
+ return {
3738
+ ext: "nes",
3739
+ mime: "application/x-nintendo-nes-rom"
3740
+ };
3741
+ }
3742
+ if (this.checkString("Cr24")) {
3743
+ return {
3744
+ ext: "crx",
3745
+ mime: "application/x-google-chrome-extension"
3746
+ };
3747
+ }
3748
+ if (this.checkString("MSCF") || this.checkString("ISc(")) {
3749
+ return {
3750
+ ext: "cab",
3751
+ mime: "application/vnd.ms-cab-compressed"
3752
+ };
3753
+ }
3754
+ if (this.check([237, 171, 238, 219])) {
3755
+ return {
3756
+ ext: "rpm",
3757
+ mime: "application/x-rpm"
3758
+ };
3759
+ }
3760
+ if (this.check([197, 208, 211, 198])) {
3761
+ return {
3762
+ ext: "eps",
3763
+ mime: "application/eps"
3764
+ };
3765
+ }
3766
+ if (this.check([40, 181, 47, 253])) {
3767
+ return {
3768
+ ext: "zst",
3769
+ mime: "application/zstd"
3770
+ };
3771
+ }
3772
+ if (this.check([127, 69, 76, 70])) {
3773
+ return {
3774
+ ext: "elf",
3775
+ mime: "application/x-elf"
3776
+ };
3777
+ }
3778
+ if (this.check([33, 66, 68, 78])) {
3779
+ return {
3780
+ ext: "pst",
3781
+ mime: "application/vnd.ms-outlook"
3782
+ };
3783
+ }
3784
+ if (this.checkString("PAR1") || this.checkString("PARE")) {
3785
+ return {
3786
+ ext: "parquet",
3787
+ mime: "application/vnd.apache.parquet"
3788
+ };
3789
+ }
3790
+ if (this.checkString("ttcf")) {
3791
+ return {
3792
+ ext: "ttc",
3793
+ mime: "font/collection"
3794
+ };
3795
+ }
3796
+ if (this.check([254, 237, 250, 206]) || this.check([254, 237, 250, 207]) || this.check([206, 250, 237, 254]) || this.check([207, 250, 237, 254])) {
3797
+ return {
3798
+ ext: "macho",
3799
+ mime: "application/x-mach-binary"
3800
+ };
3801
+ }
3802
+ if (this.check([4, 34, 77, 24])) {
3803
+ return {
3804
+ ext: "lz4",
3805
+ mime: "application/x-lz4"
3806
+ // Informal, used by freedesktop.org shared-mime-info
3807
+ };
3808
+ }
3809
+ if (this.checkString("regf")) {
3810
+ return {
3811
+ ext: "dat",
3812
+ mime: "application/x-ft-windows-registry-hive"
3813
+ };
3814
+ }
3815
+ if (this.checkString("$FL2") || this.checkString("$FL3")) {
3816
+ return {
3817
+ ext: "sav",
3818
+ mime: "application/x-spss-sav"
3819
+ };
3820
+ }
3821
+ if (this.check([79, 84, 84, 79, 0])) {
3822
+ return {
3823
+ ext: "otf",
3824
+ mime: "font/otf"
3825
+ };
3826
+ }
3827
+ if (this.checkString("#!AMR")) {
3828
+ return {
3829
+ ext: "amr",
3830
+ mime: "audio/amr"
3831
+ };
3832
+ }
3833
+ if (this.checkString(String.raw`{\rtf`)) {
3834
+ return {
3835
+ ext: "rtf",
3836
+ mime: "application/rtf"
3837
+ };
3838
+ }
3839
+ if (this.check([70, 76, 86, 1])) {
3840
+ return {
3841
+ ext: "flv",
3842
+ mime: "video/x-flv"
3843
+ };
3844
+ }
3845
+ if (this.checkString("IMPM")) {
3846
+ return {
3847
+ ext: "it",
3848
+ mime: "audio/x-it"
3849
+ };
3850
+ }
3851
+ if (this.checkString("-lh0-", { offset: 2 }) || this.checkString("-lh1-", { offset: 2 }) || this.checkString("-lh2-", { offset: 2 }) || this.checkString("-lh3-", { offset: 2 }) || this.checkString("-lh4-", { offset: 2 }) || this.checkString("-lh5-", { offset: 2 }) || this.checkString("-lh6-", { offset: 2 }) || this.checkString("-lh7-", { offset: 2 }) || this.checkString("-lzs-", { offset: 2 }) || this.checkString("-lz4-", { offset: 2 }) || this.checkString("-lz5-", { offset: 2 }) || this.checkString("-lhd-", { offset: 2 })) {
3852
+ return {
3853
+ ext: "lzh",
3854
+ mime: "application/x-lzh-compressed"
3855
+ };
3856
+ }
3857
+ if (this.check([0, 0, 1, 186])) {
3858
+ if (this.check([33], { offset: 4, mask: [241] })) {
3859
+ return {
3860
+ ext: "mpg",
3861
+ // May also be .ps, .mpeg
3862
+ mime: "video/MP1S"
3863
+ };
3864
+ }
3865
+ if (this.check([68], { offset: 4, mask: [196] })) {
3866
+ return {
3867
+ ext: "mpg",
3868
+ // May also be .mpg, .m2p, .vob or .sub
3869
+ mime: "video/MP2P"
3870
+ };
3871
+ }
3872
+ }
3873
+ if (this.checkString("ITSF")) {
3874
+ return {
3875
+ ext: "chm",
3876
+ mime: "application/vnd.ms-htmlhelp"
3877
+ };
3878
+ }
3879
+ if (this.check([202, 254, 186, 190])) {
3880
+ const machOArchitectureCount = UINT32_BE.get(this.buffer, 4);
3881
+ const javaClassFileMajorVersion = UINT16_BE.get(this.buffer, 6);
3882
+ if (machOArchitectureCount > 0 && machOArchitectureCount <= 30) {
3883
+ return {
3884
+ ext: "macho",
3885
+ mime: "application/x-mach-binary"
3886
+ };
3887
+ }
3888
+ if (javaClassFileMajorVersion > 30) {
3889
+ return {
3890
+ ext: "class",
3891
+ mime: "application/java-vm"
3892
+ };
3893
+ }
3894
+ }
3895
+ if (this.checkString(".RMF")) {
3896
+ return {
3897
+ ext: "rm",
3898
+ mime: "application/vnd.rn-realmedia"
3899
+ };
3900
+ }
3901
+ if (this.checkString("DRACO")) {
3902
+ return {
3903
+ ext: "drc",
3904
+ mime: "application/x-ft-draco"
3905
+ };
3906
+ }
3907
+ if (this.check([253, 55, 122, 88, 90, 0])) {
3908
+ return {
3909
+ ext: "xz",
3910
+ mime: "application/x-xz"
3911
+ };
3912
+ }
3913
+ if (this.checkString("<?xml ")) {
3914
+ return {
3915
+ ext: "xml",
3916
+ mime: "application/xml"
3917
+ };
3918
+ }
3919
+ if (this.check([55, 122, 188, 175, 39, 28])) {
3920
+ return {
3921
+ ext: "7z",
3922
+ mime: "application/x-7z-compressed"
3923
+ };
3924
+ }
3925
+ if (this.check([82, 97, 114, 33, 26, 7]) && (this.buffer[6] === 0 || this.buffer[6] === 1)) {
3926
+ return {
3927
+ ext: "rar",
3928
+ mime: "application/x-rar-compressed"
3929
+ };
3930
+ }
3931
+ if (this.checkString("solid ")) {
3932
+ return {
3933
+ ext: "stl",
3934
+ mime: "model/stl"
3935
+ };
3936
+ }
3937
+ if (this.checkString("AC")) {
3938
+ const version = new StringType(4, "latin1").get(this.buffer, 2);
3939
+ if (/^\d+$/v.test(version) && version >= 1e3 && version <= 1050) {
3940
+ return {
3941
+ ext: "dwg",
3942
+ mime: "image/vnd.dwg"
3943
+ };
3944
+ }
3945
+ }
3946
+ if (this.checkString("070707")) {
3947
+ return {
3948
+ ext: "cpio",
3949
+ mime: "application/x-cpio"
3950
+ };
3951
+ }
3952
+ if (this.checkString("BLENDER")) {
3953
+ return {
3954
+ ext: "blend",
3955
+ mime: "application/x-blender"
3956
+ };
3957
+ }
3958
+ if (this.checkString("!<arch>")) {
3959
+ await tokenizer.ignore(8);
3960
+ const string = await tokenizer.readToken(new StringType(13, "ascii"));
3961
+ if (string === "debian-binary") {
3962
+ return {
3963
+ ext: "deb",
3964
+ mime: "application/x-deb"
3965
+ };
3966
+ }
3967
+ return {
3968
+ ext: "ar",
3969
+ mime: "application/x-unix-archive"
3970
+ };
3971
+ }
3972
+ if (this.checkString("WEBVTT") && // One of LF, CR, tab, space, or end of file must follow "WEBVTT" per the spec (see `fixture/fixture-vtt-*.vtt` for examples). Note that `\0` is technically the null character (there is no such thing as an EOF character). However, checking for `\0` gives us the same result as checking for the end of the stream.
3973
+ ["\n", "\r", " ", " ", "\0"].some((char7) => this.checkString(char7, { offset: 6 }))) {
3974
+ return {
3975
+ ext: "vtt",
3976
+ mime: "text/vtt"
3977
+ };
3978
+ }
3979
+ if (this.check([137, 80, 78, 71, 13, 10, 26, 10])) {
3980
+ return detectPng(tokenizer);
3981
+ }
3982
+ if (this.check([65, 82, 82, 79, 87, 49, 0, 0])) {
3983
+ return {
3984
+ ext: "arrow",
3985
+ mime: "application/vnd.apache.arrow.file"
3986
+ };
3987
+ }
3988
+ if (this.check([103, 108, 84, 70, 2, 0, 0, 0])) {
3989
+ return {
3990
+ ext: "glb",
3991
+ mime: "model/gltf-binary"
3992
+ };
3993
+ }
3994
+ if (this.check([102, 114, 101, 101], { offset: 4 }) || this.check([109, 100, 97, 116], { offset: 4 }) || this.check([109, 111, 111, 118], { offset: 4 }) || this.check([119, 105, 100, 101], { offset: 4 })) {
3995
+ return {
3996
+ ext: "mov",
3997
+ mime: "video/quicktime"
3998
+ };
3999
+ }
4000
+ if (this.check([73, 73, 82, 79, 8, 0, 0, 0, 24])) {
4001
+ return {
4002
+ ext: "orf",
4003
+ mime: "image/x-olympus-orf"
4004
+ };
4005
+ }
4006
+ if (this.checkString("gimp xcf ")) {
4007
+ return {
4008
+ ext: "xcf",
4009
+ mime: "image/x-xcf"
4010
+ };
4011
+ }
4012
+ if (this.checkString("ftyp", { offset: 4 }) && (this.buffer[8] & 96) !== 0) {
4013
+ const brandMajor = new StringType(4, "latin1").get(this.buffer, 8).replace("\0", " ").trim();
4014
+ switch (brandMajor) {
4015
+ case "avif":
4016
+ case "avis":
4017
+ return { ext: "avif", mime: "image/avif" };
4018
+ case "mif1":
4019
+ return { ext: "heic", mime: "image/heif" };
4020
+ case "msf1":
4021
+ return { ext: "heic", mime: "image/heif-sequence" };
4022
+ case "heic":
4023
+ case "heix":
4024
+ return { ext: "heic", mime: "image/heic" };
4025
+ case "hevc":
4026
+ case "hevx":
4027
+ return { ext: "heic", mime: "image/heic-sequence" };
4028
+ case "qt":
4029
+ return { ext: "mov", mime: "video/quicktime" };
4030
+ case "M4V":
4031
+ case "M4VH":
4032
+ case "M4VP":
4033
+ return { ext: "m4v", mime: "video/x-m4v" };
4034
+ case "M4P":
4035
+ return { ext: "m4p", mime: "video/mp4" };
4036
+ case "M4B":
4037
+ return { ext: "m4b", mime: "audio/mp4" };
4038
+ case "M4A":
4039
+ return { ext: "m4a", mime: "audio/x-m4a" };
4040
+ case "F4V":
4041
+ return { ext: "f4v", mime: "video/mp4" };
4042
+ case "F4P":
4043
+ return { ext: "f4p", mime: "video/mp4" };
4044
+ case "F4A":
4045
+ return { ext: "f4a", mime: "audio/mp4" };
4046
+ case "F4B":
4047
+ return { ext: "f4b", mime: "audio/mp4" };
4048
+ case "crx":
4049
+ return { ext: "cr3", mime: "image/x-canon-cr3" };
4050
+ default:
4051
+ if (brandMajor.startsWith("3g")) {
4052
+ if (brandMajor.startsWith("3g2")) {
4053
+ return { ext: "3g2", mime: "video/3gpp2" };
4054
+ }
4055
+ return { ext: "3gp", mime: "video/3gpp" };
4056
+ }
4057
+ return { ext: "mp4", mime: "video/mp4" };
4058
+ }
4059
+ }
4060
+ if (this.checkString("REGEDIT4\r\n")) {
4061
+ return {
4062
+ ext: "reg",
4063
+ mime: "application/x-ms-regedit"
4064
+ };
4065
+ }
4066
+ if (this.check([82, 73, 70, 70])) {
4067
+ if (this.checkString("WEBP", { offset: 8 })) {
4068
+ return {
4069
+ ext: "webp",
4070
+ mime: "image/webp"
4071
+ };
4072
+ }
4073
+ if (this.check([65, 86, 73], { offset: 8 })) {
4074
+ return {
4075
+ ext: "avi",
4076
+ mime: "video/vnd.avi"
4077
+ };
4078
+ }
4079
+ if (this.check([87, 65, 86, 69], { offset: 8 })) {
4080
+ return {
4081
+ ext: "wav",
4082
+ mime: "audio/wav"
4083
+ };
4084
+ }
4085
+ if (this.check([81, 76, 67, 77], { offset: 8 })) {
4086
+ return {
4087
+ ext: "qcp",
4088
+ mime: "audio/qcelp"
4089
+ };
4090
+ }
4091
+ }
4092
+ if (this.check([73, 73, 85, 0, 24, 0, 0, 0, 136, 231, 116, 216])) {
4093
+ return {
4094
+ ext: "rw2",
4095
+ mime: "image/x-panasonic-rw2"
4096
+ };
4097
+ }
4098
+ if (this.check([48, 38, 178, 117, 142, 102, 207, 17, 166, 217])) {
4099
+ return detectAsf(tokenizer);
4100
+ }
4101
+ if (this.check([171, 75, 84, 88, 32, 49, 49, 187, 13, 10, 26, 10])) {
4102
+ return {
4103
+ ext: "ktx",
4104
+ mime: "image/ktx"
4105
+ };
4106
+ }
4107
+ if ((this.check([126, 16, 4]) || this.check([126, 24, 4])) && this.check([48, 77, 73, 69], { offset: 4 })) {
4108
+ return {
4109
+ ext: "mie",
4110
+ mime: "application/x-mie"
4111
+ };
4112
+ }
4113
+ if (this.check([39, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], { offset: 2 })) {
4114
+ return {
4115
+ ext: "shp",
4116
+ mime: "application/x-esri-shape"
4117
+ };
4118
+ }
4119
+ if (this.check([255, 79, 255, 81])) {
4120
+ return {
4121
+ ext: "j2c",
4122
+ mime: "image/j2c"
4123
+ };
4124
+ }
4125
+ if (this.check([0, 0, 0, 12, 106, 80, 32, 32, 13, 10, 135, 10])) {
4126
+ await tokenizer.ignore(20);
4127
+ const type = await tokenizer.readToken(new StringType(4, "ascii"));
4128
+ switch (type) {
4129
+ case "jp2 ":
4130
+ return {
4131
+ ext: "jp2",
4132
+ mime: "image/jp2"
4133
+ };
4134
+ case "jpx ":
4135
+ return {
4136
+ ext: "jpx",
4137
+ mime: "image/jpx"
4138
+ };
4139
+ case "jpm ":
4140
+ return {
4141
+ ext: "jpm",
4142
+ mime: "image/jpm"
4143
+ };
4144
+ case "mjp2":
4145
+ return {
4146
+ ext: "mj2",
4147
+ mime: "image/mj2"
4148
+ };
4149
+ default:
4150
+ return;
4151
+ }
4152
+ }
4153
+ if (this.check([255, 10]) || this.check([0, 0, 0, 12, 74, 88, 76, 32, 13, 10, 135, 10])) {
4154
+ return {
4155
+ ext: "jxl",
4156
+ mime: "image/jxl"
4157
+ };
4158
+ }
4159
+ if (this.check([254, 255])) {
4160
+ if (this.checkString("<?xml ", { offset: 2, encoding: "utf-16be" })) {
4161
+ return {
4162
+ ext: "xml",
4163
+ mime: "application/xml"
4164
+ };
4165
+ }
4166
+ return void 0;
4167
+ }
4168
+ if (this.check([208, 207, 17, 224, 161, 177, 26, 225])) {
4169
+ return {
4170
+ ext: "cfb",
4171
+ mime: "application/x-cfb"
4172
+ };
4173
+ }
4174
+ await tokenizer.peekBuffer(this.buffer, { length: Math.min(256, tokenizer.fileInfo.size), mayBeLess: true });
4175
+ if (this.check([97, 99, 115, 112], { offset: 36 })) {
4176
+ return {
4177
+ ext: "icc",
4178
+ mime: "application/vnd.iccprofile"
4179
+ };
4180
+ }
4181
+ if (this.checkString("**ACE", { offset: 7 }) && this.checkString("**", { offset: 12 })) {
4182
+ return {
4183
+ ext: "ace",
4184
+ mime: "application/x-ace-compressed"
4185
+ };
4186
+ }
4187
+ if (this.checkString("BEGIN:")) {
4188
+ if (this.checkString("VCARD", { offset: 6 })) {
4189
+ return {
4190
+ ext: "vcf",
4191
+ mime: "text/vcard"
4192
+ };
4193
+ }
4194
+ if (this.checkString("VCALENDAR", { offset: 6 })) {
4195
+ return {
4196
+ ext: "ics",
4197
+ mime: "text/calendar"
4198
+ };
4199
+ }
4200
+ }
4201
+ if (this.checkString("FUJIFILMCCD-RAW")) {
4202
+ return {
4203
+ ext: "raf",
4204
+ mime: "image/x-fujifilm-raf"
4205
+ };
4206
+ }
4207
+ if (this.checkString("Extended Module:")) {
4208
+ return {
4209
+ ext: "xm",
4210
+ mime: "audio/x-xm"
4211
+ };
4212
+ }
4213
+ if (this.checkString("Creative Voice File")) {
4214
+ return {
4215
+ ext: "voc",
4216
+ mime: "audio/x-voc"
4217
+ };
4218
+ }
4219
+ if (this.check([4, 0, 0, 0]) && this.buffer.length >= 16) {
4220
+ const jsonSize = new DataView(this.buffer.buffer).getUint32(12, true);
4221
+ if (jsonSize > 12 && this.buffer.length >= jsonSize + 16) {
4222
+ try {
4223
+ const header = new TextDecoder().decode(this.buffer.subarray(16, jsonSize + 16));
4224
+ const json = JSON.parse(header);
4225
+ if (json.files) {
4226
+ return {
4227
+ ext: "asar",
4228
+ mime: "application/x-asar"
4229
+ };
4230
+ }
4231
+ } catch {
4232
+ }
4233
+ }
4234
+ }
4235
+ if (this.check([6, 14, 43, 52, 2, 5, 1, 1, 13, 1, 2, 1, 1, 2])) {
4236
+ return {
4237
+ ext: "mxf",
4238
+ mime: "application/mxf"
4239
+ };
4240
+ }
4241
+ if (this.checkString("SCRM", { offset: 44 })) {
4242
+ return {
4243
+ ext: "s3m",
4244
+ mime: "audio/x-s3m"
4245
+ };
4246
+ }
4247
+ if (this.check([71]) && this.check([71], { offset: 188 })) {
4248
+ return {
4249
+ ext: "mts",
4250
+ mime: "video/mp2t"
4251
+ };
4252
+ }
4253
+ if (this.check([71], { offset: 4 }) && this.check([71], { offset: 196 })) {
4254
+ return {
4255
+ ext: "mts",
4256
+ mime: "video/mp2t"
4257
+ };
4258
+ }
4259
+ if (this.check([66, 79, 79, 75, 77, 79, 66, 73], { offset: 60 })) {
4260
+ return {
4261
+ ext: "mobi",
4262
+ mime: "application/x-mobipocket-ebook"
4263
+ };
4264
+ }
4265
+ if (this.check([68, 73, 67, 77], { offset: 128 })) {
4266
+ return {
4267
+ ext: "dcm",
4268
+ mime: "application/dicom"
4269
+ };
4270
+ }
4271
+ if (this.check([76, 0, 0, 0, 1, 20, 2, 0, 0, 0, 0, 0, 192, 0, 0, 0, 0, 0, 0, 70])) {
4272
+ return {
4273
+ ext: "lnk",
4274
+ mime: "application/x-ms-shortcut"
4275
+ // Informal, used by freedesktop.org shared-mime-info
4276
+ };
4277
+ }
4278
+ if (this.check([98, 111, 111, 107, 0, 0, 0, 0, 109, 97, 114, 107, 0, 0, 0, 0])) {
4279
+ return {
4280
+ ext: "alias",
4281
+ mime: "application/x-ft-apple.alias"
4282
+ };
4283
+ }
4284
+ if (this.checkString("Kaydara FBX Binary \0")) {
4285
+ return {
4286
+ ext: "fbx",
4287
+ mime: "application/x-ft-fbx"
4288
+ };
4289
+ }
4290
+ if (this.check([76, 80], { offset: 34 }) && (this.check([0, 0, 1], { offset: 8 }) || this.check([1, 0, 2], { offset: 8 }) || this.check([2, 0, 2], { offset: 8 }))) {
4291
+ return {
4292
+ ext: "eot",
4293
+ mime: "application/vnd.ms-fontobject"
4294
+ };
4295
+ }
4296
+ if (this.check([6, 6, 237, 245, 216, 29, 70, 229, 189, 49, 239, 231, 254, 116, 183, 29])) {
4297
+ return {
4298
+ ext: "indd",
4299
+ mime: "application/x-indesign"
4300
+ };
4301
+ }
4302
+ if (this.check([255, 255, 0, 0, 7, 0, 0, 0, 4, 0, 0, 0, 1, 0, 1, 0]) || this.check([0, 0, 255, 255, 0, 0, 0, 7, 0, 0, 0, 4, 0, 1, 0, 1])) {
4303
+ return {
4304
+ ext: "jmp",
4305
+ mime: "application/x-jmp-data"
4306
+ };
4307
+ }
4308
+ await tokenizer.peekBuffer(this.buffer, { length: Math.min(512, tokenizer.fileInfo.size), mayBeLess: true });
4309
+ if (this.checkString("ustar", { offset: 257 }) && (this.checkString("\0", { offset: 262 }) || this.checkString(" ", { offset: 262 })) || this.check([0, 0, 0, 0, 0, 0], { offset: 257 }) && tarHeaderChecksumMatches(this.buffer)) {
4310
+ return {
4311
+ ext: "tar",
4312
+ mime: "application/x-tar"
4313
+ };
4314
+ }
4315
+ if (this.check([255, 254])) {
4316
+ const encoding = "utf-16le";
4317
+ if (this.checkString("<?xml ", { offset: 2, encoding })) {
4318
+ return {
4319
+ ext: "xml",
4320
+ mime: "application/xml"
4321
+ };
4322
+ }
4323
+ if (this.check([255, 14], { offset: 2 }) && this.checkString("SketchUp Model", { offset: 4, encoding })) {
4324
+ return {
4325
+ ext: "skp",
4326
+ mime: "application/vnd.sketchup.skp"
4327
+ };
4328
+ }
4329
+ if (this.checkString("Windows Registry Editor Version 5.00\r\n", { offset: 2, encoding })) {
4330
+ return {
4331
+ ext: "reg",
4332
+ mime: "application/x-ms-regedit"
4333
+ };
4334
+ }
4335
+ return void 0;
4336
+ }
4337
+ if (this.checkString("-----BEGIN PGP MESSAGE-----")) {
4338
+ return {
4339
+ ext: "pgp",
4340
+ mime: "application/pgp-encrypted"
4341
+ };
4342
+ }
4343
+ };
4344
+ // Detections with limited supporting data, resulting in a higher likelihood of false positives
4345
+ detectImprecise = async (tokenizer) => {
4346
+ this.buffer = new Uint8Array(reasonableDetectionSizeInBytes);
4347
+ const fileSize = getKnownFileSizeOrMaximum(tokenizer.fileInfo.size);
4348
+ await tokenizer.peekBuffer(this.buffer, { length: Math.min(8, fileSize), mayBeLess: true });
4349
+ if (this.check([0, 0, 1, 186]) || this.check([0, 0, 1, 179])) {
4350
+ return {
4351
+ ext: "mpg",
4352
+ mime: "video/mpeg"
4353
+ };
4354
+ }
4355
+ if (this.check([0, 1, 0, 0, 0])) {
4356
+ return {
4357
+ ext: "ttf",
4358
+ mime: "font/ttf"
4359
+ };
4360
+ }
4361
+ if (this.check([0, 0, 1, 0])) {
4362
+ return {
4363
+ ext: "ico",
4364
+ mime: "image/x-icon"
4365
+ };
4366
+ }
4367
+ if (this.check([0, 0, 2, 0])) {
4368
+ return {
4369
+ ext: "cur",
4370
+ mime: "image/x-icon"
4371
+ };
4372
+ }
4373
+ await tokenizer.peekBuffer(this.buffer, { length: Math.min(2 + this.options.mpegOffsetTolerance, fileSize), mayBeLess: true });
4374
+ if (this.buffer.length >= 2 + this.options.mpegOffsetTolerance) {
4375
+ for (let depth = 0; depth <= this.options.mpegOffsetTolerance; ++depth) {
4376
+ const type = this.scanMpeg(depth);
4377
+ if (type) {
4378
+ return type;
4379
+ }
4380
+ }
4381
+ }
4382
+ };
4383
+ async readTiffTag(bigEndian) {
4384
+ const tagId = await this.tokenizer.readToken(bigEndian ? UINT16_BE : UINT16_LE);
4385
+ await this.tokenizer.ignore(10);
4386
+ switch (tagId) {
4387
+ case 50341:
4388
+ return {
4389
+ ext: "arw",
4390
+ mime: "image/x-sony-arw"
4391
+ };
4392
+ case 50706:
4393
+ return {
4394
+ ext: "dng",
4395
+ mime: "image/x-adobe-dng"
4396
+ };
4397
+ default:
4398
+ }
4399
+ }
4400
+ async readTiffIFD(bigEndian) {
4401
+ const numberOfTags = await this.tokenizer.readToken(bigEndian ? UINT16_BE : UINT16_LE);
4402
+ if (numberOfTags > maximumTiffTagCount) {
4403
+ return;
4404
+ }
4405
+ if (hasUnknownFileSize(this.tokenizer) && 2 + numberOfTags * 12 > maximumTiffIfdOffsetInBytes) {
4406
+ return;
4407
+ }
4408
+ for (let n = 0; n < numberOfTags; ++n) {
4409
+ const fileType = await this.readTiffTag(bigEndian);
4410
+ if (fileType) {
4411
+ return fileType;
4412
+ }
4413
+ }
4414
+ }
4415
+ async readTiffHeader(bigEndian) {
4416
+ const tiffFileType = {
4417
+ ext: "tif",
4418
+ mime: "image/tiff"
4419
+ };
4420
+ const version = (bigEndian ? UINT16_BE : UINT16_LE).get(this.buffer, 2);
4421
+ const ifdOffset = (bigEndian ? UINT32_BE : UINT32_LE).get(this.buffer, 4);
4422
+ if (version === 42) {
4423
+ if (ifdOffset >= 6) {
4424
+ if (this.checkString("CR", { offset: 8 })) {
4425
+ return {
4426
+ ext: "cr2",
4427
+ mime: "image/x-canon-cr2"
4428
+ };
4429
+ }
4430
+ if (ifdOffset >= 8) {
4431
+ const someId1 = (bigEndian ? UINT16_BE : UINT16_LE).get(this.buffer, 8);
4432
+ const someId2 = (bigEndian ? UINT16_BE : UINT16_LE).get(this.buffer, 10);
4433
+ if (someId1 === 28 && someId2 === 254 || someId1 === 31 && someId2 === 11) {
4434
+ return {
4435
+ ext: "nef",
4436
+ mime: "image/x-nikon-nef"
4437
+ };
4438
+ }
4439
+ }
4440
+ }
4441
+ if (hasUnknownFileSize(this.tokenizer) && ifdOffset > maximumTiffStreamIfdOffsetInBytes) {
4442
+ return tiffFileType;
4443
+ }
4444
+ const maximumTiffOffset = hasUnknownFileSize(this.tokenizer) ? maximumTiffIfdOffsetInBytes : this.tokenizer.fileInfo.size;
4445
+ try {
4446
+ await safeIgnore(this.tokenizer, ifdOffset, {
4447
+ maximumLength: maximumTiffOffset,
4448
+ reason: "TIFF IFD offset"
4449
+ });
4450
+ } catch (error) {
4451
+ if (error instanceof EndOfStreamError) {
4452
+ return;
4453
+ }
4454
+ throw error;
4455
+ }
4456
+ let fileType;
4457
+ try {
4458
+ fileType = await this.readTiffIFD(bigEndian);
4459
+ } catch (error) {
4460
+ if (error instanceof EndOfStreamError) {
4461
+ return;
4462
+ }
4463
+ throw error;
4464
+ }
4465
+ return fileType ?? tiffFileType;
4466
+ }
4467
+ if (version === 43) {
4468
+ return tiffFileType;
4469
+ }
4470
+ }
4471
+ /**
4472
+ Scan check MPEG 1 or 2 Layer 3 header, or 'layer 0' for ADTS (MPEG sync-word 0xFFE).
4473
+
4474
+ @param offset - Offset to scan for sync-preamble.
4475
+ @returns {{ext: string, mime: string}}
4476
+ */
4477
+ scanMpeg(offset) {
4478
+ if (this.check([255, 224], { offset, mask: [255, 224] })) {
4479
+ if (this.check([16], { offset: offset + 1, mask: [22] })) {
4480
+ if (this.check([8], { offset: offset + 1, mask: [8] })) {
4481
+ return {
4482
+ ext: "aac",
4483
+ mime: "audio/aac"
4484
+ };
4485
+ }
4486
+ return {
4487
+ ext: "aac",
4488
+ mime: "audio/aac"
4489
+ };
4490
+ }
4491
+ if (this.check([2], { offset: offset + 1, mask: [6] })) {
4492
+ return {
4493
+ ext: "mp3",
4494
+ mime: "audio/mpeg"
4495
+ };
4496
+ }
4497
+ if (this.check([4], { offset: offset + 1, mask: [6] })) {
4498
+ return {
4499
+ ext: "mp2",
4500
+ mime: "audio/mpeg"
4501
+ };
4502
+ }
4503
+ if (this.check([6], { offset: offset + 1, mask: [6] })) {
4504
+ return {
4505
+ ext: "mp1",
4506
+ mime: "audio/mpeg"
4507
+ };
4508
+ }
4509
+ }
4510
+ }
4511
+ };
4512
+ var supportedExtensions = new Set(extensions);
4513
+ var supportedMimeTypes = new Set(mimeTypes);
4514
+
4515
+ // src/components/media-utils.ts
4516
+ init_logger();
4517
+ var TAG = "media";
4518
+ var MAX_FILE_BYTES = 16 * 1024 * 1024;
4519
+ var IMAGE_MAX_PX = parseInt(process.env["IMAGE_MAX_PX"] ?? "1024", 10);
4520
+ var IMAGE_MAX_BASE64_MB = parseFloat(process.env["IMAGE_MAX_BASE64_MB"] ?? "3");
4521
+ var MEDIA_DIR = join(abtarsHome(), "received", "media");
4522
+ var FILES_DIR = join(abtarsHome(), "received", "files");
4523
+ var IMAGE_MIMES = /* @__PURE__ */ new Set(["image/jpeg", "image/png", "image/webp", "image/gif"]);
4524
+ var EXT_MAP = {
4525
+ "image/jpeg": ".jpg",
4526
+ "image/png": ".png",
4527
+ "image/webp": ".webp",
4528
+ "image/gif": ".gif",
4529
+ "application/pdf": ".pdf",
4530
+ "text/plain": ".txt",
4531
+ "text/csv": ".csv",
4532
+ "text/markdown": ".md"
4533
+ };
4534
+ function ensureDir(dir) {
4535
+ if (!existsSync(dir)) mkdirSync(dir, { recursive: true });
4536
+ }
4537
+ function buildFilename(chatId, ext) {
4538
+ const now = /* @__PURE__ */ new Date();
4539
+ const pad = (n) => String(n).padStart(2, "0");
4540
+ const ts = `${now.getFullYear()}${pad(now.getMonth() + 1)}${pad(now.getDate())}_${pad(now.getHours())}${pad(now.getMinutes())}${pad(now.getSeconds())}`;
4541
+ const rand = randomBytes(3).toString("hex");
4542
+ return `${ts}_${chatId}_${rand}${ext}`;
4543
+ }
4544
+ async function detectMime(buffer, extHint, claimedMime) {
4545
+ const sniffed = await fileTypeFromBuffer(buffer);
4546
+ if (sniffed && sniffed.mime !== "application/octet-stream" && sniffed.mime !== "application/zip") {
4547
+ return sniffed.mime;
4548
+ }
4549
+ if (extHint) {
4550
+ const extLower = extHint.toLowerCase();
4551
+ for (const [mime, ext] of Object.entries(EXT_MAP)) {
4552
+ if (ext === extLower) return mime;
4553
+ }
4554
+ }
4555
+ if (claimedMime && claimedMime !== "application/octet-stream") {
4556
+ return claimedMime;
4557
+ }
4558
+ return sniffed?.mime ?? "application/octet-stream";
4559
+ }
4560
+ async function saveInboundMedia(buffer, chatId, opts) {
4561
+ if (buffer.length > MAX_FILE_BYTES) {
4562
+ logWarn(TAG, `Rejected file from chat ${chatId}: ${buffer.length} bytes exceeds ${MAX_FILE_BYTES}`);
4563
+ return null;
4564
+ }
4565
+ const mime = await detectMime(buffer, opts?.extHint, opts?.claimedMime);
4566
+ const isImage = IMAGE_MIMES.has(mime);
4567
+ const ext = EXT_MAP[mime] ?? ".bin";
4568
+ if (opts?.claimedMime && opts.claimedMime !== mime) {
4569
+ logWarn(TAG, `MIME mismatch: claimed=${opts.claimedMime}, detected=${mime}`);
4570
+ }
4571
+ const dir = isImage ? MEDIA_DIR : MEDIA_DIR;
4572
+ ensureDir(dir);
4573
+ const filename = buildFilename(chatId, ext);
4574
+ const path = join(dir, filename);
4575
+ let finalBuffer = buffer;
4576
+ if (isImage && buffer.length > 3e5 && (mime === "image/jpeg" || mime === "image/png")) {
4577
+ try {
4578
+ finalBuffer = await resizeImage(buffer, mime);
4579
+ } catch (err) {
4580
+ logWarn(TAG, `Resize failed, saving original: ${err instanceof Error ? err.message : String(err)}`);
4581
+ }
4582
+ }
4583
+ writeFileSync(path, finalBuffer);
4584
+ logInfo(TAG, `Saved ${isImage ? "image" : "file"}: ${filename} (${finalBuffer.length}B, ${mime})`);
4585
+ return { path, mime, ext, size: finalBuffer.length, isImage };
4586
+ }
4587
+ async function resizeImage(buffer, mime) {
4588
+ const { Jimp } = await import("./esm-DDP6NCZG.js");
4589
+ const img = await Jimp.read(buffer);
4590
+ const maxBytes = IMAGE_MAX_BASE64_MB * 1024 * 1024;
4591
+ let w = img.width;
4592
+ let h = img.height;
4593
+ if (w > IMAGE_MAX_PX || h > IMAGE_MAX_PX) {
4594
+ const scale = IMAGE_MAX_PX / Math.max(w, h);
4595
+ w = Math.round(w * scale);
4596
+ h = Math.round(h * scale);
4597
+ img.resize({ w, h });
4598
+ }
4599
+ const isJpeg = mime === "image/jpeg";
4600
+ const qualities = isJpeg ? [85, 70, 50, 30] : [void 0];
4601
+ for (let round = 0; round < 4; round++) {
4602
+ for (const q of qualities) {
4603
+ const out2 = isJpeg ? await img.getBuffer("image/jpeg", { quality: q }) : await img.getBuffer("image/png");
4604
+ const b64Size = Math.ceil(out2.length * 4 / 3);
4605
+ if (b64Size <= maxBytes) return Buffer.from(out2);
4606
+ }
4607
+ w = Math.round(w / 2);
4608
+ h = Math.round(h / 2);
4609
+ if (w < 64 || h < 64) break;
4610
+ img.resize({ w, h });
4611
+ }
4612
+ const out = isJpeg ? await img.getBuffer("image/jpeg", { quality: 30 }) : await img.getBuffer("image/png");
4613
+ return Buffer.from(out);
4614
+ }
4615
+ function pruneMediaFolder() {
4616
+ if (!existsSync(MEDIA_DIR)) return 0;
4617
+ const maxAge = 7 * 24 * 60 * 60 * 1e3;
4618
+ const maxBytes = 100 * 1024 * 1024;
4619
+ const now = Date.now();
4620
+ let deleted = 0;
4621
+ const files = readdirSync(MEDIA_DIR).map((f) => ({ name: f, path: join(MEDIA_DIR, f), stat: statSync(join(MEDIA_DIR, f)) })).sort((a, b) => a.stat.mtimeMs - b.stat.mtimeMs);
4622
+ for (const f of files) {
4623
+ if (now - f.stat.mtimeMs > maxAge) {
4624
+ try {
4625
+ unlinkSync(f.path);
4626
+ deleted++;
4627
+ } catch {
4628
+ }
4629
+ }
4630
+ }
4631
+ const remaining = files.filter((f) => existsSync(f.path));
4632
+ let totalSize = remaining.reduce((sum, f) => sum + f.stat.size, 0);
4633
+ for (const f of remaining) {
4634
+ if (totalSize <= maxBytes) break;
4635
+ try {
4636
+ unlinkSync(f.path);
4637
+ totalSize -= f.stat.size;
4638
+ deleted++;
4639
+ } catch {
4640
+ }
4641
+ }
4642
+ if (deleted > 0) logInfo(TAG, `Pruned ${deleted} media files`);
4643
+ return deleted;
4644
+ }
4645
+ async function saveA2AFile(buffer, chatId) {
4646
+ if (buffer.length > MAX_FILE_BYTES) {
4647
+ logWarn(TAG, `Rejected A2A file: ${buffer.length} bytes exceeds ${MAX_FILE_BYTES}`);
4648
+ return null;
4649
+ }
4650
+ ensureDir(FILES_DIR);
4651
+ const filename = buildFilename(chatId, ".txt");
4652
+ const path = join(FILES_DIR, filename);
4653
+ writeFileSync(path, buffer);
4654
+ logInfo(TAG, `Saved A2A file: ${filename} (${buffer.length}B, forced .txt)`);
4655
+ return { path, mime: "text/plain", ext: ".txt", size: buffer.length, isImage: false };
4656
+ }
4657
+ export {
4658
+ pruneMediaFolder,
4659
+ saveA2AFile,
4660
+ saveInboundMedia
4661
+ };
4662
+ //# sourceMappingURL=media-utils-XNNDTYFI.js.map