src/backup/data_chunk.rs: Moved ChunkInfo from merge_known_chunks.rs

This commit is contained in:
Dietmar Maurer 2019-06-13 07:35:02 +02:00
parent 6762db70d6
commit bd0e3c7cfa
2 changed files with 15 additions and 7 deletions

View File

@ -4,6 +4,12 @@ use std::io::Write;
use super::*; use super::*;
/// Data chunk with positional information
pub struct ChunkInfo {
pub chunk: DataChunk,
pub chunk_len: u64,
pub offset: u64,
}
/// Data chunk binary storage format /// Data chunk binary storage format
/// ///
@ -120,6 +126,12 @@ impl DataChunk {
let mut data = Vec::with_capacity(1024*1024); let mut data = Vec::with_capacity(1024*1024);
reader.read_to_end(&mut data)?; reader.read_to_end(&mut data)?;
Self::from_raw(data, digest)
}
/// Create Instance from raw data
pub fn from_raw(data: Vec<u8>, digest: [u8;32]) -> Result<Self, Error> {
if data.len() < 8 { if data.len() < 8 {
bail!("chunk too small ({} bytes).", data.len()); bail!("chunk too small ({} bytes).", data.len());
} }
@ -141,7 +153,7 @@ impl DataChunk {
Ok(chunk) Ok(chunk)
} else { } else {
bail!("unable to load chunk - wrong magic"); bail!("unable to parse raw chunk - wrong magic");
} }
} }
} }
@ -168,7 +180,7 @@ impl <'a, 'b> DataChunkBuilder<'a, 'b> {
config: None, config: None,
digest_computed: false, digest_computed: false,
digest: [0u8; 32], digest: [0u8; 32],
compress: false, compress: true,
} }
} }

View File

@ -1,11 +1,7 @@
use failure::*; use failure::*;
use futures::*; use futures::*;
pub struct ChunkInfo { use crate::backup::ChunkInfo;
pub digest: [u8; 32],
pub data: bytes::BytesMut,
pub offset: u64,
}
pub enum MergedChunkInfo { pub enum MergedChunkInfo {
Known(Vec<(u64,[u8;32])>), Known(Vec<(u64,[u8;32])>),