pub enum CarHeader {
V1(CarHeaderV1),
V2(),
}
Variants§
Implementations§
source§impl CarHeader
impl CarHeader
pub fn new_v1(roots: Vec<Cid>) -> Self
sourcepub fn roots(&self) -> Vec<Cid>
pub fn roots(&self) -> Vec<Cid>
Examples found in repository?
examples/extract.rs (line 17)
9 10 11 12 13 14 15 16 17 18 19 20 21
fn main() {
let file_name = std::env::args().nth(1);
let path = file_name.as_ref().map(|f| f.into()).unwrap_or_else(|| {
let file = std::path::Path::new("test");
file.join("carv1-basic.car")
});
let file = std::fs::File::open(path).unwrap();
let mut reader = reader::new_v1(file).unwrap();
let roots = reader.header().roots();
for r in roots.iter() {
extract_ipld_to_current_path(&mut reader, *r).unwrap();
}
}
More examples
examples/cat_cid.rs (line 19)
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
fn main() {
// let cid = std::env::args().nth(1).expect("use cid as argument");
let cid = "bafkreiaqv66m5nd6mwgkk7h5lwqnjzj54s4f7knmnrjhb7ylzqfg2vdo54";
let file = std::path::Path::new("test");
let file = file.join("carv1-basic.car");
let file = std::fs::File::open(file).unwrap();
let mut reader = reader::new_v1(file).unwrap();
let roots = reader.header().roots();
let file_cid = Cid::try_from(cid).expect("cid format error");
for r in roots.iter() {
let root_ipld = reader.ipld(r).unwrap();
let root: Result<UnixFs, CarError> = root_ipld.try_into();
let root_dir = root.unwrap();
let count = root_dir
.links()
.iter()
.filter(|u| u.hash() == file_cid)
.count();
if count > 0 {
cat_ipld(&mut reader, file_cid).unwrap();
}
}
}