pub struct Cas { /* private fields */ }Implementations§
Source§impl Cas
impl Cas
Sourcepub fn put_for(
&mut self,
bytes: &[u8],
origin: &BlockOrigin,
) -> Result<B3Hash, StorageError>
pub fn put_for( &mut self, bytes: &[u8], origin: &BlockOrigin, ) -> Result<B3Hash, StorageError>
Puts the bytes and records the origin they were put for. Ok
means both the object and the record are durable; a second put
with the same origin adds nothing.
§Errors
StorageError::Io naming the path the store would not take.
Sourcepub fn origins(&self, hash: &B3Hash) -> Result<Vec<BlockOrigin>, StorageError>
pub fn origins(&self, hash: &B3Hash) -> Result<Vec<BlockOrigin>, StorageError>
Every origin recorded for a block, oldest first; empty for a block put with no origin and for a hash the store never saw.
§Errors
StorageError::Io when a record exists and cannot be read.
Source§impl Cas
impl Cas
Sourcepub fn open(dir: &Path) -> Result<Cas, StorageError>
pub fn open(dir: &Path) -> Result<Cas, StorageError>
Production entrance: std filesystem underneath.
Sourcepub fn put(&mut self, bytes: &[u8]) -> Result<B3Hash, StorageError>
pub fn put(&mut self, bytes: &[u8]) -> Result<B3Hash, StorageError>
Content-addressed put: hash, dedup by existence, tmp + sync +
rename + dir sync. Ok means the named object is durable.
Sourcepub fn get(&self, hash: &B3Hash) -> Result<Vec<u8>, StorageError>
pub fn get(&self, hash: &B3Hash) -> Result<Vec<u8>, StorageError>
Full read, re-verified against the address.
Sourcepub fn get_range(
&self,
hash: &B3Hash,
range: &Range,
) -> Result<Vec<u8>, StorageError>
pub fn get_range( &self, hash: &B3Hash, range: &Range, ) -> Result<Vec<u8>, StorageError>
Range retrieval per the Locator grammar; out of bounds refuses.
The answer is read where it sits, so a fragment of a two hundred
megabyte object costs the fragment. The price of that is stated
in [ranges]: a range read cannot re-verify an address that
covers the whole object, so it trusts what put verified, and a
caller that needs the address proved calls Cas::get.
Sourcepub fn size(&self, hash: &B3Hash) -> Result<u64, StorageError>
pub fn size(&self, hash: &B3Hash) -> Result<u64, StorageError>
The object’s length in bytes, read from the filesystem rather than
from the object, so asking how long a two hundred megabyte version
is costs nothing like two hundred megabytes. A window of a stored
document version needs it to keep its request inside the object
(crates/storage/spec/Cas.lean §8-36). Like a range read, it trusts what put
verified.