Skip to content

Commit

Permalink
Add none compression (#1208)
Browse files Browse the repository at this point in the history
  • Loading branch information
shikhar authored Nov 16, 2021
1 parent bbc0a2e commit 72cef12
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/store/compressors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ pub trait StoreCompressor {
/// The default is Lz4Block, but also depends on the enabled feature flags.
#[derive(Clone, Debug, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum Compressor {
#[serde(rename = "none")]
/// No compression
None,
#[serde(rename = "lz4")]
/// Use the lz4 compressor (block format)
Lz4,
Expand All @@ -33,16 +36,15 @@ impl Default for Compressor {
} else if cfg!(feature = "snappy-compression") {
Compressor::Snappy
} else {
panic!(
"all compressor feature flags like are disabled (e.g. lz4-compression), can't choose default compressor"
);
Compressor::None
}
}
}

impl Compressor {
pub(crate) fn from_id(id: u8) -> Compressor {
match id {
0 => Compressor::None,
1 => Compressor::Lz4,
2 => Compressor::Brotli,
3 => Compressor::Snappy,
Expand All @@ -51,6 +53,7 @@ impl Compressor {
}
pub(crate) fn get_id(&self) -> u8 {
match self {
Self::None => 0,
Self::Lz4 => 1,
Self::Brotli => 2,
Self::Snappy => 3,
Expand All @@ -59,6 +62,11 @@ impl Compressor {
#[inline]
pub(crate) fn compress(&self, uncompressed: &[u8], compressed: &mut Vec<u8>) -> io::Result<()> {
match self {
Self::None => {
compressed.clear();
compressed.extend_from_slice(uncompressed);
Ok(())
}
Self::Lz4 => {
#[cfg(feature = "lz4-compression")]
{
Expand Down Expand Up @@ -99,6 +107,11 @@ impl Compressor {
decompressed: &mut Vec<u8>,
) -> io::Result<()> {
match self {
Self::None => {
decompressed.clear();
decompressed.extend_from_slice(compressed);
Ok(())
}
Self::Lz4 => {
#[cfg(feature = "lz4-compression")]
{
Expand Down
4 changes: 4 additions & 0 deletions src/store/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,10 @@ pub mod tests {
Ok(())
}

#[test]
fn test_store_noop() -> crate::Result<()> {
test_store(Compressor::None)
}
#[cfg(feature = "lz4-compression")]
#[test]
fn test_store_lz4_block() -> crate::Result<()> {
Expand Down

0 comments on commit 72cef12

Please sign in to comment.