rsbag/examples/bag_info.rs

43 lines
1018 B
Rust

use std::env::args;
use log::info;
use rsbag::{Bag, Result};
fn main() -> Result<()> {
color_eyre::install()?;
env_logger::init();
let args: Vec<_> = args().collect();
if args.len() != 2 {
eprintln!("Usage: {} <bag path>", args[0]);
return Ok(());
}
let bag_path = &args[1];
let mut bag = Bag::open(bag_path)?;
let chunk_positions = bag
.index()
.chunks
.iter()
.map(|chunk| chunk.pos)
.collect::<Vec<_>>();
let chunk_sizes = chunk_positions
.windows(2)
.map(|window| {
if let &[last, next] = window {
next - last
} else {
unreachable!();
}
})
.collect::<Vec<_>>();
let mean_chunk_size =
chunk_sizes.iter().map(|s| *s as f64).sum::<f64>() / (chunk_sizes.len() as f64);
info!("average chunk size: {}", mean_chunk_size);
let info = bag.compute_info()?;
info!("bag info: {:#?}", info);
Ok(())
}