One-shot compression codecs for the aoughwl
stack — gzip, Brotli, and Zstandard — over the system libraries. Protocol-
agnostic string → string: no streaming state, no HTTP assumptions.
import compress
let gz = gzipCompress("...") # Content-Encoding: gzip
let back = gzipDecompress(gz)
let br = brotliCompress("...") # Content-Encoding: br
let zs = zstdCompress("...") # Content-Encoding: zstd| Codec | Functions | Library |
|---|---|---|
| gzip / zlib | gzipCompress / gzipDecompress |
libz.so.1 |
| Brotli | brotliCompress / brotliDecompress |
libbrotlienc / libbrotlidec |
| Zstandard | zstdCompress / zstdDecompress |
libzstd.so.1 |
Each is a single call over an in-memory string. Decompressors are bounded by a
maxSize argument. "" signals an error (bad input, library failure).
The codecs are general-purpose: http layers
Content-Encoding negotiation (pickEncoding / encodeFor) on top for HTTP, but
a WebSocket (permessage-deflate), an on-disk blob store, or any binary protocol
can depend on just this package without pulling in HTTP.
- The zlib
z_streamstruct is hand-laid to the LP64 C ABI (no zlib headers needed); gzip uses window bits 31 (deflate) / 47 (auto-detect inflate). - Brotli and Zstd use their one-shot APIs (
BrotliEncoderCompress,ZSTD_compress), sized viaBrotliEncoderMaxCompressedSize/ZSTD_compressBound.
nimony c -r --path:. tests/tcodecs.nim
Round-trips a compressible sample through all three codecs (verifying each shrinks
it and restores it byte-for-byte; gzip additionally checks the 1f 8b magic).
Nimony; libz, libbrotlienc/libbrotlidec, libzstd (all standard on Linux).
MIT.