Struct chunk_store::ChunkStore
[−]
[src]
pub struct ChunkStore<Key, Value> { /* fields omitted */ }
ChunkStore
is a store of data held as serialised files on disk, implementing a maximum disk
usage to restrict storage.
The data chunks are deleted when the ChunkStore
goes out of scope.
Methods
impl<Key, Value> ChunkStore<Key, Value> where
Key: Decodable + Encodable,
Value: Decodable + Encodable,
[src]
Key: Decodable + Encodable,
Value: Decodable + Encodable,
fn new_in<P: AsRef<Path>>(
root: P,
prefix: &str,
max_space: u64
) -> Result<ChunkStore<Key, Value>, Error>
root: P,
prefix: &str,
max_space: u64
) -> Result<ChunkStore<Key, Value>, Error>
Creates new ChunkStore with max_space
allowed storage space.
The data is stored in a temporary directory that contains prefix
in its name and is placed
in the root
directory. If root
doesn't exist, it will be created.
fn new(prefix: &str, max_space: u64) -> Result<ChunkStore<Key, Value>, Error>
Creates new ChunkStore with max_space
allowed storage space.
The data is stored in a temporary directory that contains prefix
in its name and is placed
in the system temp directory.
fn put(&mut self, key: &Key, value: &Value) -> Result<(), Error>
Stores a new data chunk under key
.
If there is not enough storage space available, returns Error::NotEnoughSpace
. In case of
If the key already exists, it will be overwritten.
fn delete(&mut self, key: &Key) -> Result<(), Error>
Deletes the data chunk stored under key
.
If the data doesn't exist, it does nothing and returns Ok
. In the case of an IO error, it
returns Error::Io
.
fn get(&self, key: &Key) -> Result<Value, Error>
Returns a data chunk previously stored under key
.
If the data file can't be accessed, it returns Error::ChunkNotFound
.
fn has(&self, key: &Key) -> bool
Tests if a data chunk has been previously stored under key
.
fn keys(&self) -> Vec<Key>
Lists all keys of currently-data stored.
fn max_space(&self) -> u64
Returns the maximum amount of storage space available for this ChunkStore.
fn used_space(&self) -> u64
Returns the amount of storage space already used by this ChunkStore.