read_blocks/
read_blocks.rs1use std::collections::BTreeMap;
2use std::env;
3use std::error::Error;
4use std::fs::File;
5
6use sbf_tools::SbfReader;
7
8fn main() -> Result<(), Box<dyn Error>> {
9 let path = env::args()
10 .nth(1)
11 .ok_or("usage: cargo run --example read_blocks -- <path-to-file.sbf>")?;
12
13 let file = File::open(&path)?;
14 let reader = SbfReader::new(file);
15 let mut counts = BTreeMap::<&'static str, u64>::new();
16
17 for block in reader {
18 let block = block?;
19 *counts.entry(block.name()).or_default() += 1;
20 }
21
22 for (name, count) in counts {
23 println!("{count:>8} {name}");
24 }
25
26 Ok(())
27}