Decompresses data into a new buffer. max_output bounds the result (a compressed bomb fails
instead of exhausting memory). A GZIP stream is a single member; bytes after the stream are
ignored. On failure the output is empty and error says why.
#import "Extensions/Deflate";
DEFLATE compression (RFC 1951) with its zlib (RFC 1950) and gzip (RFC 1952) wrappers. deflate compresses, inflate decompresses, and crc32 and adler32 are the checksums.
#import "Extensions/Deflate";
bytes := cast([] u8) "hello hello hello hello";
packed := deflate(bytes, .GZIP);
unpacked, ok, error := inflate(packed, .GZIP);
assert(ok && cast(string) unpacked == "hello hello hello hello");Results are allocated with context.allocator and owned by the caller. Errors are static strings.
Procedures#
Like inflate, into a buffer the caller sized. Fails with "output is too small" when the
stream expands past output; nothing is written beyond it.
#import "Extensions/Deflate";
packed := deflate(cast([] u8) "abcabcabc");
buffer: [16] u8;
written, ok := inflate_into(packed, buffer);
assert(ok && written == 9);↗Compresses data. level runs from 0 (stored blocks only) to 9 (smallest); 6 is the usual
balance. Out-of-range levels are clamped.
CRC-32 (the checksum of gzip and PNG). To continue over more data, pass the previous result.
Adler-32 (the checksum of zlib). To continue over more data, pass the previous result.
Types#
The framing around the compressed blocks.
- RAW
- bare DEFLATE blocks
- ZLIB
- 2-byte header, Adler-32 trailer (PNG's IDAT stream)
- GZIP
- gzip member: header, CRC-32 and size trailer
Constants#
A gzip member is at least this long: 10 bytes of header and 8 of trailer.
DEFLATE cannot expand a byte past 1032 bytes of output.
inflate refuses to produce more than this many bytes unless told otherwise.