Your browser sucks, JavaScript disabled! Gunnar's console needs JavaScript and WebAssembly. Git over SSH on port 2222 does not.

nordisk/znippy-zoomies

lgz/examples/falsestart.rs

//! Debug aid: the false-start stream of tests/stream.rs at a small chunk.
use std::io::Write;
fn corpus(len: usize, seed: u32) -> Vec<u8> {
    let mut out = Vec::with_capacity(len + 64);
    let mut x: u32 = seed | 1;
    let words: [&[u8]; 4] = [b"usr", b"lib/python3.12", b"site-packages", b"share"];
    while out.len() < len {
        x ^= x << 13;
        x ^= x >> 17;
        x ^= x << 5;
        out.extend_from_slice(words[(x % 4) as usize]);
        out.push(if x >> 29 == 0 { b'\n' } else { b'/' });
        if x & 0x3f00 == 0 {
            out.extend_from_slice(&x.to_le_bytes());
        }
    }
    out.truncate(len);
    out
}
fn gzip(d: &[u8]) -> Vec<u8> {
    let mut e = flate2::write::GzEncoder::new(Vec::new(), flate2::Compression::new(6));
    e.write_all(d).unwrap();
    e.finish().unwrap()
}
fn main() {
    let mut data = Vec::new();
    for k in 0..12u32 {
        data.extend_from_slice(&corpus(1 << 20, 300 + k));
        data.extend_from_slice(&gzip(&corpus(5 << 20, 400 + k)));
    }
    let gz = gzip(&data);
    let mut out = Vec::new();
    let r = lgz::stream::decode(&gz[..], &mut out, 6, 1 << 20);
    eprintln!("{r:?} out {} want {}", out.len(), data.len());
}