about summary refs log blame commit diff
path: root/tvix/store/src/chunkservice/mod.rs
blob: faf0a88f151a0d91bfa101018474d8f6b1efd1a1 (plain) (tree)
1
2
3
4
5
6
7
8
9

         






                                         
                                       
                                  
                                 






                                                                              
                                                            


                                                                                
                                                                       

                                                                     
                                                            
 
mod util;

pub mod memory;
pub mod sled;

use crate::Error;

pub use self::memory::MemoryChunkService;
pub use self::sled::SledChunkService;
pub use self::util::read_all_and_chunk;
pub use self::util::update_hasher;
pub use self::util::upload_chunk;

/// The base trait all ChunkService services need to implement.
/// It allows checking for the existence, download and upload of chunks.
/// It's usually used after consulting a [crate::blobservice::BlobService] for
/// chunking information.
pub trait ChunkService {
    /// check if the service has a chunk, given by its digest.
    fn has(&self, digest: &[u8; 32]) -> Result<bool, Error>;

    /// retrieve a chunk by its digest. Implementations MUST validate the digest
    /// matches.
    fn get(&self, digest: &[u8; 32]) -> Result<Option<Vec<u8>>, Error>;

    /// insert a chunk. returns the digest of the chunk, or an error.
    fn put(&self, data: Vec<u8>) -> Result<[u8; 32], Error>;
}