Streaming Tree ARchive format

handle empty MSTs

+23 -6
+21 -4
src/examples/car-to-star.rs
··· 49 49 50 50 let repo_commit: RepoCommit = serde_ipld_dagcbor::from_slice(commit_bytes)?; 51 51 52 + let root_bytes = blocks 53 + .get(&repo_commit.data) 54 + .context("repo data cannot be null")?; 55 + let root_node: RepoMstNode = 56 + serde_ipld_dagcbor::from_slice(root_bytes).context("root must be an mst node")?; 57 + 58 + let star_data = if root_node.l.is_none() && root_node.e.is_empty() { 59 + None 60 + } else { 61 + Some(repo_commit.data) 62 + }; 63 + 52 64 let star_commit = StarCommit { 53 65 did: repo_commit.did, 54 66 version: repo_commit.version, 55 - data: Some(repo_commit.data), 67 + data: star_data, 56 68 rev: repo_commit.rev, 57 69 prev: repo_commit.prev, 58 70 sig: repo_commit.sig, ··· 62 74 63 75 serializer.write_header(&star_commit)?; 64 76 println!("wrote header. Root: {}", repo_commit.data); 65 - println!("writing tree..."); 66 - let (nodes, records) = write_tree(repo_commit.data, &blocks, &mut serializer)?; 67 - println!("wrote {nodes} nodes and {records} records."); 77 + 78 + if let Some(root_cid) = star_commit.data { 79 + println!("writing tree..."); 80 + let (nodes, records) = write_tree(root_cid, &blocks, &mut serializer)?; 81 + println!("wrote {nodes} nodes and {records} records."); 82 + } else { 83 + println!("empty MST, no tree written."); 84 + } 68 85 69 86 serializer.finish()?; 70 87 println!("Done!");
+2 -2
src/examples/star-debug.rs
··· 24 24 println!(" Root: {:?}", c.data); 25 25 } 26 26 StarItem::Node(n) => { 27 - // print_node(&n); 27 + print_node(&n); 28 28 } 29 29 StarItem::Record { key, cid, .. } => { 30 - // println!(" Record: key={}, cid={}", to_hex(&key), cid); 30 + println!(" Record: key={}, cid={}", to_hex(&key), cid); 31 31 } 32 32 } 33 33 }
star-samples/empty.star

This is a binary file and will not be displayed.