From bd0e3c7cfa79ee901dbc9913429b0c3ccb1bbe29 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Thu, 13 Jun 2019 07:35:02 +0200 Subject: [PATCH] src/backup/data_chunk.rs: Moved ChunkInfo from merge_known_chunks.rs --- src/backup/data_chunk.rs | 16 ++++++++++++++-- src/client/merge_known_chunks.rs | 6 +----- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/backup/data_chunk.rs b/src/backup/data_chunk.rs index 220ca3fa..2baba71a 100644 --- a/src/backup/data_chunk.rs +++ b/src/backup/data_chunk.rs @@ -4,6 +4,12 @@ use std::io::Write; 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 /// @@ -120,6 +126,12 @@ impl DataChunk { let mut data = Vec::with_capacity(1024*1024); reader.read_to_end(&mut data)?; + Self::from_raw(data, digest) + } + + /// Create Instance from raw data + pub fn from_raw(data: Vec, digest: [u8;32]) -> Result { + if data.len() < 8 { bail!("chunk too small ({} bytes).", data.len()); } @@ -141,7 +153,7 @@ impl DataChunk { Ok(chunk) } 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, digest_computed: false, digest: [0u8; 32], - compress: false, + compress: true, } } diff --git a/src/client/merge_known_chunks.rs b/src/client/merge_known_chunks.rs index 28ea5bf8..c5255bdf 100644 --- a/src/client/merge_known_chunks.rs +++ b/src/client/merge_known_chunks.rs @@ -1,11 +1,7 @@ use failure::*; use futures::*; -pub struct ChunkInfo { - pub digest: [u8; 32], - pub data: bytes::BytesMut, - pub offset: u64, -} +use crate::backup::ChunkInfo; pub enum MergedChunkInfo { Known(Vec<(u64,[u8;32])>),