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
impl BrBlob
Sourcepub fn read(self) -> Result<Vec<u8>, BrFsError>
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
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§
Auto Trait Implementations§
impl Freeze for BrBlob
impl RefUnwindSafe for BrBlob
impl Send for BrBlob
impl Sync for BrBlob
impl Unpin for BrBlob
impl UnsafeUnpin for BrBlob
impl UnwindSafe for BrBlob
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more