项目作者: guzba

项目描述 :
Pure Nim implementation of deflate, zlib, gzip and zip.
高级语言: Nim
项目地址: git://github.com/guzba/zippy.git
创建时间: 2020-10-14T00:59:06Z
项目社区:https://github.com/guzba/zippy

开源协议:MIT License

下载


Zippy

nimble install zippy

Github Actions

API reference

Zippy is an implementation of DEFLATE, ZLIB and GZIP data compression formats.

Zippy can also open ZIP archives) (.zip) and Tarballs) (.tar, .tar.gz, .tgz, .taz).

The goal of this library is to be a pure Nim implementation that is small, performant and dependency-free.

To ensure Zippy is compatible with other implementations, tests/validate.nim can be run. This script verifies that data compressed by Zippy can be uncompressed by other implementations (and that other implementations can uncompress data compressed by Zippy).

This library works well using Nim’s --gc:arc and --gc:orc as well as the default garbage collector. This library also works using both nim c and nim cpp, in addition to --cc:vcc on Windows.

Examples

Simple examples using Zippy can be found in the examples/ folder.

Performance

Benchmarks can be run comparing different deflate implementations. My benchmarking shows this library performs very well, around 1.5x - 2x faster than zlib found on a fresh Linux install. Check the performance yourself by running tests/benchmark.nim.

nim c --gc:arc -d:release -r .\tests\benchmark.nim

The times below are measured on a Ryzen 5 5600X.

Uncompress

  1. https://github.com/guzba/zippy uncompress
  2. name ............................... min time avg time std dv runs
  3. alice29.txt.gz ..................... 0.233 ms 0.235 ms ±0.003 x1000
  4. urls.10K.gz ........................ 1.140 ms 1.148 ms ±0.007 x1000
  5. rfctest3.gz ........................ 0.047 ms 0.048 ms ±0.001 x1000
  6. randtest3.gz ....................... 0.001 ms 0.001 ms ±0.000 x1000
  7. paper-100k.pdf.gz .................. 0.210 ms 0.212 ms ±0.001 x1000
  8. geo.protodata.gz ................... 0.068 ms 0.071 ms ±0.002 x1000
  9. tor-list.gz ....................... 27.297 ms 27.520 ms ±0.277 x182
  10. https://github.com/nim-lang/zip uncompress
  11. alice29.txt.gz ..................... 0.397 ms 0.403 ms ±0.004 x1000
  12. urls.10K.gz ........................ 1.719 ms 1.731 ms ±0.009 x1000
  13. rfctest3.gz ........................ 0.054 ms 0.055 ms ±0.002 x1000
  14. randtest3.gz ....................... 0.008 ms 0.008 ms ±0.000 x1000
  15. paper-100k.pdf.gz .................. 0.250 ms 0.252 ms ±0.001 x1000
  16. geo.protodata.gz ................... 0.126 ms 0.132 ms ±0.005 x1000
  17. tor-list.gz ....................... 36.613 ms 37.061 ms ±0.423 x135

Compress

  1. https://github.com/guzba/zippy compress [best speed]
  2. name ............................... min time avg time std dv runs
  3. alice29.txt ........................ 0.643 ms 0.655 ms ±0.017 x1000
  4. urls.10K ........................... 1.943 ms 1.959 ms ±0.022 x1000
  5. rfctest3.gold ...................... 0.119 ms 0.121 ms ±0.003 x1000
  6. randtest3.gold ..................... 0.005 ms 0.006 ms ±0.001 x1000
  7. paper-100k.pdf ..................... 0.230 ms 0.235 ms ±0.003 x1000
  8. geo.protodata ...................... 0.192 ms 0.195 ms ±0.003 x1000
  9. gzipfiletest.txt ................... 0.002 ms 0.002 ms ±0.000 x1000
  10. tor-list.gold ..................... 26.106 ms 26.418 ms ±0.370 x189
  11. https://github.com/nim-lang/zip compress [best speed]
  12. alice29.txt ........................ 1.236 ms 1.245 ms ±0.010 x1000
  13. urls.10K ........................... 5.155 ms 5.222 ms ±0.092 x952
  14. rfctest3.gold ...................... 0.205 ms 0.232 ms ±0.009 x1000
  15. randtest3.gold ..................... 0.076 ms 0.097 ms ±0.013 x1000
  16. paper-100k.pdf ..................... 1.250 ms 1.276 ms ±0.023 x1000
  17. geo.protodata ...................... 0.313 ms 0.320 ms ±0.006 x1000
  18. gzipfiletest.txt ................... 0.006 ms 0.008 ms ±0.001 x1000
  19. tor-list.gold .................... 178.197 ms 179.970 ms ±1.559 x28
  20. https://github.com/guzba/zippy compress [default]
  21. name ............................... min time avg time std dv runs
  22. alice29.txt ........................ 2.361 ms 2.379 ms ±0.024 x1000
  23. urls.10K .......................... 13.364 ms 13.432 ms ±0.036 x372
  24. rfctest3.gold ...................... 0.335 ms 0.342 ms ±0.009 x1000
  25. randtest3.gold ..................... 0.048 ms 0.049 ms ±0.000 x1000
  26. paper-100k.pdf ..................... 0.831 ms 0.843 ms ±0.010 x1000
  27. geo.protodata ...................... 0.563 ms 0.570 ms ±0.007 x1000
  28. gzipfiletest.txt ................... 0.008 ms 0.008 ms ±0.001 x1000
  29. tor-list.gold .................... 409.542 ms 411.858 ms ±1.779 x13
  30. https://github.com/nim-lang/zip compress [default]
  31. alice29.txt ........................ 5.726 ms 5.766 ms ±0.053 x862
  32. urls.10K .......................... 13.049 ms 13.106 ms ±0.057 x381
  33. rfctest3.gold ...................... 0.637 ms 0.644 ms ±0.007 x1000
  34. randtest3.gold ..................... 0.083 ms 0.087 ms ±0.007 x1000
  35. paper-100k.pdf ..................... 1.467 ms 1.490 ms ±0.023 x1000
  36. geo.protodata ...................... 0.867 ms 0.879 ms ±0.011 x1000
  37. gzipfiletest.txt ................... 0.009 ms 0.010 ms ±0.001 x1000
  38. tor-list.gold .................... 244.424 ms 246.601 ms ±1.630 x21

Testing

nimble test

To prevent Zippy from causing a crash or otherwise misbehaving on bad input data, a fuzzer has been run against it. You can run the fuzzer any time by running nim c -r tests/fuzz.nim and nim c -r tests/stress.nim