moonzip — compression for MoonBit: DEFLATE and gzip, one algorithm to a package.
let small = @gzip.gzip(body[:])
let back = @gzip.gunzip(small[:]) // raises if the checksum disagrees
// The raw stream, for a protocol that carries its own framing.
@deflate.deflate(body[:])
@deflate.inflate(stream[:])| Package | What | Specification |
|---|---|---|
| deflate | DEFLATE, both directions | RFC 1951 |
| gzip | The gzip container, with CRC-32 | RFC 1952 |
| zlib | The zlib container, with Adler-32 | RFC 1950 |
@deflate.deflate(body[:]) // level 6, a 32 KiB window
@deflate.deflate(body[:], level=9) // search hardest
@deflate.deflate(body[:], level=0) // store, do not compress
@deflate.deflate(body[:], chain=2048) // set the search depth directly
@deflate.inflate(stream[:], limit=1 << 20) // refuse to expand past a megabyte
@gzip.gzip(body[:], name="report.csv", mtime=written_at)
@gzip.gunzip(stream[:], checksum=false) // read what a damaged stream holds| Setting | Default | Why that one |
|---|---|---|
| level | 6 | zlib's default, and Go's, Python's and Node's. It maps to the same search depths zlib's own table uses, so a level here means what it means there |
| window | 32768 | The most DEFLATE allows, and the only size a reader can be assumed to handle |
| chain | from level | For a caller who would rather set the depth than pick a level |
| limit | unbounded | What every library does. A reader handling input from elsewhere should set it: a compressed stream says nothing about how far it expands |
| mtime | 0 | So the same input gives the same bytes. Go's gzip.Writer also writes zero unless told otherwise; a compressor that stamped the clock would make a build unreproducible |
| checksum, length, header_crc | on | A container that carries a checksum and does not look at it is not a container. Off is for reading what a damaged stream still holds |
moon add moonbitstack/moonzipInstall
Download zipmoonzip — compression for MoonBit: DEFLATE and gzip, one algorithm to a package.