diff --git a/source/marathon/defl.rs b/source/marathon/defl.rs index ddc8d8c..d2c3f68 100644 --- a/source/marathon/defl.rs +++ b/source/marathon/defl.rs @@ -2,6 +2,34 @@ use crate::durandal::err::*; +/// Loads a ZLIB file header. +pub fn load_zlib_header(b: &[u8]) -> ResultS +{ + const CM: u8 = 0b00001111; + const CINFO: u8 = 0b11110000; + const FDICT: u8 = 0b00100000; + + read_data! { + 2, BE in b => + fcheck = u16[0]; + cmf = u8[0]; + flg = u8[1]; + } + + let cm = cmf & CM; + let cinfo = cmf & CINFO >> 4; + + if cm != 8 || fcheck % 31 != 0 || cinfo > 7 { + bail!("not zlib format"); + } + + if flg & FDICT != 0 { + bail!("dictionary not supported"); + } + + Ok(2) +} + /// Loads a GZIP file header. pub fn load_gzip_header(b: &[u8]) -> ResultS {