From 2745151d93fd1cb57dc87bdeae85238e7d4d7ef4 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Mon, 14 Oct 2019 10:44:46 +0200 Subject: [PATCH] src/backup/data_blob.rs: add create_zero_chunk() helper --- src/backup/data_blob.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/backup/data_blob.rs b/src/backup/data_blob.rs index 910461fd..82dab648 100644 --- a/src/backup/data_blob.rs +++ b/src/backup/data_blob.rs @@ -426,3 +426,20 @@ impl <'a, 'b> DataChunkBuilder<'a, 'b> { Ok((chunk, self.digest)) } } + +/// Create a chunk filled with zeroes +pub fn create_zero_chunk( + crypt_config: Option<&CryptConfig>, + chunk_size: usize, + compress: bool, +) -> Result<(DataBlob, [u8; 32]), Error> { + + let mut zero_bytes = Vec::with_capacity(chunk_size); + zero_bytes.resize(chunk_size, 0u8); + let mut chunk_builder = DataChunkBuilder::new(&zero_bytes).compress(compress); + if let Some(ref crypt_config) = crypt_config { + chunk_builder = chunk_builder.crypt_config(crypt_config); + } + + chunk_builder.build() +}