pub struct UnixFs {
pub cid: Option<Cid>,
pub mode: Option<u32>,
pub file_type: FileType,
pub fanout: Option<u64>,
pub block_sizes: Vec<u64>,
pub file_size: Option<u64>,
pub hash_type: Option<u64>,
pub links: Vec<Link>,
pub mtime: Option<UnixTime>,
pub file_name: Option<String>,
}Fields§
§cid: Option<Cid>§mode: Option<u32>§file_type: FileType§fanout: Option<u64>§block_sizes: Vec<u64>§file_size: Option<u64>§hash_type: Option<u64>§links: Vec<Link>§mtime: Option<UnixTime>§file_name: Option<String>Implementations§
source§impl UnixFs
impl UnixFs
pub fn new(cid: Cid) -> Self
pub fn new_directory() -> Self
pub fn add_link(&mut self, child: Link) -> usize
sourcepub fn links(&self) -> Vec<&Link>
pub fn links(&self) -> Vec<&Link>
Examples found in repository?
examples/cat_cid.rs (line 26)
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();
}
}
}More examples
examples/ls.rs (line 28)
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
fn walk(vecq: &mut VecDeque<Cid>, reader: &mut impl CarReader) {
let mut cache: HashMap<Cid, String> = HashMap::new();
let raw_code: u64 = RawCodec.into();
while let Some(file_cid) = vecq.pop_front() {
let codec = file_cid.codec();
let file_n = cache.get(&file_cid).map_or(file_cid.to_string(), |c| c.to_string());
println!("{file_n}");
if codec == raw_code {
continue;
}
let file_ipld: Ipld = reader.ipld(&file_cid).unwrap();
match file_ipld {
m @ Ipld::Map(_) => {
let unixfs: UnixFs = m.try_into().unwrap();
match unixfs.file_type() {
FileType::Directory => {},
_=> continue,
}
for n in unixfs.links().into_iter() {
let cid = n.hash();
cache.insert(cid, file_n.clone() + "/" + n.name_ref());
vecq.push_back(cid);
}
}
_ => {}
}
}
}pub fn mtime(&self) -> Option<&UnixTime>
pub fn mode(&self) -> Option<u32>
pub fn fanout(&self) -> Option<u64>
pub fn file_name(&self) -> Option<&str>
pub fn hash_type(&self) -> Option<u64>
pub fn block_sizes(&self) -> Vec<u64>
pub fn file_size(&self) -> Option<u64>
sourcepub fn file_type(&self) -> FileType
pub fn file_type(&self) -> FileType
Examples found in repository?
examples/ls.rs (line 24)
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
fn walk(vecq: &mut VecDeque<Cid>, reader: &mut impl CarReader) {
let mut cache: HashMap<Cid, String> = HashMap::new();
let raw_code: u64 = RawCodec.into();
while let Some(file_cid) = vecq.pop_front() {
let codec = file_cid.codec();
let file_n = cache.get(&file_cid).map_or(file_cid.to_string(), |c| c.to_string());
println!("{file_n}");
if codec == raw_code {
continue;
}
let file_ipld: Ipld = reader.ipld(&file_cid).unwrap();
match file_ipld {
m @ Ipld::Map(_) => {
let unixfs: UnixFs = m.try_into().unwrap();
match unixfs.file_type() {
FileType::Directory => {},
_=> continue,
}
for n in unixfs.links().into_iter() {
let cid = n.hash();
cache.insert(cid, file_n.clone() + "/" + n.name_ref());
vecq.push_back(cid);
}
}
_ => {}
}
}
}