pub struct Bindle { /* private fields */ }Expand description
A binary archive for collecting files.
Uses memory-mapped I/O for fast reads, supports optional zstd compression, and handles updates via shadowing. Files can be added incrementally without rewriting the entire archive.
§Example
use bindle_file::{Bindle, Compress};
let mut archive = Bindle::open("data.bndl")?;
archive.add("file.txt", b"data", Compress::None)?;
archive.save()?;Implementations§
Source§impl Bindle
impl Bindle
Sourcepub fn create<P: AsRef<Path>>(path: P) -> Result<Self>
pub fn create<P: AsRef<Path>>(path: P) -> Result<Self>
Creates a new archive, overwriting any existing file at the path.
Sourcepub fn open<P: AsRef<Path>>(path: P) -> Result<Self>
pub fn open<P: AsRef<Path>>(path: P) -> Result<Self>
Opens an existing archive or creates a new one if it doesn’t exist.
Sourcepub fn load<P: AsRef<Path>>(path: P) -> Result<Self>
pub fn load<P: AsRef<Path>>(path: P) -> Result<Self>
Opens an existing archive. Returns an error if the file doesn’t exist.
Sourcepub fn new(path: PathBuf, opts: OpenOptions) -> Result<Self>
pub fn new(path: PathBuf, opts: OpenOptions) -> Result<Self>
Create a new Bindle from a path and file, the path must match the file
Sourcepub fn add(&mut self, name: &str, data: &[u8], compress: Compress) -> Result<()>
pub fn add(&mut self, name: &str, data: &[u8], compress: Compress) -> Result<()>
Adds data to the archive with the given name.
If an entry with the same name exists, it will be shadowed. Call save() to commit changes.
Sourcepub fn add_file(
&mut self,
name: &str,
path: impl AsRef<Path>,
compress: Compress,
) -> Result<()>
pub fn add_file( &mut self, name: &str, path: impl AsRef<Path>, compress: Compress, ) -> Result<()>
Adds a file from the filesystem to the archive.
Reads the file at path and stores it with the given name. Call save() to commit changes.
Sourcepub fn save(&mut self) -> Result<()>
pub fn save(&mut self) -> Result<()>
Commits all pending changes by writing the index and footer to disk.
Must be called after add/remove operations to make changes persistent.
Sourcepub fn vacuum(&mut self) -> Result<()>
pub fn vacuum(&mut self) -> Result<()>
Reclaims space by removing shadowed data.
Rebuilds the archive with only live entries, removing old versions of updated files.
Sourcepub fn read<'a>(&'a self, name: &str) -> Option<Cow<'a, [u8]>>
pub fn read<'a>(&'a self, name: &str) -> Option<Cow<'a, [u8]>>
Reads an entry from the archive, decompressing if needed.
Returns None if the entry doesn’t exist or if CRC32 verification fails.
Sourcepub fn read_to<W: Write>(&self, name: &str, w: W) -> Result<u64>
pub fn read_to<W: Write>(&self, name: &str, w: W) -> Result<u64>
Reads an entry and writes it to the given writer.
Returns the number of bytes written. Verifies CRC32 after reading.
Sourcepub fn reader<'a>(&'a self, name: &str) -> Result<Reader<'a>>
pub fn reader<'a>(&'a self, name: &str) -> Result<Reader<'a>>
Returns a streaming reader for an entry.
Automatically decompresses if the entry is compressed. Call Reader::verify_crc32() after reading to verify integrity.
Sourcepub fn index(&self) -> &BTreeMap<String, Entry>
pub fn index(&self) -> &BTreeMap<String, Entry>
Returns a reference to the archive index.
The index maps entry names to their metadata.
Sourcepub fn remove(&mut self, name: &str) -> bool
pub fn remove(&mut self, name: &str) -> bool
Removes an entry from the index.
Returns true if the entry existed. Data remains in the file until vacuum() is called.
Sourcepub fn pack<P: AsRef<Path>>(
&mut self,
src_dir: P,
compress: Compress,
) -> Result<()>
pub fn pack<P: AsRef<Path>>( &mut self, src_dir: P, compress: Compress, ) -> Result<()>
Recursively adds all files from a directory to the archive.
File paths are stored relative to the source directory. Call save() to commit.