pub struct ContentAddressedArchive {
pub config: ArchiveConfig,
pub index: ArchiveIndex,
pub data: Vec<u8>,
}Expand description
An append-only, content-addressed archive for storing immutable data blobs.
Data is kept in a flat in-memory byte array (data). Each entry records
the offset and length of its blob so that slices can be returned without
copying. Removed entries are tombstoned in their metadata; their bytes
remain in the flat array but are excluded from all live-entry computations.
Fields§
§config: ArchiveConfigArchive capacity and behaviour settings.
index: ArchiveIndexCID → entry index.
data: Vec<u8>Flat byte array holding all blob data (including tombstoned blobs).
Implementations§
Source§impl ContentAddressedArchive
impl ContentAddressedArchive
Sourcepub fn new(config: ArchiveConfig) -> Self
pub fn new(config: ArchiveConfig) -> Self
Create a new, empty archive with the given configuration.
Sourcepub fn is_full(&self) -> bool
pub fn is_full(&self) -> bool
Returns true when the archive has reached either of its capacity limits.
Sourcepub fn put(
&mut self,
data: Vec<u8>,
metadata: HashMap<String, String>,
now: u64,
) -> Result<String, ArchiveError>
pub fn put( &mut self, data: Vec<u8>, metadata: HashMap<String, String>, now: u64, ) -> Result<String, ArchiveError>
Insert a blob into the archive.
Computes the CID from data, checks for duplicates, enforces capacity
limits, appends the bytes to the flat array, and records the entry.
Returns the computed CID on success.
Sourcepub fn get(&self, cid: &str) -> Result<&[u8], ArchiveError>
pub fn get(&self, cid: &str) -> Result<&[u8], ArchiveError>
Retrieve the raw bytes of the blob identified by cid.
Sourcepub fn get_entry(&self, cid: &str) -> Result<&ArchiveEntry, ArchiveError>
pub fn get_entry(&self, cid: &str) -> Result<&ArchiveEntry, ArchiveError>
Retrieve the metadata entry for the blob identified by cid.
Sourcepub fn remove(&mut self, cid: &str) -> Result<Vec<u8>, ArchiveError>
pub fn remove(&mut self, cid: &str) -> Result<Vec<u8>, ArchiveError>
Logically remove the entry for cid, returning the original blob bytes.
The entry is kept in the index with "_tombstone" = "true" in its
metadata; the raw bytes remain in the flat data array.
Sourcepub fn list_cids(&self) -> Vec<&str>
pub fn list_cids(&self) -> Vec<&str>
Return the sorted list of all live CID strings (alphabetical order).
Sourcepub fn list_entries(&self) -> Vec<&ArchiveEntry>
pub fn list_entries(&self) -> Vec<&ArchiveEntry>
Return live entries sorted by CID.
Sourcepub fn total_data_bytes(&self) -> u64
pub fn total_data_bytes(&self) -> u64
Total bytes occupied by live entries.
Sourcepub fn entry_count(&self) -> usize
pub fn entry_count(&self) -> usize
Number of live entries.
Sourcepub fn verify_integrity(&self) -> Vec<String>
pub fn verify_integrity(&self) -> Vec<String>
Verify every live entry by recomputing its CID from stored bytes.
Returns the CIDs of entries where the recomputed CID differs from the recorded CID (indicating data corruption).
Sourcepub fn export_entries(&self) -> Vec<ArchiveBlock>
pub fn export_entries(&self) -> Vec<ArchiveBlock>
Export all live entries as ArchiveBlock values.
Sourcepub fn merge(
&mut self,
other: &ContentAddressedArchive,
now: u64,
) -> Result<usize, ArchiveError>
pub fn merge( &mut self, other: &ContentAddressedArchive, now: u64, ) -> Result<usize, ArchiveError>
Import all live entries from other that are not already present in
self. Returns the number of entries added.
Entries that already exist (even as tombstones) in self are skipped.
Sourcepub fn stats(&self) -> ArchiveStats
pub fn stats(&self) -> ArchiveStats
Compute aggregate statistics for the archive.
Trait Implementations§
Source§impl Clone for ContentAddressedArchive
impl Clone for ContentAddressedArchive
Source§fn clone(&self) -> ContentAddressedArchive
fn clone(&self) -> ContentAddressedArchive
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for ContentAddressedArchive
impl RefUnwindSafe for ContentAddressedArchive
impl Send for ContentAddressedArchive
impl Sync for ContentAddressedArchive
impl Unpin for ContentAddressedArchive
impl UnsafeUnpin for ContentAddressedArchive
impl UnwindSafe for ContentAddressedArchive
Blanket Implementations§
impl<T> Allocation for T
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more