Skip to main content

BrFsReader

Trait BrFsReader 

Source
pub trait BrFsReader {
    // Required methods
    fn find_folder(
        &self,
        parent_id: Option<i64>,
        name: &str,
    ) -> Result<Option<i64>, BrFsError>;
    fn find_file(
        &self,
        parent_id: Option<i64>,
        name: &str,
    ) -> Result<Option<FoundFile>, BrFsError>;
    fn find_file_at_revision(
        &self,
        parent_id: Option<i64>,
        name: &str,
        date: i64,
    ) -> Result<Option<FoundFile>, BrFsError>;
    fn find_blob(&self, content_id: i64) -> Result<BrBlob, BrFsError>;
    fn get_fs(&self) -> Result<BrFs, BrFsError>;

    // Provided methods
    fn find_file_by_path(
        &self,
        path: impl Display,
    ) -> Result<Option<FoundFile>, BrFsError> { ... }
    fn find_file_by_path_at_revision(
        &self,
        path: impl Display,
        date: i64,
    ) -> Result<Option<FoundFile>, BrFsError> { ... }
    fn read_file(&self, path: impl Display) -> Result<Vec<u8>, BrFsError> { ... }
}

Required Methods§

Source

fn find_folder( &self, parent_id: Option<i64>, name: &str, ) -> Result<Option<i64>, BrFsError>

Find a file by its name and parent folder id in the brdb filesystem, returning its folder_id

Source

fn find_file( &self, parent_id: Option<i64>, name: &str, ) -> Result<Option<FoundFile>, BrFsError>

Find a file by its name and parent in the brdb filesystem, returns the FoundFile if found.

Source

fn find_file_at_revision( &self, parent_id: Option<i64>, name: &str, date: i64, ) -> Result<Option<FoundFile>, BrFsError>

Find a file by its name and parent in the brdb filesystem at a specific revision, returns the FoundFile if found.

Source

fn find_blob(&self, content_id: i64) -> Result<BrBlob, BrFsError>

Read the metadata for a file in the brdb filesystem.

Source

fn get_fs(&self) -> Result<BrFs, BrFsError>

Get the filesystem representation of the BRDB database.

Provided Methods§

Source

fn find_file_by_path( &self, path: impl Display, ) -> Result<Option<FoundFile>, BrFsError>

Find a file by its path in the brdb filesystem, returning FoundFile if found.

Source

fn find_file_by_path_at_revision( &self, path: impl Display, date: i64, ) -> Result<Option<FoundFile>, BrFsError>

Find a file by its path in the brdb filesystem as it existed at a specific revision date, returning FoundFile if found. Unlike find_file_by_path, the final path component is resolved to the version that was live at date rather than the latest version. This matters for schema files, which are re-written when the save format changes: an old chunk must be decoded with the schema that was live when the chunk was written, not the latest schema.

Parent folders are resolved against the current tree (folders are stable across revisions); only the leaf file is resolved at the revision.

Source

fn read_file(&self, path: impl Display) -> Result<Vec<u8>, BrFsError>

Find and read a file from the brdb filesystem, returning its decompressed content as a byte vector.

Examples found in repository?
examples/world_replace_bundle.rs (line 15)
6fn main() -> Result<(), Box<dyn std::error::Error>> {
7    let meta_dst = PathBuf::from("dst.brdb");
8    let meta_src = PathBuf::from("src.brdb");
9
10    let src_f = Brdb::open(meta_src)?.into_reader();
11    let dst_f = Brdb::open(meta_dst)?.into_reader();
12
13    println!(
14        "replacing: {}",
15        String::from_utf8(dst_f.read_file("Meta/Bundle.json")?).unwrap()
16    );
17    println!(
18        "with: {}",
19        String::from_utf8(src_f.read_file("Meta/Bundle.json")?).unwrap()
20    );
21
22    let patch = BrPendingFs::Root(vec![(
23        "Meta".to_owned(),
24        BrPendingFs::Folder(Some(vec![(
25            "Bundle.json".to_string(),
26            BrPendingFs::File(Some(src_f.read_file("Meta/Bundle.json")?)),
27        )])),
28    )]);
29
30    dst_f.write_pending(
31        "Replace Bundle",
32        dst_f.to_pending_patch()?.with_patch(patch)?,
33    )?;
34
35    Ok(())
36}

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl BrFsReader for ()

Source§

fn find_folder( &self, _parent_id: Option<i64>, _name: &str, ) -> Result<Option<i64>, BrFsError>

Source§

fn find_file( &self, _parent_id: Option<i64>, _name: &str, ) -> Result<Option<FoundFile>, BrFsError>

Source§

fn find_file_at_revision( &self, _parent_id: Option<i64>, _name: &str, _date: i64, ) -> Result<Option<FoundFile>, BrFsError>

Source§

fn find_blob(&self, _content_id: i64) -> Result<BrBlob, BrFsError>

Source§

fn get_fs(&self) -> Result<BrFs, BrFsError>

Source§

impl<T: BrFsReader> BrFsReader for &T

Source§

fn find_folder( &self, parent_id: Option<i64>, name: &str, ) -> Result<Option<i64>, BrFsError>

Source§

fn find_file( &self, parent_id: Option<i64>, name: &str, ) -> Result<Option<FoundFile>, BrFsError>

Source§

fn find_file_at_revision( &self, parent_id: Option<i64>, name: &str, date: i64, ) -> Result<Option<FoundFile>, BrFsError>

Source§

fn find_blob(&self, content_id: i64) -> Result<BrBlob, BrFsError>

Source§

fn get_fs(&self) -> Result<BrFs, BrFsError>

Implementors§