Skip to main content

Bindle

Struct Bindle 

Source
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

Source

pub fn create<P: AsRef<Path>>(path: P) -> Result<Self>

Creates a new archive, overwriting any existing file at the path.

Source

pub fn open<P: AsRef<Path>>(path: P) -> Result<Self>

Opens an existing archive or creates a new one if it doesn’t exist.

Source

pub fn load<P: AsRef<Path>>(path: P) -> Result<Self>

Opens an existing archive. Returns an error if the file doesn’t exist.

Source

pub fn new(path: PathBuf, opts: OpenOptions) -> Result<Self>

Create a new Bindle from a path and file, the path must match the file

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn read_into(&self, name: &str, buffer: &mut [u8]) -> Result<usize>

Reads an entry into a provided buffer, avoiding allocation.

Decompresses if needed and verifies CRC32. Returns the number of bytes read. If the buffer is too small, only reads up to buffer.len() bytes.

§Example
use bindle_file::Bindle;

let archive = Bindle::open("data.bndl")?;
let mut buffer = vec![0u8; 1024];
let bytes_read = archive.read_into("file.txt", &mut buffer)?;
Source

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.

Source

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.

Source

pub fn len(&self) -> usize

Returns the number of entries in the archive.

Source

pub fn is_empty(&self) -> bool

Returns true if the archive contains no entries.

Source

pub fn index(&self) -> &BTreeMap<String, Entry>

Returns a reference to the archive index.

The index maps entry names to their metadata.

Source

pub fn clear(&mut self)

Removes all entries from the index.

Call save() to commit. Data remains in the file until vacuum() is called.

Source

pub fn exists(&self, name: &str) -> bool

Returns true if an entry with the given name exists.

Source

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.

Source

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.

Source

pub fn unpack<P: AsRef<Path>>(&self, dest: P) -> Result<()>

Extracts all entries to a destination directory.

Creates subdirectories as needed to match the stored paths.

Source

pub fn writer<'a>( &'a mut self, name: &str, compress: Compress, ) -> Result<Writer<'a>>

Creates a streaming writer for adding an entry.

The writer must be closed and then save() must be called to commit the entry.

Trait Implementations§

Source§

impl Drop for Bindle

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl Freeze for Bindle

§

impl RefUnwindSafe for Bindle

§

impl Send for Bindle

§

impl Sync for Bindle

§

impl Unpin for Bindle

§

impl UnwindSafe for Bindle

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> 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, 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.