Struct rust_car::unixfs::UnixFs

source ·
pub struct UnixFs { /* private fields */ }

Implementations§

source§

impl UnixFs

source

pub fn new(cid: Cid) -> Self

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
Hide additional 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);
                }
            }
            _ => {}
        }
    }
}
source

pub fn mtime(&self) -> Option<&UnixTime>

source

pub fn mode(&self) -> Option<u32>

source

pub fn fanout(&self) -> Option<u64>

source

pub fn file_name(&self) -> Option<&str>

source

pub fn hash_type(&self) -> Option<u64>

source

pub fn block_sizes(&self) -> Vec<u64>

source

pub fn file_size(&self) -> Option<u64>

source

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);
                }
            }
            _ => {}
        }
    }
}
source

pub fn cid(&self) -> Option<Cid>

Trait Implementations§

source§

impl Clone for UnixFs

source§

fn clone(&self) -> UnixFs

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for UnixFs

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Decoder<UnixFs> for Ipld

source§

impl Default for UnixFs

source§

fn default() -> UnixFs

Returns the “default value” for a type. Read more
source§

impl Encoder<Ipld> for UnixFs

source§

impl PartialEq<UnixFs> for UnixFs

source§

fn eq(&self, other: &UnixFs) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl TryFrom<(Cid<64>, Ipld)> for UnixFs

§

type Error = CarError

The type returned in the event of a conversion error.
source§

fn try_from(value: (Cid, Ipld)) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<Ipld> for UnixFs

§

type Error = CarError

The type returned in the event of a conversion error.
source§

fn try_from(value: Ipld) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<UnixFs> for Ipld

§

type Error = CarError

The type returned in the event of a conversion error.
source§

fn try_from(value: UnixFs) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl Eq for UnixFs

source§

impl StructuralEq for UnixFs

source§

impl StructuralPartialEq for UnixFs

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> References<RawCodec> for T

§

fn references<R, E>(_c: RawCodec, _r: &mut R, _set: &mut E) -> Result<(), Error>where R: Read, E: Extend<Cid<64>>,

Scrape the references from an impl Read. Read more
source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.