···11+/*!
22+Read a CAR slice in memory and show some info about it.
33+*/
44+55+extern crate repo_stream;
66+use repo_stream::{Driver, DriverBuilder, Output, Step};
77+88+type Result<T> = std::result::Result<T, Box<dyn std::error::Error>>;
99+1010+#[tokio::main]
1111+async fn main() -> Result<()> {
1212+ env_logger::init();
1313+ let reader = tokio::io::BufReader::new(tokio::io::stdin());
1414+1515+ let (commit, prev_rkey, mut driver) = match DriverBuilder::new()
1616+ .with_block_processor(|block| block.len().to_ne_bytes().to_vec())
1717+ .load_car(reader)
1818+ .await?
1919+ {
2020+ Driver::Memory(commit, prev, mem_driver) => (commit, prev, mem_driver),
2121+ Driver::Disk(_) => panic!("this example doesn't handle big CARs"),
2222+ };
2323+2424+ println!(
2525+ "\nthis slice is from {}, repo rev {}",
2626+ commit.did, commit.rev
2727+ );
2828+ if let Some(rkey) = prev_rkey {
2929+ println!(" -> key immediately before CAR slice: {rkey}");
3030+ } else {
3131+ println!(
3232+ " -> no key preceeding the CAR slice, so it includes the leading edge of the tree."
3333+ );
3434+ }
3535+3636+ println!("included records:");
3737+ let end = loop {
3838+ match driver.next_chunk(256).await? {
3939+ Step::Value(chunk) => {
4040+ for Output { cid, rkey, .. } in chunk {
4141+ print!(" SHA256 ");
4242+ for byte in cid.to_bytes().iter().skip(4).take(5) {
4343+ print!("{byte:02x}");
4444+ }
4545+ println!("...\t{rkey}");
4646+ }
4747+ }
4848+ Step::End(e) => break e,
4949+ }
5050+ };
5151+5252+ println!("done walking records present in the slice.");
5353+ if let Some(rkey) = end {
5454+ println!(" -> key immediately after CAR slice: {rkey}");
5555+ } else {
5656+ println!(
5757+ " -> no key proceeding the CAR slice, so it includes the trailing edge of the tree."
5858+ );
5959+ }
6060+6161+ Ok(())
6262+}
-2
src/drive.rs
···282282 /// Step through the record outputs, in rkey order
283283 pub async fn next_chunk(&mut self, n: usize) -> Result<Step<BlockChunk>, DriveError> {
284284 if let Some(missing) = &self.next_missing {
285285- println!("other side???");
286285 // TODO: make the walker finish walking to verify no more present blocks (oops sparse tree)
287286 // HACK: just get the last rkey if it's there -- i think we might actually need to walk for it though
288287 // ...and walk to verify rkey order of the rest of the nodes anyway?
···291290 ThingKind::Record(rkey) => Step::End(Some(rkey.clone())),
292291 });
293292 }
294294- println!("stepping in...");
295293 let mut out = Vec::with_capacity(n);
296294 // let mut err;
297295 for _ in 0..n {