Struct Store
pub struct Store { /* private fields */ }Expand description
A content-addressed object store rooted at a .cadvm/objects directory.
Implementations§
§impl Store
impl Store
pub fn open(objects_root: impl Into<PathBuf>) -> Result<Store, StoreError>
pub fn open(objects_root: impl Into<PathBuf>) -> Result<Store, StoreError>
Open a store rooted at the given objects directory. The directory and
its category sub-directories are created if missing.
pub fn has(&self, category: Category, id: &ObjectId) -> bool
pub fn has(&self, category: Category, id: &ObjectId) -> bool
Whether an object with this id already exists in the given category.
pub fn has_object(&self, id: &ObjectId) -> bool
pub fn has_object(&self, id: &ObjectId) -> bool
Convenience: does this blob exist?
pub fn put(
&self,
category: Category,
bytes: &[u8],
) -> Result<ObjectId, StoreError>
pub fn put( &self, category: Category, bytes: &[u8], ) -> Result<ObjectId, StoreError>
Store raw bytes in the given category and return their content id.
Writing is atomic and idempotent: if the object already exists the write is skipped entirely.
pub fn put_bytes(&self, bytes: &[u8]) -> Result<ObjectId, StoreError>
pub fn put_bytes(&self, bytes: &[u8]) -> Result<ObjectId, StoreError>
Store a raw blob and return its id (level-1 dedup).
pub fn get(
&self,
category: Category,
id: &ObjectId,
) -> Result<Vec<u8>, StoreError>
pub fn get( &self, category: Category, id: &ObjectId, ) -> Result<Vec<u8>, StoreError>
Read the raw bytes of a stored object.
pub fn put_json<T>(
&self,
category: Category,
value: &T,
) -> Result<ObjectId, StoreError>where
T: Serialize,
pub fn put_json<T>(
&self,
category: Category,
value: &T,
) -> Result<ObjectId, StoreError>where
T: Serialize,
Store a JSON-serializable object content-addressed and return its id.
pub fn get_json<T>(
&self,
category: Category,
id: &ObjectId,
) -> Result<T, StoreError>where
T: for<'de> Deserialize<'de>,
pub fn get_json<T>(
&self,
category: Category,
id: &ObjectId,
) -> Result<T, StoreError>where
T: for<'de> Deserialize<'de>,
Read and deserialize a JSON object.
pub fn put_file_content(&self, content: &[u8]) -> Result<BlobRef, StoreError>
pub fn put_file_content(&self, content: &[u8]) -> Result<BlobRef, StoreError>
Write a file’s content into the store, producing a BlobRef.
The file is split into fixed 256 KiB chunks, each stored content-addressed
so identical chunks across files/versions are shared. raw_hash is the
BLAKE3 hash of the whole file and serves purely as a content identity
(used for dedup keys and status comparisons) — the full file is not
stored as a standalone blob, so there is no on-disk duplication between a
raw blob and its chunks.
pub fn read_file_content(
&self,
blob_ref: &BlobRef,
) -> Result<Vec<u8>, StoreError>
pub fn read_file_content( &self, blob_ref: &BlobRef, ) -> Result<Vec<u8>, StoreError>
Reconstruct a file’s content from a BlobRef by concatenating its
chunks.
pub fn read_file_content_from_chunks(
&self,
blob_ref: &BlobRef,
) -> Result<Vec<u8>, StoreError>
pub fn read_file_content_from_chunks( &self, blob_ref: &BlobRef, ) -> Result<Vec<u8>, StoreError>
Reconstruct a file’s content from its chunks. Equivalent to
read_file_content; kept as an explicit name
for tests that exercise the chunk path directly.