OXYGENHUB
◆ v0.5.1 oxygenflow / crates / jet / examples / scan.rs
801 B · Rust · last changed jet: the Jetstream crate, starting with images by hash 24 days ago source blame history raw
59078d2b Andy McCall ↶ 1
fn main() {
2
    let p = std::env::args().nth(1).unwrap();
3
    let t = std::time::Instant::now();
4
    let m = jet::images::scan_file(std::path::Path::new(&p), None, |_, _| Ok(())).unwrap();
5
    let zeros: u64 = m.chunks.iter().filter(|c| c.is_zeros()).map(|c| c.1 as u64).sum();
6
    let need = m.needed();
7
    let need_bytes: u64 = need.iter().map(|h| m.chunks.iter().find(|c| c.hash() == *h).unwrap().1 as u64).sum();
8
    let json = serde_json::to_vec(&m).unwrap();
9
    println!(
10
        "hash {}… size {} MiB, {} chunks, zeros {} MiB, distinct non-zero {} ({} MiB), manifest {} KiB, {:.1} s",
11
        &m.hash[..12],
12
        m.size >> 20,
13
        m.chunks.len(),
14
        zeros >> 20,
15
        need.len(),
16
        need_bytes >> 20,
17
        json.len() >> 10,
18
        t.elapsed().as_secs_f64()
19
    );
20
}