This commit is contained in:
nora 2025-08-31 16:28:58 +02:00
commit 00a411a728
5 changed files with 311 additions and 0 deletions

32
src/main.rs Normal file
View file

@ -0,0 +1,32 @@
use std::ffi::CStr;
fn main() {
let gz = std::env::args().nth(1).unwrap();
let gz = std::fs::read(gz).unwrap();
assert_eq!(gz[0], 31, "ID");
assert_eq!(gz[1], 139, "ID");
assert_eq!(gz[2], 8, "compression method");
let flg = gz[3];
assert!(flg == 8 || flg == 0); // only FLG.FNAME
let mut data_start = 10;
if flg & 0b1000 != 0 {
let fname = CStr::from_bytes_until_nul(&gz[10..]).unwrap();
dbg!(fname);
data_start += fname.count_bytes() + 1;
}
let blocks = &gz[(data_start)..];
let blocks = &blocks[..(blocks.len() - 8)]; // crc32 and isize
let mut out = Vec::new();
zwergli::inflate(blocks, &mut out);
dbg!(&out);
dbg!(String::from_utf8(out)).ok();
}