Skip to main content

BrBlob

Struct BrBlob 

Source
pub struct BrBlob {
    pub blob_id: i64,
    pub compression: i64,
    pub size_uncompressed: i64,
    pub size_compressed: i64,
    pub delta_base_id: Option<i64>,
    pub hash: Vec<u8>,
    pub content: Vec<u8>,
}

Fields§

§blob_id: i64§compression: i64§size_uncompressed: i64§size_compressed: i64§delta_base_id: Option<i64>§hash: Vec<u8>§content: Vec<u8>

Implementations§

Source§

impl BrBlob

Source

pub fn hash(content: &[u8]) -> [u8; 32]

Get the BLAKE3 hash of the given content.

Source

pub fn read(self) -> Result<Vec<u8>, BrFsError>

Read (and decompress) the content of a blob in the brdb filesystem.

Examples found in repository?
examples/dump_canonical.rs (line 39)
31fn dump(reader: &impl BrFsReader) -> Result<(), Box<dyn std::error::Error>> {
32    let mut files = Vec::new();
33    collect(&reader.get_fs()?, "", &mut files);
34    files.sort_by(|a, b| a.0.cmp(&b.0));
35
36    let mut out = BTreeMap::new();
37    for (path, content_id) in files {
38        let content = match content_id {
39            Some(id) => reader.find_blob(id)?.read()?,
40            None => Vec::new(),
41        };
42        out.insert(
43            path,
44            serde_json::json!({
45                "blake3": blake3::hash(&content).to_hex().to_string(),
46                "len": content.len(),
47            }),
48        );
49    }
50    println!("{}", serde_json::to_string_pretty(&out)?);
51    Ok(())
52}
More examples
Hide additional examples
examples/write_fixtures.rs (line 429)
412fn hash_archive(path: &PathBuf) -> Result<BTreeMap<String, serde_json::Value>, Box<dyn std::error::Error>> {
413    fn collect(fs: &BrFs, prefix: &str, out: &mut Vec<(String, Option<i64>)>) {
414        match fs {
415            BrFs::Root(children) => for (n, c) in children { collect(c, n, out); },
416            BrFs::Folder(_, children) => for (n, c) in children {
417                collect(c, &format!("{prefix}/{n}"), out);
418            },
419            BrFs::File(f) => out.push((prefix.to_string(), f.content_id)),
420        }
421    }
422    let reader = Brz::open(path)?.into_reader();
423    let reader = &*reader;
424    let mut files = Vec::new();
425    collect(&reader.get_fs()?, "", &mut files);
426    let mut out = BTreeMap::new();
427    for (p, content_id) in files {
428        let content = match content_id {
429            Some(id) => reader.find_blob(id)?.read()?,
430            None => Vec::new(),
431        };
432        out.insert(p, serde_json::json!({
433            "blake3": blake3::hash(&content).to_hex().to_string(),
434            "len": content.len(),
435        }));
436    }
437    Ok(out)
438}

Trait Implementations§

Source§

impl Clone for BrBlob

Source§

fn clone(&self) -> BrBlob

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for BrBlob

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

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.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

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 T
where U: Into<T>,

Source§

type Error = Infallible

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

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

Performs the conversion.
Source§

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

Source§

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

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

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

Performs the conversion.