Something went wrong. Try again.
STreaming ARchive format: simpler, stricter, smaller than CARs for a subset of use-cases. forked from microcosm.blue/star
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172use star::{StarItem, StarIterator};use std::env;use std::fs::File;use std::io::BufReader;
fn main() -> Result<(), Box<dyn std::error::Error>> { let args: Vec<String> = env::args().collect(); if args.len() != 2 { eprintln!("Usage: star-debug <file.star>"); std::process::exit(1); }
let file = File::open(&args[1])?; let reader = BufReader::new(file); let iter = StarIterator::new(reader);
let mut nodes = 0; let mut records = 0;
for item in iter.iter_tree() { let item = item?; match item { StarItem::Commit(c) => { println!("Commit:"); println!(" DID: {}", c.did); println!(" Rev: {}", c.rev); println!(" Root: {:?}", c.data); } StarItem::Node(_n) => { // print_node(&n); nodes += 1; } StarItem::Record { .. } => { // println!(" Record: key={}, cid={}", to_hex(&key), cid); records += 1; } } }
println!("Tree contained {nodes} nodes, {records} records.");
Ok(())}
// fn print_node(node: &StarMstNode) {// println!("Node:");// if let Some(l) = node.l {// println!(" Left -> {}", l);// }// for (i, e) in node.e.iter().enumerate() {// print!(" Entry {}: key={}", i, to_hex(&e.k));// if let Some(v) = e.v {// print!(", val={}", v);// } else {// print!(", val=(implicit)");// }// if let Some(t) = e.t {// print!(", right->{}", t);// }// println!();// }// }
// fn to_hex(bytes: &[u8]) -> String {// let mut s = String::with_capacity(bytes.len() * 2);// for b in bytes {// use std::fmt::Write;// write!(&mut s, "{:02x}", b).unwrap();// }// s// }