]>
git.proxmox.com Git - proxmox-backup.git/blob - src/backup/read_chunk.rs
9662ea8ea904b78525f02054442f3851c67dd26b
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 encoded chunk data
11 fn read_raw_chunk(&mut self, digest
:&[u8; 32]) -> Result
<DataBlob
, Error
>;
13 /// Returns the decoded chunk data
14 fn read_chunk(&mut self, digest
:&[u8; 32]) -> Result
<Vec
<u8>, Error
>;
17 pub struct LocalChunkReader
{
18 store
: Arc
<DataStore
>,
19 crypt_config
: Option
<Arc
<CryptConfig
>>,
22 impl LocalChunkReader
{
24 pub fn new(store
: Arc
<DataStore
>, crypt_config
: Option
<Arc
<CryptConfig
>>) -> Self {
25 Self { store, crypt_config }
29 impl ReadChunk
for LocalChunkReader
{
31 fn read_raw_chunk(&mut self, digest
:&[u8; 32]) -> Result
<DataBlob
, Error
> {
33 let digest_str
= proxmox
::tools
::digest_to_hex(digest
);
34 println
!("READ CHUNK {}", digest_str
);
36 let (path
, _
) = self.store
.chunk_path(digest
);
37 let raw_data
= proxmox
::tools
::fs
::file_get_contents(&path
)?
;
38 let chunk
= DataBlob
::from_raw(raw_data
)?
;
44 fn read_chunk(&mut self, digest
:&[u8; 32]) -> Result
<Vec
<u8>, Error
> {
45 let chunk
= self.read_raw_chunk(digest
)?
;
47 let raw_data
= chunk
.decode(self.crypt_config
.as_ref().map(Arc
::as_ref
))?
;
49 // fixme: verify digest?