···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};
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, 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, _, mem_driver) => (commit, mem_driver),
2121+ Driver::Disk(_) => panic!("this example doesn't handle big CARs"),
2222+ };
2323+2424+ println!(
2525+ "\nthis slice is from {}, repo rev {}\n\n",
2626+ commit.did, commit.rev
2727+ );
2828+2929+ driver.viz(commit.data)?;
3030+3131+ Ok(())
3232+}
+18-2
src/drive.rs
···242242 };
243243 let mut walker = Walker::new(root_node);
244244245245+ // eprintln!("going to edge...");
245246 let edge = walker.step_to_edge(&mem_blocks)?;
247247+ // eprintln!("got edge? {edge:?}");
246248247249 Ok(Driver::Memory(
248250 commit,
···274276pub struct MemDriver {
275277 blocks: HashMap<ObjectLink, MaybeProcessedBlock>,
276278 walker: Walker,
277277- process: fn(Bytes) -> Bytes,
279279+ process: fn(Bytes) -> Bytes, // TODO: impl Fn(bytes) -> Bytes?
278280 next_missing: Option<NodeThing>,
279281}
280282281283impl MemDriver {
284284+ pub fn viz(&self, tree: ObjectLink) -> Result<(), WalkError> {
285285+ self.walker.viz(&self.blocks, tree)
286286+ }
282287 /// Step through the record outputs, in rkey order
283288 pub async fn next_chunk(&mut self, n: usize) -> Result<Step<BlockChunk>, DriveError> {
284284- if let Some(missing) = &self.next_missing {
289289+ if let Some(ref mut missing) = self.next_missing {
290290+ while let Step::Value(sparse_out) =
291291+ self.walker.step_sparse(&self.blocks, self.process)?
292292+ {
293293+ if missing.kind == ThingKind::ChildNode {
294294+ *missing = NodeThing {
295295+ link: sparse_out.cid.into(),
296296+ kind: ThingKind::Record(sparse_out.rkey),
297297+ };
298298+ }
299299+ }
300300+ // TODO: l asdflkja slfkja lkdfj lakjd f
285301 // TODO: make the walker finish walking to verify no more present blocks (oops sparse tree)
286302 // HACK: just get the last rkey if it's there -- i think we might actually need to walk for it though
287303 // ...and walk to verify rkey order of the rest of the nodes anyway?