DoxigAlpha

Function parameters

Parameters

#

Deflate is a lossless data compression file format that uses a combination

Types

#
Compress
Deflate is a lossless data compression file format that uses a combination
Decompress
Inflate is the decoding process that consumes a Deflate bitstream and
HuffmanEncoder
Compression without Lempel-Ziv match searching.
Container
Container of the deflate bit stream body.

When decompressing, the output buffer is used as the history window, so

Values

#
max_window_len
When decompressing, the output buffer is used as the history window, so

Source

Implementation

#
pub fn header(container: Container) []const u8 {
    return switch (container) {
        // GZIP 10 byte header (https://datatracker.ietf.org/doc/html/rfc1952#page-5):
        //  - ID1 (IDentification 1), always 0x1f
        //  - ID2 (IDentification 2), always 0x8b
        //  - CM (Compression Method), always 8 = deflate
        //  - FLG (Flags), all set to 0
        //  - 4 bytes, MTIME (Modification time), not used, all set to zero
        //  - XFL (eXtra FLags), all set to zero
        //  - OS (Operating System), 03 = Unix
        .gzip => &[_]u8{ 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03 },
        // ZLIB has a two-byte header (https://datatracker.ietf.org/doc/html/rfc1950#page-4):
        // 1st byte:
        //  - First four bits is the CINFO (compression info), which is 7 for the default deflate window size.
        //  - The next four bits is the CM (compression method), which is 8 for deflate.
        // 2nd byte:
        //  - Two bits is the FLEVEL (compression level). Values are: 0=fastest, 1=fast, 2=default, 3=best.
        //  - The next bit, FDICT, is set if a dictionary is given.
        //  - The final five FCHECK bits form a mod-31 checksum.
        //
        // CINFO = 7, CM = 8, FLEVEL = 0b10, FDICT = 0, FCHECK = 0b11100
        .zlib => &[_]u8{ 0x78, 0b10_0_11100 },
        .raw => &.{},
    };
}