Skip to content

Commit

Permalink
Merge pull request #21 from AlyoshaVasilieva/decspeed
Browse files Browse the repository at this point in the history
Add support for favoring decompression speed
  • Loading branch information
pmarks committed Mar 6, 2022
2 parents dcb1e5d + 5a91912 commit e46e5e6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lz4-sys/src/lib.rs
Expand Up @@ -89,7 +89,8 @@ pub struct LZ4FPreferences {
pub frame_info: LZ4FFrameInfo,
pub compression_level: c_uint, // 0 == default (fast mode); values above 16 count as 16
pub auto_flush: c_uint, // 1 == always flush : reduce need for tmp buffer
pub reserved: [c_uint; 4],
pub favor_dec_speed: c_uint, // 1 == favor decompression speed over ratio, requires level 10+
pub reserved: [c_uint; 3],
}

#[derive(Debug)]
Expand Down
12 changes: 11 additions & 1 deletion src/encoder.rs
Expand Up @@ -19,6 +19,7 @@ pub struct EncoderBuilder {
level: u32,
// 1 == always flush (reduce need for tmp buffer)
auto_flush: bool,
favor_dec_speed: bool,
}

#[derive(Debug)]
Expand All @@ -37,6 +38,7 @@ impl EncoderBuilder {
checksum: ContentChecksum::ChecksumEnabled,
level: 0,
auto_flush: false,
favor_dec_speed: false,
}
}

Expand Down Expand Up @@ -65,6 +67,13 @@ impl EncoderBuilder {
self
}

/// Favor decompression speed over compression ratio. Requires compression
/// level >=10.
pub fn favor_dec_speed(&mut self, favor_dec_speed: bool) -> &mut Self {
self.favor_dec_speed = favor_dec_speed;
self
}

pub fn build<W: Write>(&self, w: W) -> Result<Encoder<W>> {
let block_size = self.block_size.get_size();
let preferences = LZ4FPreferences {
Expand All @@ -76,7 +85,8 @@ impl EncoderBuilder {
},
compression_level: self.level,
auto_flush: if self.auto_flush { 1 } else { 0 },
reserved: [0; 4],
favor_dec_speed: if self.favor_dec_speed { 1 } else { 0 },
reserved: [0; 3],
};
let mut encoder = Encoder {
w,
Expand Down

0 comments on commit e46e5e6

Please sign in to comment.