Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for favoring decompression speed #21

Merged
merged 1 commit into from Mar 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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