# zlib-header Rust binary and library to work with the 2 Byte zlib header, as defined in [RFC 1950](https://datatracker.ietf.org/doc/html/rfc1950). This was initially written to reverse-engineer more details about Blizzard's proprietary MPQ archive format, which uses zlib streams to store data. ## Binary ``` Usage: zlib-header-cli [OPTIONS] [HEX4CHAR] Arguments: [HEX4CHAR] A four-character hex string representing the ZlibHeader (Big Endian) Options: -e, --explain Explain the ZlibHeader struct and abbreviations -h, --help Print help ``` ``` drfrugal@karazhan:~$ zlib-header-cli 789C CM 8 (DEFLATE) CINFO 7 (Window: 32768 Bytes) FCHECK 28 (valid) FDICT false (Preset Dictionary not used) FLEVEL 2 (default) ``` ``` drfrugal@karazhan:~$ zlib-header-cli --explain 2 Byte zlib header according to https://datatracker.ietf.org/doc/html/rfc1950 1st Byte - CMF (Compression Method and Flags) 0000_1111 CM Compression Method 8, _ (DEFLATE, UNDEFINED) 1111_0000 CINFO Compression Info window size is 2.pow(CINFO + 8) 2nd Byte - FLG (Flags) 0001_1111 FCHECK Checksum Adjustment valid if (CMF * 256 + FLG) % 31 == 0 0010_0000 FDICT Preset Dictionary a preset dictionary was used 1100_0000 FLEVEL Compression Level 0, 1, 2, 3 (fastest, fast, default, best) ``` ## Library Read the complete documentation [here](https://git.drfrugal.xyz/doc/zlib_header/). ``` use zlib_header::ZlibHeader; let cm = 8; let cinfo = 7; let fdict = false; let flevel = 2; let header = ZlibHeader::new(cm, cinfo, fdict, flevel); match header { Ok(header) => { println!("header is valid (strict): {}", header.is_valid_strict()); // header is valid (strict): true }, Err(err) => eprintln!("Unable to initialize zlib header: {:?}", err) } ``` ``` use zlib_header::ZlibHeader; let header = ZlibHeader::default(); println!("Display: {}", header); // Display: 789C println!("Debug: {:?}", header); // Debug: ZlibHeader { DEFLATE | 32768 Bytes | default | Dictionary: false | valid } let bytes = [0x78, 0x9C]; println!("header matches expected bytes: {}", header == bytes); // header matches expected bytes: true ``` ## Downloads [linux/x86_64/zlib-header-cli](https://git.drfrugal.xyz/bin/linux/x86_64/zlib-header-cli) [windows/x86_64/zlib-header-cli.exe](https://git.drfrugal.xyz/bin/windows/x86_64/zlib-header-cli.exe)