diff options
author | Alex Auvolat <alex@adnab.me> | 2024-02-23 11:47:44 +0100 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2024-02-23 11:54:40 +0100 |
commit | 07c78959480327af3709dc0e7b6c8f798cef9c92 (patch) | |
tree | fc7b53b2529449203e8953441cc14bf2c6cba5e2 /src/block/block.rs | |
parent | 9b41f4ff2016b099ee706747828f5828f8c96b1c (diff) | |
download | garage-07c78959480327af3709dc0e7b6c8f798cef9c92.tar.gz garage-07c78959480327af3709dc0e7b6c8f798cef9c92.zip |
[refactor-block] simplify rpc_get_block
Diffstat (limited to 'src/block/block.rs')
-rw-r--r-- | src/block/block.rs | 23 |
1 files changed, 2 insertions, 21 deletions
diff --git a/src/block/block.rs b/src/block/block.rs index 20f57aa5..34afea5d 100644 --- a/src/block/block.rs +++ b/src/block/block.rs @@ -2,7 +2,7 @@ use std::path::PathBuf; use bytes::Bytes; use serde::{Deserialize, Serialize}; -use zstd::stream::{decode_all as zstd_decode, Encoder}; +use zstd::stream::Encoder; use garage_util::data::*; use garage_util::error::*; @@ -43,26 +43,7 @@ impl DataBlock { res } - /// Get the buffer, possibly decompressing it, and verify it's integrity. - /// For Plain block, data is compared to hash, for Compressed block, zstd checksumming system - /// is used instead. - pub fn verify_get(self, hash: Hash) -> Result<Bytes, Error> { - match self { - DataBlock::Plain(data) => { - if blake2sum(&data) == hash { - Ok(data) - } else { - Err(Error::CorruptData(hash)) - } - } - DataBlock::Compressed(data) => zstd_decode(&data[..]) - .map_err(|_| Error::CorruptData(hash)) - .map(Bytes::from), - } - } - - /// Verify data integrity. Allocate less than [`DataBlock::verify_get`] and don't consume self, but - /// does not return the buffer content. + /// Verify data integrity. Does not return the buffer content. pub fn verify(&self, hash: Hash) -> Result<(), Error> { match self { DataBlock::Plain(data) => { |