Pure Nim implementation of deflate, zlib, gzip and zip.
Go to file
Ryan Oldenburg a50985ff8d formatting 2020-11-08 17:34:09 -06:00
.github/workflows update github actions dep 2020-10-25 15:04:43 -05:00
examples formatting 2020-11-08 17:34:09 -06:00
src formatting 2020-11-08 17:34:09 -06:00
tests formatting 2020-11-08 17:34:09 -06:00
.gitignore ingore dll 2020-11-02 22:05:29 -06:00
LICENSE license 2020-10-13 20:05:19 -05:00
README.md update benchmarks 2020-11-08 17:32:26 -06:00
zippy.nimble 0.2.0 2020-11-08 12:02:19 -06:00

README.md

Zippy

nimble install zippy

Zippy is an implementation of DEFLATE, ZLIB, GZIP and ZIP archives (in-progress).

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 also works using both nim c and nim cpp, in addition to --cc:vcc on Windows.

I have also verified that Zippy builds with --experimental:strictFuncs on Nim 1.4.0.

NOTE: This library is in active development. It is tested and should work well, but the API is not yet stable.

Examples

Simple examples using Zippy can be found in the examples/ folder. This includes an HTTP client and HTTP server example for handing gzip'ed requests and responses.

Performance

Benchmarks can be run comparing different deflate implementations. My benchmarking shows this library performs very well but it is not quite as fast as zlib itself (not a surprise). Check the performance yourself by running tests/benchmark.nim.

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

Compress

Each file is compressed 1000 times.

https://github.com/guzba/zippy compress results:

File Time % Size Reduction
alice29.txt 6.3391s 62.33%
urls.10K 19.9189s 67.01%
rfctest3.gold 1.1809s 70.91%
randtest3.gold 0.1285s 0%

https://github.com/nim-lang/zip compress results: (Requires zlib1.dll)

File Time % Size Reduction
alice29.txt 7.0150s 64.23%
urls.10K 16.6361s 68.29%
rfctest3.gold 0.8147s 71.74%
randtest3.gold 0.1545s 0%

Uncompress

Each file is uncompressed 1000 times.

https://github.com/guzba/zippy uncompress results:

File Time
alice29 1.3988s
urls.10K 7.3736s
rfctest3.gold 0.2936s
randtest3.gold 0.0398s

https://github.com/nim-lang/zip uncompress results: (Requires zlib1.dll)

File Time
alice29 0.4929s
urls.10K 2.2334s
rfctest3.gold 0.1148s
randtest3.gold 0.0053s

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 do run the fuzzer any time by running nim c -r tests/fuzz.nim

API: zippy

import zippy

type CompressedDataFormat

Supported compressed data formats

CompressedDataFormat = enum
 dfDetect, dfZlib, dfGzip, dfDeflate

func compress

Compresses src and returns the compressed data.

func compress(src: seq[uint8]; dataFormat = dfGzip): seq[uint8] {.raises: [ZippyError].}

template compress

Helper for when preferring to work with strings.

template compress(src: string; dataFormat = dfGzip): string

func uncompress

Uncompresses src and returns the uncompressed data seq.

func uncompress(src: seq[uint8]; dataFormat = dfDetect): seq[uint8] {.raises: [ZippyError].}

template uncompress

Helper for when preferring to work with strings.

template uncompress(src: string; dataFormat = dfDetect): string