qzip 1.2.1__py3-none-win_amd64.whl

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 (407) hide show
  1. qzip/__init__.py +54 -0
  2. qzip/__main__.py +2 -0
  3. qzip/cli.py +265 -0
  4. qzip/container.py +52 -0
  5. qzip/core.py +38 -0
  6. qzip/identity.py +207 -0
  7. qzip/jobs.py +614 -0
  8. qzip/web.py +67 -0
  9. qzip-1.2.1.dist-info/METADATA +548 -0
  10. qzip-1.2.1.dist-info/RECORD +407 -0
  11. qzip-1.2.1.dist-info/WHEEL +5 -0
  12. qzip-1.2.1.dist-info/entry_points.txt +2 -0
  13. qzip-1.2.1.dist-info/licenses/LICENSE +680 -0
  14. qzip-1.2.1.dist-info/licenses/NOTICE +23 -0
  15. qzip-1.2.1.dist-info/licenses/THIRD_PARTY_NOTICES.md +34 -0
  16. qzip-1.2.1.dist-info/top_level.txt +3 -0
  17. src/__init__.py +0 -0
  18. src/candidates/__init__.py +8 -0
  19. src/elliott_quantum_compression_enterprise.py +7543 -0
  20. src/engine_mcmfork/Archive.cpp +918 -0
  21. src/engine_mcmfork/Archive.hpp +202 -0
  22. src/engine_mcmfork/BracketModel.hpp +150 -0
  23. src/engine_mcmfork/CM-inl.hpp +813 -0
  24. src/engine_mcmfork/CM.hpp +1243 -0
  25. src/engine_mcmfork/COPYING +674 -0
  26. src/engine_mcmfork/Compressor.cpp +133 -0
  27. src/engine_mcmfork/Compressor.hpp +207 -0
  28. src/engine_mcmfork/CyclicBuffer.hpp +186 -0
  29. src/engine_mcmfork/DeltaFilter.hpp +99 -0
  30. src/engine_mcmfork/Detector.hpp +660 -0
  31. src/engine_mcmfork/Dict.hpp +1147 -0
  32. src/engine_mcmfork/DivTable.hpp +54 -0
  33. src/engine_mcmfork/Entropy.hpp +50 -0
  34. src/engine_mcmfork/File.cpp +214 -0
  35. src/engine_mcmfork/File.hpp +561 -0
  36. src/engine_mcmfork/Filter.hpp +301 -0
  37. src/engine_mcmfork/FilterTest.cpp +363 -0
  38. src/engine_mcmfork/GD.hpp +147 -0
  39. src/engine_mcmfork/HashTable.hpp +90 -0
  40. src/engine_mcmfork/Huffman.cpp +66 -0
  41. src/engine_mcmfork/Huffman.hpp +427 -0
  42. src/engine_mcmfork/JPEG.hpp +68 -0
  43. src/engine_mcmfork/LZ-inl.hpp +144 -0
  44. src/engine_mcmfork/LZ.cpp +313 -0
  45. src/engine_mcmfork/LZ.hpp +411 -0
  46. src/engine_mcmfork/Log.hpp +139 -0
  47. src/engine_mcmfork/MCM.cpp +586 -0
  48. src/engine_mcmfork/MatchFinder.hpp +373 -0
  49. src/engine_mcmfork/MatchModel.hpp +199 -0
  50. src/engine_mcmfork/Memory.cpp +83 -0
  51. src/engine_mcmfork/Memory.hpp +77 -0
  52. src/engine_mcmfork/Mixer.hpp +382 -0
  53. src/engine_mcmfork/Model.hpp +332 -0
  54. src/engine_mcmfork/ProbMap.hpp +151 -0
  55. src/engine_mcmfork/ProgressMeter.hpp +227 -0
  56. src/engine_mcmfork/QZIP_FORK.md +53 -0
  57. src/engine_mcmfork/QzCsv.hpp +167 -0
  58. src/engine_mcmfork/README.md +48 -0
  59. src/engine_mcmfork/Range.hpp +239 -0
  60. src/engine_mcmfork/Reorder.hpp +59 -0
  61. src/engine_mcmfork/SSE.hpp +253 -0
  62. src/engine_mcmfork/SimdCompat.hpp +11 -0
  63. src/engine_mcmfork/StateMap.hpp +256 -0
  64. src/engine_mcmfork/Stream.hpp +443 -0
  65. src/engine_mcmfork/Tests.cpp +28 -0
  66. src/engine_mcmfork/Tests.hpp +29 -0
  67. src/engine_mcmfork/TurboCM.hpp +445 -0
  68. src/engine_mcmfork/UTF8.hpp +97 -0
  69. src/engine_mcmfork/Util.cpp +165 -0
  70. src/engine_mcmfork/Util.hpp +562 -0
  71. src/engine_mcmfork/Wav16.hpp +369 -0
  72. src/engine_mcmfork/WordCounter.hpp +390 -0
  73. src/engine_mcmfork/WordModel.hpp +327 -0
  74. src/engine_mcmfork/X86Binary.hpp +229 -0
  75. src/engine_mcmfork/bench/RESULTS.md +51 -0
  76. src/engine_mcmfork/bench/box_dev_ablations.log +166 -0
  77. src/engine_mcmfork/bench/mfbench.sh +13 -0
  78. src/engine_mcmfork/bench/pc2_results.tsv +33 -0
  79. src/engine_mcmfork/make.bat +2 -0
  80. src/engine_mcmfork/make.sh +1 -0
  81. src/engine_mcmfork/sse2neon.h +11855 -0
  82. src/native/LICENSE.libbsc +202 -0
  83. src/native/Makefile +82 -0
  84. src/native/VERSION.libbsc +1 -0
  85. src/native/__init__.py +0 -0
  86. src/native/everyday/Makefile +33 -0
  87. src/native/everyday/lzma/7zStream.c +199 -0
  88. src/native/everyday/lzma/7zTypes.h +600 -0
  89. src/native/everyday/lzma/7zWindows.h +107 -0
  90. src/native/everyday/lzma/Alloc.c +774 -0
  91. src/native/everyday/lzma/Alloc.h +76 -0
  92. src/native/everyday/lzma/Bra.c +709 -0
  93. src/native/everyday/lzma/Bra.h +105 -0
  94. src/native/everyday/lzma/Bra86.c +187 -0
  95. src/native/everyday/lzma/BraIA64.c +14 -0
  96. src/native/everyday/lzma/Compiler.h +287 -0
  97. src/native/everyday/lzma/CpuArch.c +970 -0
  98. src/native/everyday/lzma/CpuArch.h +719 -0
  99. src/native/everyday/lzma/LzFind.c +1746 -0
  100. src/native/everyday/lzma/LzFind.h +160 -0
  101. src/native/everyday/lzma/LzFindMt.c +1422 -0
  102. src/native/everyday/lzma/LzFindMt.h +114 -0
  103. src/native/everyday/lzma/LzFindOpt.c +578 -0
  104. src/native/everyday/lzma/LzHash.h +34 -0
  105. src/native/everyday/lzma/Lzma2Dec.c +493 -0
  106. src/native/everyday/lzma/Lzma2Dec.h +121 -0
  107. src/native/everyday/lzma/Lzma2Enc.c +799 -0
  108. src/native/everyday/lzma/Lzma2Enc.h +58 -0
  109. src/native/everyday/lzma/LzmaDec.c +1367 -0
  110. src/native/everyday/lzma/LzmaDec.h +237 -0
  111. src/native/everyday/lzma/LzmaEnc.c +3268 -0
  112. src/native/everyday/lzma/LzmaEnc.h +90 -0
  113. src/native/everyday/lzma/LzmaLib.c +42 -0
  114. src/native/everyday/lzma/LzmaLib.h +138 -0
  115. src/native/everyday/lzma/MtCoder.c +604 -0
  116. src/native/everyday/lzma/MtCoder.h +144 -0
  117. src/native/everyday/lzma/MtDec.c +1124 -0
  118. src/native/everyday/lzma/MtDec.h +202 -0
  119. src/native/everyday/lzma/Precomp.h +127 -0
  120. src/native/everyday/lzma/README +17 -0
  121. src/native/everyday/lzma/RotateDefs.h +50 -0
  122. src/native/everyday/lzma/Threads.c +826 -0
  123. src/native/everyday/lzma/Threads.h +260 -0
  124. src/native/everyday/lzma/lzma-sdk.txt +437 -0
  125. src/native/everyday/qze.c +1148 -0
  126. src/native/everyday/xform.c +1291 -0
  127. src/native/everyday/xform.h +41 -0
  128. src/native/everyday/zstd/LICENSE +30 -0
  129. src/native/everyday/zstd/common/allocations.h +55 -0
  130. src/native/everyday/zstd/common/bits.h +205 -0
  131. src/native/everyday/zstd/common/bitstream.h +454 -0
  132. src/native/everyday/zstd/common/compiler.h +464 -0
  133. src/native/everyday/zstd/common/cpu.h +249 -0
  134. src/native/everyday/zstd/common/debug.c +30 -0
  135. src/native/everyday/zstd/common/debug.h +107 -0
  136. src/native/everyday/zstd/common/entropy_common.c +340 -0
  137. src/native/everyday/zstd/common/error_private.c +64 -0
  138. src/native/everyday/zstd/common/error_private.h +158 -0
  139. src/native/everyday/zstd/common/fse.h +625 -0
  140. src/native/everyday/zstd/common/fse_decompress.c +315 -0
  141. src/native/everyday/zstd/common/huf.h +277 -0
  142. src/native/everyday/zstd/common/mem.h +422 -0
  143. src/native/everyday/zstd/common/pool.c +371 -0
  144. src/native/everyday/zstd/common/pool.h +81 -0
  145. src/native/everyday/zstd/common/portability_macros.h +171 -0
  146. src/native/everyday/zstd/common/threading.c +182 -0
  147. src/native/everyday/zstd/common/threading.h +142 -0
  148. src/native/everyday/zstd/common/xxhash.c +18 -0
  149. src/native/everyday/zstd/common/xxhash.h +7094 -0
  150. src/native/everyday/zstd/common/zstd_common.c +48 -0
  151. src/native/everyday/zstd/common/zstd_deps.h +123 -0
  152. src/native/everyday/zstd/common/zstd_internal.h +324 -0
  153. src/native/everyday/zstd/common/zstd_trace.h +156 -0
  154. src/native/everyday/zstd/compress/clevels.h +134 -0
  155. src/native/everyday/zstd/compress/fse_compress.c +625 -0
  156. src/native/everyday/zstd/compress/hist.c +191 -0
  157. src/native/everyday/zstd/compress/hist.h +82 -0
  158. src/native/everyday/zstd/compress/huf_compress.c +1464 -0
  159. src/native/everyday/zstd/compress/zstd_compress.c +7843 -0
  160. src/native/everyday/zstd/compress/zstd_compress_internal.h +1636 -0
  161. src/native/everyday/zstd/compress/zstd_compress_literals.c +235 -0
  162. src/native/everyday/zstd/compress/zstd_compress_literals.h +39 -0
  163. src/native/everyday/zstd/compress/zstd_compress_sequences.c +442 -0
  164. src/native/everyday/zstd/compress/zstd_compress_sequences.h +55 -0
  165. src/native/everyday/zstd/compress/zstd_compress_superblock.c +688 -0
  166. src/native/everyday/zstd/compress/zstd_compress_superblock.h +32 -0
  167. src/native/everyday/zstd/compress/zstd_cwksp.h +765 -0
  168. src/native/everyday/zstd/compress/zstd_double_fast.c +778 -0
  169. src/native/everyday/zstd/compress/zstd_double_fast.h +42 -0
  170. src/native/everyday/zstd/compress/zstd_fast.c +985 -0
  171. src/native/everyday/zstd/compress/zstd_fast.h +30 -0
  172. src/native/everyday/zstd/compress/zstd_lazy.c +2199 -0
  173. src/native/everyday/zstd/compress/zstd_lazy.h +193 -0
  174. src/native/everyday/zstd/compress/zstd_ldm.c +745 -0
  175. src/native/everyday/zstd/compress/zstd_ldm.h +109 -0
  176. src/native/everyday/zstd/compress/zstd_ldm_geartab.h +106 -0
  177. src/native/everyday/zstd/compress/zstd_opt.c +1580 -0
  178. src/native/everyday/zstd/compress/zstd_opt.h +72 -0
  179. src/native/everyday/zstd/compress/zstd_preSplit.c +238 -0
  180. src/native/everyday/zstd/compress/zstd_preSplit.h +33 -0
  181. src/native/everyday/zstd/compress/zstdmt_compress.c +1923 -0
  182. src/native/everyday/zstd/compress/zstdmt_compress.h +102 -0
  183. src/native/everyday/zstd/decompress/huf_decompress.c +1944 -0
  184. src/native/everyday/zstd/decompress/zstd_ddict.c +244 -0
  185. src/native/everyday/zstd/decompress/zstd_ddict.h +44 -0
  186. src/native/everyday/zstd/decompress/zstd_decompress.c +2410 -0
  187. src/native/everyday/zstd/decompress/zstd_decompress_block.c +2209 -0
  188. src/native/everyday/zstd/decompress/zstd_decompress_block.h +73 -0
  189. src/native/everyday/zstd/decompress/zstd_decompress_internal.h +240 -0
  190. src/native/everyday/zstd/zstd.h +3198 -0
  191. src/native/everyday/zstd/zstd_errors.h +107 -0
  192. src/native/fast/lpaq1.cpp +846 -0
  193. src/native/fast/qtyp.c +158 -0
  194. src/native/libbsc/adler32/adler32.cpp +317 -0
  195. src/native/libbsc/adler32/adler32.h +66 -0
  196. src/native/libbsc/bwt/bwt.cpp +379 -0
  197. src/native/libbsc/bwt/bwt.h +78 -0
  198. src/native/libbsc/bwt/libcubwt/AUTHORS +11 -0
  199. src/native/libbsc/bwt/libcubwt/CHANGES +18 -0
  200. src/native/libbsc/bwt/libcubwt/LICENSE +201 -0
  201. src/native/libbsc/bwt/libcubwt/VERSION +1 -0
  202. src/native/libbsc/bwt/libcubwt/libcubwt.cu +3144 -0
  203. src/native/libbsc/bwt/libcubwt/libcubwt.cuh +107 -0
  204. src/native/libbsc/bwt/libsais/CHANGES +118 -0
  205. src/native/libbsc/bwt/libsais/LICENSE +219 -0
  206. src/native/libbsc/bwt/libsais/VERSION +1 -0
  207. src/native/libbsc/bwt/libsais/libsais.c +14328 -0
  208. src/native/libbsc/bwt/libsais/libsais.h +531 -0
  209. src/native/libbsc/coder/coder.cpp +589 -0
  210. src/native/libbsc/coder/coder.h +76 -0
  211. src/native/libbsc/coder/common/predictor.h +259 -0
  212. src/native/libbsc/coder/common/rangecoder.h +370 -0
  213. src/native/libbsc/coder/common/tables.h +1872 -0
  214. src/native/libbsc/coder/qlfc/qlfc.cpp +2590 -0
  215. src/native/libbsc/coder/qlfc/qlfc.h +139 -0
  216. src/native/libbsc/coder/qlfc/qlfc_model.cpp +102 -0
  217. src/native/libbsc/coder/qlfc/qlfc_model.h +305 -0
  218. src/native/libbsc/filters/detectors.cpp +584 -0
  219. src/native/libbsc/filters/preprocessing.cpp +180 -0
  220. src/native/libbsc/filters/tables.h +754 -0
  221. src/native/libbsc/filters.h +125 -0
  222. src/native/libbsc/libbsc/libbsc.cpp +684 -0
  223. src/native/libbsc/libbsc.h +184 -0
  224. src/native/libbsc/lzp/lzp.cpp +1315 -0
  225. src/native/libbsc/lzp/lzp.h +73 -0
  226. src/native/libbsc/platform/platform.cpp +278 -0
  227. src/native/libbsc/platform/platform.h +266 -0
  228. src/native/libbsc/st/st.cpp +1533 -0
  229. src/native/libbsc/st/st.cu +407 -0
  230. src/native/libbsc/st/st.cuh +69 -0
  231. src/native/libbsc/st/st.h +80 -0
  232. src/native/libqznative.so +0 -0
  233. src/native/mcm/Archive.cpp +907 -0
  234. src/native/mcm/Archive.hpp +201 -0
  235. src/native/mcm/BracketModel.hpp +150 -0
  236. src/native/mcm/CM-inl.hpp +684 -0
  237. src/native/mcm/CM.hpp +1149 -0
  238. src/native/mcm/COPYING +674 -0
  239. src/native/mcm/Compressor.cpp +133 -0
  240. src/native/mcm/Compressor.hpp +206 -0
  241. src/native/mcm/CyclicBuffer.hpp +186 -0
  242. src/native/mcm/DeltaFilter.hpp +99 -0
  243. src/native/mcm/Detector.hpp +660 -0
  244. src/native/mcm/Dict.hpp +1147 -0
  245. src/native/mcm/DivTable.hpp +54 -0
  246. src/native/mcm/Entropy.hpp +50 -0
  247. src/native/mcm/File.cpp +214 -0
  248. src/native/mcm/File.hpp +561 -0
  249. src/native/mcm/Filter.hpp +301 -0
  250. src/native/mcm/FilterTest.cpp +363 -0
  251. src/native/mcm/GD.hpp +147 -0
  252. src/native/mcm/HashTable.hpp +90 -0
  253. src/native/mcm/Huffman.cpp +66 -0
  254. src/native/mcm/Huffman.hpp +427 -0
  255. src/native/mcm/JPEG.hpp +68 -0
  256. src/native/mcm/LZ-inl.hpp +144 -0
  257. src/native/mcm/LZ.cpp +313 -0
  258. src/native/mcm/LZ.hpp +411 -0
  259. src/native/mcm/Log.hpp +139 -0
  260. src/native/mcm/MCM.cpp +585 -0
  261. src/native/mcm/MatchFinder.hpp +373 -0
  262. src/native/mcm/MatchModel.hpp +199 -0
  263. src/native/mcm/Memory.cpp +83 -0
  264. src/native/mcm/Memory.hpp +77 -0
  265. src/native/mcm/Mixer.hpp +382 -0
  266. src/native/mcm/Model.hpp +332 -0
  267. src/native/mcm/ProbMap.hpp +151 -0
  268. src/native/mcm/ProgressMeter.hpp +227 -0
  269. src/native/mcm/QZIP_PATCHES.diff +41 -0
  270. src/native/mcm/Range.hpp +239 -0
  271. src/native/mcm/Reorder.hpp +59 -0
  272. src/native/mcm/SSE.hpp +253 -0
  273. src/native/mcm/SimdCompat.hpp +11 -0
  274. src/native/mcm/StateMap.hpp +256 -0
  275. src/native/mcm/Stream.hpp +443 -0
  276. src/native/mcm/Tests.cpp +28 -0
  277. src/native/mcm/Tests.hpp +29 -0
  278. src/native/mcm/TurboCM.hpp +445 -0
  279. src/native/mcm/UTF8.hpp +97 -0
  280. src/native/mcm/Util.cpp +165 -0
  281. src/native/mcm/Util.hpp +562 -0
  282. src/native/mcm/Wav16.hpp +369 -0
  283. src/native/mcm/WordCounter.hpp +390 -0
  284. src/native/mcm/WordModel.hpp +320 -0
  285. src/native/mcm/X86Binary.hpp +229 -0
  286. src/native/mcm/sse2neon.h +11855 -0
  287. src/native/qtyp.exe +0 -0
  288. src/native/qz_bsc.c +64 -0
  289. src/native/qz_native.py +303 -0
  290. src/native/qz_wrt.c +135 -0
  291. src/native/qzcm.exe +0 -0
  292. src/native/qze.exe +0 -0
  293. src/native/qzlpaq.exe +0 -0
  294. src/native/qzmf.exe +0 -0
  295. src/quantum_image_compression.py +470 -0
  296. src/quantum_parameter_tuner.py +529 -0
  297. src/qzcore/.gitignore +1 -0
  298. src/qzcore/README.md +24 -0
  299. src/qzcore/RESULTS.md +288 -0
  300. src/qzcore/ROUTER.md +159 -0
  301. src/qzcore/__init__.py +0 -0
  302. src/qzcore/bench/bg.sh +4 -0
  303. src/qzcore/bench/medical/README.md +45 -0
  304. src/qzcore/bench/medical/med_outside.py +67 -0
  305. src/qzcore/bench/medical/med_outside.tsv +52 -0
  306. src/qzcore/bench/q_csv.sh +8 -0
  307. src/qzcore/bench/q_e9.sh +8 -0
  308. src/qzcore/bench/q_med.sh +3 -0
  309. src/qzcore/bench/refs.sh +22 -0
  310. src/qzcore/bench/router/corpus_files.txt +68 -0
  311. src/qzcore/bench/router/eval_c.tsv +60 -0
  312. src/qzcore/bench/router/eval_h.tsv +19 -0
  313. src/qzcore/bench/router/extra.tsv +61 -0
  314. src/qzcore/bench/router/extra2.tsv +4 -0
  315. src/qzcore/bench/router/features.tsv +54 -0
  316. src/qzcore/bench/router/gt.py +39 -0
  317. src/qzcore/bench/router/gt.tsv +333 -0
  318. src/qzcore/bench/router/gt_h.tsv +54 -0
  319. src/qzcore/bench/router/jobs1.txt +269 -0
  320. src/qzcore/bench/router/jobs3.txt +21 -0
  321. src/qzcore/bench/router/jobs_h.txt +54 -0
  322. src/qzcore/bench/router/router_eval.py +73 -0
  323. src/qzcore/bench/router/run_gt.sh +2 -0
  324. src/qzcore/bench/router/tsave.py +11 -0
  325. src/qzcore/bench/router/ver_c.jsonl +53 -0
  326. src/qzcore/bench/router/ver_c.txt +6 -0
  327. src/qzcore/bench/router/ver_c_policy.txt +5 -0
  328. src/qzcore/bench/router/ver_h.jsonl +12 -0
  329. src/qzcore/bench/router/ver_h.txt +7 -0
  330. src/qzcore/bench/router/ver_h_policy.txt +4 -0
  331. src/qzcore/bench/router/verify_detail.py +19 -0
  332. src/qzcore/bench/router/verify_eval.py +104 -0
  333. src/qzcore/bench/router/wt.py +11 -0
  334. src/qzcore/bench/rt.sh +13 -0
  335. src/qzcore/bench/tune.sh +6 -0
  336. src/qzcore/bench/wordmodel/README.md +34 -0
  337. src/qzcore/bench/wordmodel/bw.sh +10 -0
  338. src/qzcore/bench/wordmodel/conly.tsv +60 -0
  339. src/qzcore/bench/wordmodel/e2e.tsv +71 -0
  340. src/qzcore/build.sh +21 -0
  341. src/qzcore/qmed.py +544 -0
  342. src/qzcore/qtyp.c +163 -0
  343. src/qzcore/qtyp.exe +0 -0
  344. src/qzcore/qzb.cpp +44 -0
  345. src/qzcore/qzb.exe +0 -0
  346. src/qzcore/qzc.cpp +432 -0
  347. src/qzcore/qzc.exe +0 -0
  348. src/qzcore/qzc2.cpp +974 -0
  349. src/qzcore/qzc2.exe +0 -0
  350. src/qzcore/qzcsv.py +101 -0
  351. src/qzcore/qzm +2 -0
  352. src/qzcore/qzmed.py +67 -0
  353. src/qzcore/qzs +2 -0
  354. src/qzcore/tests/test_csv_endings.sh +35 -0
  355. src/qzcore/vendor/libbsc/AUTHORS +15 -0
  356. src/qzcore/vendor/libbsc/LICENSE +202 -0
  357. src/qzcore/vendor/libbsc/VERSION +1 -0
  358. src/qzcore/vendor/libbsc/adler32/adler32.cpp +317 -0
  359. src/qzcore/vendor/libbsc/adler32/adler32.h +66 -0
  360. src/qzcore/vendor/libbsc/bwt/bwt.cpp +379 -0
  361. src/qzcore/vendor/libbsc/bwt/bwt.h +78 -0
  362. src/qzcore/vendor/libbsc/bwt/libcubwt/AUTHORS +11 -0
  363. src/qzcore/vendor/libbsc/bwt/libcubwt/CHANGES +18 -0
  364. src/qzcore/vendor/libbsc/bwt/libcubwt/LICENSE +201 -0
  365. src/qzcore/vendor/libbsc/bwt/libcubwt/VERSION +1 -0
  366. src/qzcore/vendor/libbsc/bwt/libcubwt/libcubwt.cu +3144 -0
  367. src/qzcore/vendor/libbsc/bwt/libcubwt/libcubwt.cuh +107 -0
  368. src/qzcore/vendor/libbsc/bwt/libsais/CHANGES +118 -0
  369. src/qzcore/vendor/libbsc/bwt/libsais/LICENSE +219 -0
  370. src/qzcore/vendor/libbsc/bwt/libsais/VERSION +1 -0
  371. src/qzcore/vendor/libbsc/bwt/libsais/libsais.c +14328 -0
  372. src/qzcore/vendor/libbsc/bwt/libsais/libsais.h +531 -0
  373. src/qzcore/vendor/libbsc/coder/coder.cpp +589 -0
  374. src/qzcore/vendor/libbsc/coder/coder.h +76 -0
  375. src/qzcore/vendor/libbsc/coder/common/predictor.h +259 -0
  376. src/qzcore/vendor/libbsc/coder/common/rangecoder.h +370 -0
  377. src/qzcore/vendor/libbsc/coder/common/tables.h +1872 -0
  378. src/qzcore/vendor/libbsc/coder/qlfc/qlfc.cpp +2590 -0
  379. src/qzcore/vendor/libbsc/coder/qlfc/qlfc.h +139 -0
  380. src/qzcore/vendor/libbsc/coder/qlfc/qlfc_model.cpp +102 -0
  381. src/qzcore/vendor/libbsc/coder/qlfc/qlfc_model.h +305 -0
  382. src/qzcore/vendor/libbsc/filters/detectors.cpp +584 -0
  383. src/qzcore/vendor/libbsc/filters/preprocessing.cpp +180 -0
  384. src/qzcore/vendor/libbsc/filters/tables.h +754 -0
  385. src/qzcore/vendor/libbsc/filters.h +125 -0
  386. src/qzcore/vendor/libbsc/libbsc/libbsc.cpp +684 -0
  387. src/qzcore/vendor/libbsc/libbsc.h +184 -0
  388. src/qzcore/vendor/libbsc/lzp/lzp.cpp +1315 -0
  389. src/qzcore/vendor/libbsc/lzp/lzp.h +73 -0
  390. src/qzcore/vendor/libbsc/platform/platform.cpp +278 -0
  391. src/qzcore/vendor/libbsc/platform/platform.h +266 -0
  392. src/qzcore/vendor/libbsc/st/st.cpp +1533 -0
  393. src/qzcore/vendor/libbsc/st/st.cu +407 -0
  394. src/qzcore/vendor/libbsc/st/st.cuh +69 -0
  395. src/qzcore/vendor/libbsc/st/st.h +80 -0
  396. src/qzfast.py +174 -0
  397. src/qzip_fast_codecs.py +41 -0
  398. src/qzip_legacy_2025_10.py +5942 -0
  399. src/qzip_routes.py +308 -0
  400. src/qzpar.py +121 -0
  401. src/qzrouter.py +540 -0
  402. src/qzverify.py +192 -0
  403. src/safe_compress.py +310 -0
  404. webapp/__init__.py +1 -0
  405. webapp/api.py +192 -0
  406. webapp/templates/quantum_interface.html +1465 -0
  407. webapp/ui.py +1724 -0
qzip/__init__.py ADDED
@@ -0,0 +1,54 @@
1
+ """QZip: verified (byte-exact) compression. GPL-3.0-or-later (see LICENSE, NOTICE).
2
+
3
+ Library use::
4
+
5
+ import qzip
6
+ blob = qzip.compress_bytes(data) # Quick by default; returns .qz container bytes
7
+ assert qzip.decompress_bytes(blob) == data # sha256-checked against the original
8
+
9
+ Both functions run in-process on bytes. `compress_bytes` decodes its own output and compares the sha256 with the
10
+ input before returning, so a returned blob always round-trips. The blob is the same `.qz` format that
11
+ `qzip compress` and the web app write, so either side can open the other's files.
12
+ """
13
+ import os as _os
14
+ # Quiet, local-only defaults: no Ray cluster, no log file in the working directory.
15
+ _os.environ.setdefault("QZIP_NO_RAY", "1")
16
+ _os.environ.setdefault("QZIP_LOG_FILE", "")
17
+ __version__ = "1.2.1"
18
+
19
+ # Friendly names -> internal modes (same meaning as the CLI flags of the same name).
20
+ _API_MODES = {"quick": "quick", "fast": "tier-fast", "deep": "deep", "classic": "classic", "max": "auto-max"}
21
+
22
+ __all__ = ["compress_bytes", "decompress_bytes", "__version__"]
23
+
24
+
25
+ def compress_bytes(data, mode="quick", name=None):
26
+ """Compress `data` and return `.qz` container bytes.
27
+
28
+ data: bytes-like input.
29
+ mode: "quick" (default; CSV/log/JSON/SQLite-aware, tens of MB/s), "fast" (zstd-class speed), "deep",
30
+ "classic" (the v1.0 context-mixing engine: smaller on text/CSVs, ~2 MB/s, several GB of RAM) or
31
+ "max" (QZip's own x18/qzs codecs; slowest).
32
+ name: optional original file name to record in the header (shown by `qzip info`, used by the web app).
33
+
34
+ The result is verified before it is returned: it is decoded and its sha256 compared with `data`. If the chosen
35
+ codec ever fails that check, QZip falls back to xz (zstd above 32 MiB) rather than return a broken file.
36
+ """
37
+ if mode not in _API_MODES:
38
+ raise ValueError(f"mode must be one of {sorted(_API_MODES)}")
39
+ from qzip.core import compress_bytes as _compress, dump_container
40
+ container, _info = _compress(bytes(data), mode=_API_MODES[mode])
41
+ if name:
42
+ from qzip.identity import attach_identity
43
+ attach_identity(container, original_filename=_os.path.basename(str(name)))
44
+ return dump_container(container)
45
+
46
+
47
+ def decompress_bytes(blob):
48
+ """Decode `.qz` container bytes (or an older `.qc.gz` / `.qc` container) and return the original bytes.
49
+
50
+ Raises if the decoded bytes do not match the sha256 recorded in the container. Raw `qze` streams (`.qze` files
51
+ from the standalone engine) are not containers; decode those with `qze d`.
52
+ """
53
+ from qzip.core import load_container, decompress_container
54
+ return decompress_container(load_container(bytes(blob)))
qzip/__main__.py ADDED
@@ -0,0 +1,2 @@
1
+ from qzip.cli import main
2
+ raise SystemExit(main())
qzip/cli.py ADDED
@@ -0,0 +1,265 @@
1
+ """QZip — Quick Zip command line.
2
+
3
+ qzip compress <file> [-o out.qz] [--quick] [--classic] [--deep] [--fast] [--max]
4
+ [--mode quick|classic|deep|auto|auto-max|auto-fast|fast|max|ultra|legacy|hybrid|text]
5
+ [--codec NAME]
6
+ --quick (default) Quick: everyday qze -2. Beats xz -9 / 7z -9 / brotli -11 on a 719 MB mix at ~17 MB/s (8 threads)
7
+ --classic Classic: the launch method (mcm fork router / x18 exceptions)
8
+ --deep Deep: max tier (qze -3 for now; a stronger engine is in development)
9
+ auto alias of --classic
10
+ --max = --mode auto-max: smallest output from QZip's own codecs (x18 = qzc2 CM, qzs CSV/log
11
+ transform, qzm NIfTI); about 3x slower than classic on text, often slower still on CSV
12
+ auto-fast same analysis, among the fast codecs (qzb, zstd, stored)
13
+ --codec NAME override the prediction (qzmf, qzc2, qzc2_lean, qzs, qzm, qzb, qzb_w0, zstd, xz, stored)
14
+ --ram-mb MB RAM budget (default 3/4 of RAM): qzmf drops its level (11: ~6 GB, 10: ~3 GB), qzc2 -> lean
15
+ --no-verify skip the verifier (uncertain picks, e.g. qzm vs qzc2, are checked on a small sample)
16
+ fast routed by file type to the measured-best method (text: QWRT+libbsc; CSV: qtyp; ...)
17
+ max / ultra same router; text and logs use the CM text mode (4 x stock mcm -h11 / 2 x mcm -x11)
18
+ legacy original Oct-2025 routes only ("QZip today")
19
+ --fast everyday fast tier (qze -1): CSV column transform + zstd, parallel blocks; zstd-class speed
20
+ --balanced everyday balanced tier (qze -2): CSV transform + BWT / zstd -19; xz-class size or better, much faster
21
+ --strong = the default engine (mcm fork + QZip table/text models)
22
+ --smart [--goal everyday|open-often|archive] [--time-budget S] picks the tier from size / type / goal
23
+ qzip decompress <file.qz|file.qc.gz|file.qc> [-o out]
24
+ qzip verify <file.qz> [original]
25
+ qzip info <file.qz> show header: method, size, sha256, original name, source path
26
+ qzip bench <file> [--mode ...] QZip vs xz / zstd / brotli / bzip2 (all byte-exact checked)
27
+ qzip web [--host 127.0.0.1] [--port 5000] drag-and-drop web UI + local API (no API key)
28
+ """
29
+ import argparse, bz2, hashlib, lzma, os, sys, time
30
+
31
+ from src.safe_compress import MODES as _SAFE_MODES, DEFAULT_MODE
32
+ from src.qzrouter import CODECS
33
+ MODES = list(_SAFE_MODES)
34
+
35
+ def _mode(a):
36
+ if getattr(a, "ram_mb", None):
37
+ os.environ["QZIP_RAM_MB"] = str(a.ram_mb)
38
+ if getattr(a, "no_verify", False):
39
+ os.environ["QZIP_VERIFY"] = "0"
40
+ if getattr(a, "codec", None):
41
+ return f"codec:{a.codec}"
42
+ if getattr(a, "goal", None):
43
+ os.environ["QZIP_GOAL"] = a.goal
44
+ if getattr(a, "time_budget", None):
45
+ os.environ["QZIP_TIME_BUDGET"] = str(a.time_budget)
46
+ if getattr(a, "threads", None):
47
+ os.environ["QZIP_TIER_THREADS"] = str(a.threads)
48
+ tiers = [t for t in ("quick", "classic", "deep", "fast", "balanced", "strong", "smart") if getattr(a, t, False)]
49
+ if len(tiers) > 1 or (tiers and (getattr(a, "max", False) or a.mode != DEFAULT_MODE)):
50
+ sys.exit("qzip: pick one of --quick / --classic / --deep / --fast / --balanced / --strong / --smart / --max / --mode")
51
+ if tiers:
52
+ return {"quick": "quick", "classic": "classic", "deep": "deep",
53
+ "fast": "tier-fast", "balanced": "tier-balanced", "strong": "auto", "smart": "smart"}[tiers[0]]
54
+ if getattr(a, "max", False):
55
+ # "auto" / "classic" (the v1.0 default and its alias) still combine with --max: auto-max is Classic's max mode
56
+ if a.mode not in (DEFAULT_MODE, "auto", "classic", "auto-max"):
57
+ sys.exit("qzip: --max is --mode auto-max; do not combine it with another --mode")
58
+ return "auto-max"
59
+ return a.mode
60
+
61
+ def _out_name_decompress(path):
62
+ from qzip.container import strip_ext
63
+ return strip_ext(path) or path + ".out"
64
+
65
+ def _write(path, data, force):
66
+ if os.path.exists(path) and not force:
67
+ sys.exit(f"qzip: {path} exists (use -f to overwrite)")
68
+ with open(path, "wb") as f:
69
+ f.write(data)
70
+
71
+ def _tier_args(p):
72
+ g = p.add_argument_group("modes")
73
+ g.add_argument("--quick", action="store_true", help="Quick (default): everyday qze -2, xz-class or better size at tens of MB/s")
74
+ g.add_argument("--classic", action="store_true", help="Classic: the launch method (mcm-fork router / x18 exceptions)")
75
+ g.add_argument("--deep", action="store_true", help="Deep: max tier (qze -3 for now; a stronger engine is in development)")
76
+ g.add_argument("--fast", action="store_true", help="fast tier: zstd-class speed, CSV column transform + zstd")
77
+ g.add_argument("--balanced", action="store_true", help="same engine as --quick (qze -2)")
78
+ g.add_argument("--strong", action="store_true", help="same engine as --classic (mcm fork + QZip models)")
79
+ g.add_argument("--smart", action="store_true", help="pick the tier from file size/type and --goal")
80
+ g.add_argument("--goal", choices=("everyday", "open-often", "archive"), help="for --smart (default everyday)")
81
+ g.add_argument("--time-budget", type=float, help="--smart: seconds allowed for compress + decompress (default 10)")
82
+ g.add_argument("--threads", type=int, help="threads for the tiers (default min(8, idle cores))")
83
+
84
+ def cmd_compress(a):
85
+ from qzip.core import compress_bytes, dump_container
86
+ from qzip.identity import attach_identity, relative_source_path
87
+ data = open(a.file, "rb").read()
88
+ t = time.time()
89
+ container, info = compress_bytes(data, mode=_mode(a))
90
+ attach_identity(container, source_path=relative_source_path(a.file),
91
+ original_filename=os.path.basename(a.file))
92
+ blob = dump_container(container)
93
+ out = a.output or a.file + ".qz"
94
+ _write(out, blob, a.force)
95
+ src = container.get("source_path")
96
+ src_note = f" source={src}" if src else ""
97
+ print(f"{a.file}: {len(data):,} -> {len(blob):,} B ({len(data)/max(len(blob),1):.2f}:1) "
98
+ f"type={info.get('detected_type') or '-'} method={info.get('route_choice') or info['chosen']} "
99
+ f"verified=yes{src_note} {time.time()-t:.1f}s -> {out}")
100
+ if a.verbose:
101
+ f = ((container.get("quantum_parameters") or {}).get("qzip") or {}).get("features")
102
+ if f:
103
+ print(" analysis: " + " ".join(f"{k}={v}" for k, v in f.items()))
104
+ for m, r in info["tried"]:
105
+ print(f" tried {m}: {r}")
106
+ return 0
107
+
108
+ def cmd_decompress(a):
109
+ from qzip.core import load_container, decompress_container
110
+ c = load_container(open(a.file, "rb").read())
111
+ out_bytes = decompress_container(c) # raises if sha256 recorded and mismatched
112
+ out = a.output or _out_name_decompress(a.file)
113
+ _write(out, out_bytes, a.force)
114
+ from qzip.identity import identity_from_container
115
+ ident = identity_from_container(c)
116
+ sha_note = "verified" if c.get("orig_sha256") or (c.get("quantum_parameters") or {}).get("qzip") else "not recorded (old file)"
117
+ extra = []
118
+ if ident.get("original_filename"):
119
+ extra.append(f"name={ident['original_filename']}")
120
+ if ident.get("source_path"):
121
+ extra.append(f"source={ident['source_path']}")
122
+ if ident.get("orig_sha256"):
123
+ extra.append(f"sha256={ident['orig_sha256']}")
124
+ extra_s = (" " + " ".join(extra)) if extra else ""
125
+ print(f"{a.file} -> {out} ({len(out_bytes):,} B, sha256 {sha_note}{extra_s})")
126
+ return 0
127
+
128
+ def cmd_verify(a):
129
+ from qzip.core import load_container, decompress_container
130
+ c = load_container(open(a.file, "rb").read())
131
+ try:
132
+ out = decompress_container(c)
133
+ except Exception as e:
134
+ print(f"FAIL {a.file}: {e}"); return 1
135
+ ok = True
136
+ if a.original:
137
+ ok = hashlib.sha256(out).digest() == hashlib.sha256(open(a.original, "rb").read()).digest()
138
+ from qzip.identity import identity_from_container
139
+ ident = identity_from_container(c)
140
+ extra = []
141
+ if ident.get("original_filename"):
142
+ extra.append(f"name={ident['original_filename']}")
143
+ if ident.get("source_path"):
144
+ extra.append(f"source={ident['source_path']}")
145
+ if ident.get("orig_sha256"):
146
+ extra.append(f"sha256={ident['orig_sha256']}")
147
+ extra_s = (" " + " ".join(extra)) if extra else ""
148
+ print(f"{'OK' if ok else 'FAIL'} {a.file}: decodes to {len(out):,} B"
149
+ + (f", {'matches' if ok else 'DIFFERS FROM'} {a.original}" if a.original else "")
150
+ + extra_s)
151
+ return 0 if ok else 1
152
+
153
+ def _baselines(data):
154
+ res = []
155
+ def run(name, c, d):
156
+ t = time.time()
157
+ try:
158
+ z = c(data)
159
+ except Exception as e:
160
+ res.append((name, None, f"error {type(e).__name__}", 0)); return
161
+ dt = time.time() - t
162
+ ok = d(z) == data
163
+ res.append((name, len(z), "ok" if ok else "ROUNDTRIP FAIL", dt))
164
+ run("xz -9", lambda b: lzma.compress(b, preset=9), lzma.decompress)
165
+ try:
166
+ import zstandard as zs
167
+ p = zs.ZstdCompressionParameters.from_level(19, window_log=min(27, max(10, (len(data) - 1).bit_length())), enable_ldm=True)
168
+ run("zstd -19 --long", lambda b: zs.ZstdCompressor(compression_params=p).compress(b),
169
+ lambda z: zs.ZstdDecompressor().decompress(z, max_output_size=len(data) + 1))
170
+ except ImportError:
171
+ res.append(("zstd -19 --long", None, "pip install zstandard", 0))
172
+ try:
173
+ import brotli
174
+ run("brotli -11", lambda b: brotli.compress(b, quality=11, lgwin=24), brotli.decompress)
175
+ except ImportError:
176
+ res.append(("brotli -11", None, "pip install brotli", 0))
177
+ run("bzip2 -9", lambda b: bz2.compress(b, 9), bz2.decompress)
178
+ return res
179
+
180
+ def cmd_info(a):
181
+ from qzip.core import load_container
182
+ from qzip.identity import identity_from_container
183
+ raw = open(a.file, "rb").read()
184
+ c = load_container(raw)
185
+ ident = identity_from_container(c)
186
+ qp = (c.get("quantum_parameters") or {}).get("qzip") or {}
187
+ rows = [
188
+ ("file", a.file),
189
+ ("format", c.get("format") or qp.get("format") or "unknown"),
190
+ ("size", f"{len(raw):,} B"),
191
+ ("method", c.get("method") or "-"),
192
+ ("mode", qp.get("mode") or "-"),
193
+ ("codec", qp.get("chosen") or "-"),
194
+ ("orig_size", ident.get("orig_size") if ident.get("orig_size") is not None else c.get("orig_size") or "-"),
195
+ ("orig_sha256", ident.get("orig_sha256") or "not recorded"),
196
+ ("original_filename", ident.get("original_filename") or "not recorded"),
197
+ ("source_path", ident.get("source_path") or "not recorded"),
198
+ ("verified", c.get("verified") if "verified" in c else qp.get("verified", "-")),
199
+ ]
200
+ width = max(len(k) for k, _ in rows)
201
+ for k, v in rows:
202
+ print(f"{k:<{width}} {v}")
203
+ return 0
204
+
205
+ def cmd_bench(a):
206
+ from qzip.core import compress_bytes, dump_container, load_container, decompress_container
207
+ data = open(a.file, "rb").read()
208
+ print(f"{a.file}: {len(data):,} B")
209
+ t = time.time()
210
+ container, info = compress_bytes(data, mode=_mode(a))
211
+ blob = dump_container(container)
212
+ ct = time.time() - t
213
+ ok = decompress_container(load_container(blob)) == data
214
+ rows = [(f"qzip --mode {_mode(a)} [{info['chosen']}]", len(blob), "ok" if ok else "ROUNDTRIP FAIL", ct)]
215
+ rows += _baselines(data)
216
+ print(f"{'codec':42} {'bytes':>14} {'ratio':>9} {'secs':>8} check")
217
+ for name, n, st, dt in rows:
218
+ print(f"{name:42} {n if n is not None else '-':>14,} {(f'{len(data)/n:.2f}:1' if n else '-'):>9} {dt:8.1f} {st}"
219
+ if n is not None else f"{name:42} {'-':>14} {'-':>9} {'-':>8} {st}")
220
+ return 0
221
+
222
+ def cmd_native(a):
223
+ import subprocess
224
+ from src.native import qz_native as N
225
+ here = os.path.dirname(os.path.abspath(N.__file__))
226
+ r = subprocess.run(["make", "-C", os.path.dirname(os.path.dirname(here)), "native"])
227
+ if r.returncode:
228
+ return r.returncode
229
+ print(f"libqznative={'ok' if N.lib_available() else 'MISSING'} "
230
+ f"qzcm(max/ultra)={'ok' if N.cm_available() else 'not available'}")
231
+ return 0
232
+
233
+ def cmd_web(a):
234
+ from qzip.web import main as web_main
235
+ return web_main(host=a.host, port=a.port, api_port=a.api_port)
236
+
237
+ def main(argv=None):
238
+ ap = argparse.ArgumentParser(prog="qzip", description="QZip — Quick Zip (verified compression, GPL-3.0-or-later)")
239
+ sub = ap.add_subparsers(dest="cmd", required=True)
240
+ p = sub.add_parser("compress"); p.add_argument("file"); p.add_argument("-o", "--output")
241
+ p.add_argument("--mode", choices=MODES, default=DEFAULT_MODE); p.add_argument("-f", "--force", action="store_true")
242
+ p.add_argument("--max", action="store_true", help="= --mode auto-max: x18 / qzs, smallest, slowest")
243
+ _tier_args(p)
244
+ p.add_argument("--codec", choices=CODECS, help="override the predicted codec"); p.add_argument("--ram-mb", type=int)
245
+ p.add_argument("--no-verify", action="store_true", help="skip the sample check of uncertain picks (src/qzverify.py)")
246
+ p.add_argument("-v", "--verbose", action="store_true"); p.set_defaults(fn=cmd_compress)
247
+ p = sub.add_parser("decompress"); p.add_argument("file"); p.add_argument("-o", "--output")
248
+ p.add_argument("-f", "--force", action="store_true"); p.set_defaults(fn=cmd_decompress)
249
+ p = sub.add_parser("verify"); p.add_argument("file"); p.add_argument("original", nargs="?"); p.set_defaults(fn=cmd_verify)
250
+ p = sub.add_parser("info", help="show .qz header fields (name, source path, sha256)"); p.add_argument("file"); p.set_defaults(fn=cmd_info)
251
+ p = sub.add_parser("bench"); p.add_argument("file"); p.add_argument("--mode", choices=MODES, default=DEFAULT_MODE)
252
+ p.add_argument("--max", action="store_true", help="= --mode auto-max")
253
+ _tier_args(p)
254
+ p.add_argument("--codec", choices=CODECS); p.add_argument("--ram-mb", type=int); p.add_argument("--no-verify", action="store_true")
255
+ p.set_defaults(fn=cmd_bench)
256
+ p = sub.add_parser("web"); p.add_argument("--host", default=os.getenv("QZIP_WEB_HOST", "127.0.0.1"))
257
+ p.add_argument("--port", type=int, default=int(os.getenv("QZIP_WEB_PORT", "5000")))
258
+ p.add_argument("--api-port", type=int, default=int(os.getenv("QZIP_API_PORT", "8000"))); p.set_defaults(fn=cmd_web)
259
+ p = sub.add_parser("native", help="build/check the native text codecs (make native)")
260
+ p.set_defaults(fn=cmd_native)
261
+ a = ap.parse_args(argv)
262
+ return a.fn(a)
263
+
264
+ if __name__ == "__main__":
265
+ raise SystemExit(main())
qzip/container.py ADDED
@@ -0,0 +1,52 @@
1
+ """QZip file container (`.qz`).
2
+
3
+ Layout (format qzip-2, all new files):
4
+ b"QZIP" | version byte 0x02 | u32 little-endian header length | header (compact UTF-8 JSON) | payload (raw bytes)
5
+ The header holds everything except the payload: method, reconstruction_metadata, quantum_parameters (incl. the
6
+ qzip block: orig_sha256, orig_size, decoder, route...), orig_sha256, orig_size, and optional identity fields
7
+ (original_filename, source_path: a sanitized relative path, never absolute and never `..`). Older readers ignore
8
+ unknown JSON keys, so v1.0.0 still opens files that carry these fields. The payload is the codec output as
9
+ is: no base64, no gzip, so the file is the benchmarked size plus a few hundred bytes of header.
10
+
11
+ Readers also accept the older containers: JSON with a base64 payload, optionally gzipped and/or space-padded
12
+ (CLI `.qc.gz` and web-app `.qc` / `.qc.gz` files, 2025-2026).
13
+ """
14
+ import base64, gzip, json, struct
15
+
16
+ MAGIC = b"QZIP\x02"
17
+ EXT = ".qz"
18
+ OLD_EXTS = (".qc.gz", ".qc")
19
+
20
+
21
+ def pack(container):
22
+ """Container dict (compressed_data as base64 str or bytes) -> .qz bytes."""
23
+ cd = container.get("compressed_data")
24
+ payload = base64.b64decode(cd) if isinstance(cd, str) else bytes(cd or b"")
25
+ head = {k: v for k, v in container.items() if k != "compressed_data"}
26
+ head["format"] = "qzip-2"
27
+ hb = json.dumps(head, separators=(",", ":"), sort_keys=True).encode("utf-8")
28
+ return MAGIC + struct.pack("<I", len(hb)) + hb + payload
29
+
30
+
31
+ def unpack(raw):
32
+ """.qz bytes or an older .qc / .qc.gz container -> container dict (compressed_data as base64 str)."""
33
+ raw = bytes(raw)
34
+ if raw[:5] == MAGIC:
35
+ (n,) = struct.unpack("<I", raw[5:9])
36
+ if 9 + n > len(raw):
37
+ raise ValueError("truncated .qz header")
38
+ c = json.loads(raw[9:9 + n].decode("utf-8"))
39
+ c["compressed_data"] = base64.b64encode(raw[9 + n:]).decode("ascii")
40
+ return c
41
+ if raw[:4] == b"QZIP":
42
+ raise ValueError(f"unsupported .qz version {raw[4]} (newer QZip?)")
43
+ if raw[:2] == b"\x1f\x8b":
44
+ raw = gzip.decompress(raw)
45
+ return json.loads(raw.decode("utf-8").rstrip()) # web .qc files carry trailing space padding
46
+
47
+
48
+ def strip_ext(name):
49
+ for suf in (EXT,) + OLD_EXTS:
50
+ if name.endswith(suf):
51
+ return name[: -len(suf)]
52
+ return None
qzip/core.py ADDED
@@ -0,0 +1,38 @@
1
+ """Thin library API used by the CLI and tests: compress_bytes / decompress_bytes / read/write .qz containers (and older .qc/.qc.gz)."""
2
+ import gzip, json, logging
3
+ import qzip # noqa: F401 (sets env defaults before the engine is imported)
4
+
5
+ _ENGINE = {}
6
+
7
+ def engine():
8
+ if 'e' not in _ENGINE:
9
+ logging.disable(logging.CRITICAL)
10
+ from src.elliott_quantum_compression_enterprise import ElliottQuantumCompressionEnterprise, CompressionConfig
11
+ _ENGINE['e'] = ElliottQuantumCompressionEnterprise(CompressionConfig())
12
+ return _ENGINE['e']
13
+
14
+ class _LazyEngine:
15
+ """Builds the enterprise engine on first use: the auto router (qzcore codecs) and stored/xz/zstd containers
16
+ never touch it, so they skip its ~10 s import."""
17
+ def __getattr__(self, name):
18
+ return getattr(engine(), name)
19
+
20
+ def compress_bytes(data, mode=None):
21
+ """Return (container_dict, info). The container is guaranteed to decode byte-exact (verified here)."""
22
+ from src.safe_compress import safe_compress
23
+ return safe_compress(_LazyEngine(), data, mode=mode)
24
+
25
+ def decompress_container(container):
26
+ from src.safe_compress import safe_decompress
27
+ return safe_decompress(_LazyEngine(), container)
28
+
29
+ def dump_container(container, gz=None):
30
+ """Container dict -> `.qz` bytes (format qzip-2: small JSON header + raw payload; see qzip/container.py).
31
+ `gz` is ignored (kept for API compatibility: the payload is already compressed, base64+gzip only added ~1%)."""
32
+ from qzip.container import pack
33
+ return pack(container)
34
+
35
+ def load_container(raw):
36
+ """`.qz` bytes, or an older `.qc.gz` / `.qc` JSON container -> container dict."""
37
+ from qzip.container import unpack
38
+ return unpack(raw)
qzip/identity.py ADDED
@@ -0,0 +1,207 @@
1
+ """Identity fields for `.qz` archives: original basename, a sanitized relative source path, and download names.
2
+
3
+ The qzip-2 header is compact UTF-8 JSON. Extra keys are ignored by older readers (v1.0.0 and earlier),
4
+ so adding `original_filename` and `source_path` is backward compatible. Absolute paths and `..`
5
+ components are never stored.
6
+ """
7
+ from __future__ import annotations
8
+
9
+ import os
10
+ import re
11
+ from urllib.parse import quote
12
+
13
+ MAX_SOURCE_PATH = 1024
14
+ SHORT_SHA_LEN = 6
15
+
16
+ _DRIVE = re.compile(r"^[A-Za-z]:[/\\]?")
17
+ _UNC = re.compile(r"^//[^/]+/[^/]+/")
18
+
19
+
20
+ def short_sha(sha256, n=SHORT_SHA_LEN):
21
+ if not sha256:
22
+ return ""
23
+ s = str(sha256).strip().lower()
24
+ if s.startswith("sha256:"):
25
+ s = s.split(":", 1)[1]
26
+ return s[: int(n)]
27
+
28
+
29
+ def clean_basename(name):
30
+ return _clean_basename(name)
31
+
32
+
33
+ def _clean_basename(name):
34
+ if not name:
35
+ return None
36
+ name = str(name).replace("\\", "/").replace("\x00", "").strip()
37
+ name = name.rstrip("/")
38
+ if not name or name in (".", ".."):
39
+ return None
40
+ base = name.rsplit("/", 1)[-1].strip()
41
+ if not base or base in (".", ".."):
42
+ return None
43
+ return base
44
+
45
+
46
+ def sanitize_source_path(path, basename=None):
47
+ """Return a relative POSIX path with no `..` and no absolute root, or the basename, or None.
48
+
49
+ Unsafe input (absolute paths that cannot be reduced, `..` components, NUL, UNC roots,
50
+ Windows drive letters) is stripped down to a relative path or to `basename`.
51
+ """
52
+ fallback = _clean_basename(basename) or _clean_basename(path)
53
+ if path is None:
54
+ return fallback
55
+ text = str(path).replace("\x00", "").replace("\\", "/").strip()
56
+ if not text:
57
+ return fallback
58
+ # RFC 8089 / Windows: strip file://, drive letters, and UNC //server/share/
59
+ if text.lower().startswith("file:"):
60
+ text = re.sub(r"^[Ff][Ii][Ll][Ee]:/*", "", text)
61
+ text = _DRIVE.sub("", text)
62
+ if text.startswith("//"):
63
+ text = _UNC.sub("", text)
64
+ text = text.lstrip("/")
65
+ parts = []
66
+ for part in text.split("/"):
67
+ if part in ("", "."):
68
+ continue
69
+ if part == "..":
70
+ return fallback
71
+ parts.append(part)
72
+ if not parts:
73
+ return fallback
74
+ rel = "/".join(parts)
75
+ if len(rel) > MAX_SOURCE_PATH:
76
+ rel = rel[-MAX_SOURCE_PATH:]
77
+ if "/" in rel:
78
+ rel = rel.split("/", 1)[-1]
79
+ return rel or fallback
80
+
81
+
82
+ def relative_source_path(path, cwd=None, basename=None):
83
+ """Best relative path to record for a CLI or filesystem input. Never absolute, never `..`."""
84
+ base = basename or _clean_basename(path)
85
+ if path is None or str(path).strip() == "":
86
+ return sanitize_source_path(base, basename=base)
87
+ raw = os.path.expanduser(str(path))
88
+ cwd = os.path.abspath(cwd or os.getcwd())
89
+ if not os.path.isabs(raw):
90
+ return sanitize_source_path(raw, basename=base)
91
+ try:
92
+ rel = os.path.relpath(os.path.abspath(raw), cwd)
93
+ except ValueError:
94
+ rel = None
95
+ if rel is None or rel == "." or rel.startswith(".." + os.sep) or rel == ".." or os.path.isabs(rel):
96
+ parent = os.path.basename(os.path.dirname(os.path.abspath(raw)))
97
+ name = os.path.basename(os.path.abspath(raw)) or base
98
+ if parent and parent not in (os.sep, "", ".", ".."):
99
+ return sanitize_source_path(f"{parent}/{name}", basename=name)
100
+ return sanitize_source_path(name, basename=name)
101
+ return sanitize_source_path(rel.replace("\\", "/"), basename=base)
102
+
103
+
104
+ def parent_dir(source_path):
105
+ rel = sanitize_source_path(source_path)
106
+ if not rel or "/" not in rel:
107
+ return None
108
+ parent = rel.rsplit("/", 1)[0]
109
+ if not parent or parent in (".", ".."):
110
+ return None
111
+ return parent.rsplit("/", 1)[-1]
112
+
113
+
114
+ def attach_identity(container, source_path=None, original_filename=None):
115
+ """Write `original_filename` and `source_path` onto a container dict (in place) and return it.
116
+
117
+ Older readers ignore these keys. `original_filename` is always a basename. `source_path` is a
118
+ sanitized relative path, omitted when it would be empty.
119
+ """
120
+ container = container if isinstance(container, dict) else {}
121
+ base = _clean_basename(original_filename) or _clean_basename(source_path)
122
+ rel = sanitize_source_path(source_path, basename=base)
123
+ if base:
124
+ container["original_filename"] = base
125
+ if rel:
126
+ container["source_path"] = rel
127
+ return container
128
+
129
+
130
+ def identity_from_container(container):
131
+ """Pull identity fields out of a container (missing on v1.0.0 files)."""
132
+ container = container or {}
133
+ qp = (container.get("quantum_parameters") or {}).get("qzip") or {}
134
+ base = _clean_basename(container.get("original_filename")) or _clean_basename(qp.get("original_filename"))
135
+ rel = sanitize_source_path(
136
+ container.get("source_path") or qp.get("source_path"),
137
+ basename=base,
138
+ )
139
+ sha = container.get("orig_sha256") or qp.get("orig_sha256")
140
+ return {
141
+ "original_filename": base,
142
+ "source_path": rel,
143
+ "orig_sha256": sha,
144
+ "orig_sha256_short": short_sha(sha),
145
+ "orig_size": container.get("orig_size") or qp.get("orig_size"),
146
+ }
147
+
148
+
149
+ def _safe_component(text, fallback="file"):
150
+ text = (text or "").replace("\x00", "").replace("/", "_").replace("\\", "_").strip()
151
+ text = text.replace("\r", " ").replace("\n", " ")
152
+ return text or fallback
153
+
154
+
155
+ def download_name(original_filename, source_path=None, orig_sha256=None, used_names=None, ext=".qz"):
156
+ """Pick a Content-Disposition download name.
157
+
158
+ Uses `{basename}{ext}` when that is unique in `used_names`. On a collision, prefers
159
+ `{basename} ({parent}){ext}`, then `{basename}.{shortsha}{ext}`.
160
+ """
161
+ ext = ext or ""
162
+ base = _safe_component(_clean_basename(original_filename) or _clean_basename(source_path) or "download")
163
+ used = set(used_names or ())
164
+ preferred = f"{base}{ext}"
165
+ if preferred not in used:
166
+ return preferred
167
+ parent = parent_dir(source_path)
168
+ if parent:
169
+ with_parent = f"{base} ({_safe_component(parent)}){ext}"
170
+ if with_parent not in used:
171
+ return with_parent
172
+ tagged = f"{base} ({_safe_component(parent)}).{short_sha(orig_sha256) or 'dup'}{ext}"
173
+ if tagged not in used:
174
+ return tagged
175
+ sha = short_sha(orig_sha256) or "dup"
176
+ candidate = f"{base}.{sha}{ext}"
177
+ if candidate not in used:
178
+ return candidate
179
+ n = 2
180
+ while True:
181
+ extra = f"{base}.{sha}.{n}{ext}"
182
+ if extra not in used:
183
+ return extra
184
+ n += 1
185
+
186
+
187
+ def ascii_fallback_filename(name):
188
+ """ASCII filename= token for Content-Disposition (no quotes, backslashes, or controls)."""
189
+ out = []
190
+ for ch in str(name or ""):
191
+ o = ord(ch)
192
+ if ch in '"\\:\r\n/' or o < 32 or o == 127:
193
+ out.append("_")
194
+ elif o >= 128:
195
+ out.append("_")
196
+ else:
197
+ out.append(ch)
198
+ s = "".join(out).strip(" .") or "download"
199
+ return s
200
+
201
+
202
+ def content_disposition(filename):
203
+ """RFC 6266 / RFC 5987 Content-Disposition: ASCII filename plus UTF-8 filename*."""
204
+ name = str(filename or "download").replace("\x00", "").replace("\r", "").replace("\n", "")
205
+ fallback = ascii_fallback_filename(name)
206
+ starred = "UTF-8''" + quote(name, safe="")
207
+ return f'attachment; filename="{fallback}"; filename*={starred}'