Deflate

:= []
compress : List(U8), Level -> List(U8)

Compress bytes into a raw DEFLATE stream at the given level.

This never fails. It crashes only on a bug in this package.

compress_bound : U64 -> U64

The largest a compressed stream can be, matching libdeflate's bound.

The compressor never uses a compressed block where an uncompressed one would be cheaper, so the worst case is all uncompressed blocks: five bytes of header each, over blocks no shorter than the minimum block length.

decompress_into : List(U8), List(U8) -> Try(List(U8), DeflateError)

Decompress a raw DEFLATE stream, appending the output to out.

Passing a list with enough spare capacity for the whole result means the decompressor never reallocates mid-stream, and a returned list can be emptied with its capacity kept and passed back in for the next stream.

The stream cannot refer back into the bytes out already holds. A match that reaches past the start of the stream's own output is CorruptData, the same as with an empty out.

Level

Deflate.Level :: # (opaque)

A compression level from 0 to 12, with libdeflate's meaning: 0 stores the input without compressing it, 1 is the fastest, 6 the usual default, and 12 searches hardest.

A number literal is a Level wherever one is expected, so Deflate.compress(bytes, 6) works, and a literal outside 0 to 12 is a compile-time error. A level only known at runtime, such as one read from a command-line argument, goes through from_u64.

from_numeral : Numeral -> Try(Level, [InvalidNumeral(Str)])

Turn a number literal into a level when the program is compiled, rejecting any literal that is not a whole number from 0 to 12.

from_u64 : U64 -> Try(Level, [OutOfRange])

The level for a number only known at runtime.

to_u64 : Level -> U64

The level's number, from 0 to 12.

all : List(Level)

Every level, from 0 to 12.