]>
git.proxmox.com Git - proxmox-backup.git/blob - src/backup/read_chunk.rs
4 use super::datastore
::*;
5 use super::crypt_config
::*;
6 use super::data_blob
::*;
8 /// The ReadChunk trait allows reading backup data chunks (local or remote)
10 /// Returns the decoded chunk data
11 fn read_chunk(&mut self, digest
:&[u8; 32]) -> Result
<Vec
<u8>, Error
>;
14 pub struct LocalChunkReader
{
15 store
: Arc
<DataStore
>,
16 crypt_config
: Option
<Arc
<CryptConfig
>>,
19 impl LocalChunkReader
{
21 pub fn new(store
: Arc
<DataStore
>, crypt_config
: Option
<Arc
<CryptConfig
>>) -> Self {
22 Self { store, crypt_config }
26 impl ReadChunk
for LocalChunkReader
{
28 fn read_chunk(&mut self, digest
:&[u8; 32]) -> Result
<Vec
<u8>, Error
> {
30 let digest_str
= proxmox
::tools
::digest_to_hex(digest
);
31 println
!("READ CHUNK {}", digest_str
);
33 let (path
, _
) = self.store
.chunk_path(digest
);
34 let raw_data
= proxmox
::tools
::fs
::file_get_contents(&path
)?
;
35 let chunk
= DataBlob
::from_raw(raw_data
)?
;
38 let raw_data
= chunk
.decode(self.crypt_config
.as_ref().map(Arc
::as_ref
))?
;
40 // fixme: verify digest?