std.compress
Compresses and decompresses DEFLATE (RFC 1951), zlib (RFC 1950) and gzip (RFC 1952), written entirely in Lyric.
Decoding reads stored, fixed and dynamic blocks through a 32 KiB window; encoding writes them
at the levels 0 to 9 — 0 stored, 1 the fixed tables over a greedy LZ77, 2 and up dynamic
tables, 4 and up with lazy matching, the chains longer with the level. The streams are
DeflateReader<R>/DeflateWriter<W> raw, ZlibReader/ZlibWriter with the zlib header and
Adler-32, GzipReader/GzipWriter with the gzip header and CRC-32 (members in a row read as
one). Gzip, Zlib and Deflate compress and decompress bytes held in memory. Corrupt input
is reported as IoError { kind = .InvalidData } carrying a CompressError.
Examples
import std.io { println, IoError };
import std.compress { Gzip, CompressError };
fn main(): void throws [CompressError, IoError] {
let line = "to be or not to be, that is the question; ";
let text = [line, line, line, line, line, line, line, line].iter().join("");
let packed = try Gzip.compress(text.bytes());
println(packed.length() < text.length());
let back = try Gzip.decompress(packed);
println(back.length() == text.length());
}
true
true
Types
CompressError struct — The error for bytes that are not the format, a checksum or a length that does not hold, or a compression level outside 0 to 9.
DeflateWriter class — A
Writer that compresses the bytes given into raw DEFLATE blocks written to inner; close writes the final block.ZlibReader class — A
Reader that decompresses a zlib stream: the two header bytes, the deflate blocks, the Adler-32 checked at the end.ZlibWriter class — A
Writer that compresses into a zlib stream: the header, the deflate blocks, the Adler-32 at close.GzipReader class — A
Reader that decompresses a gzip file: the header (its extra field, name, comment and header CRC skipped), the deflate blocks, the CRC-32 and the size checked at the end; members in a row read as one.GzipWriter class — A
Writer that compresses into a gzip file: the header, the deflate blocks, the CRC-32 and the size at close.