sile / libflate

A Rust implementation of DEFLATE algorithm and related formats (ZLIB, GZIP)
https://docs.rs/libflate
MIT License
178 stars 35 forks source link

Compression level #55

Closed Smotrov closed 4 years ago

Smotrov commented 4 years ago

Hi all! Would appreciate it if someone will point me to an example showing how to set a certain compression level when I compress some data using libflate. Thank you in advance!

sile commented 4 years ago

Hi @Smotrov, thank you for reaching out.

In terms of API, you can specify a Lz77Encode instance to control the compression level via the EncodeOptions::with_lz77 method as follows:

// From: https://docs.rs/libflate/1.0.2/libflate/deflate/struct.EncodeOptions.html#example
use libflate::lz77::DefaultLz77Encoder;
use libflate::deflate::{Encoder, EncodeOptions};

let options = EncodeOptions::with_lz77(DefaultLz77Encoder::new());
let encoder = Encoder::with_options(Vec::new(), options);

However, unfortunately, the current libflate only provides DefaultLz77Encoder as a practical built-in LZ77 encoder implementation and it doesn't have the capability to change the compression level. (Actually, there is another Lz77Encode implementation named NoCompressionLz77Encoder but it seems to be of little use in practice)

Smotrov commented 4 years ago

Thank you very much @sile! Same story from GZIP?

sile commented 4 years ago

Same story from GZIP?

Yes (cf. libflate::gzip::EncodeOptions).

Smotrov commented 4 years ago

🙏

Code7R commented 9 months ago

Hi @Smotrov, thank you for reaching out.

In terms of API, you can specify a Lz77Encode instance to control the compression level via the EncodeOptions::with_lz77 method as follows:

// From: https://docs.rs/libflate/1.0.2/libflate/deflate/struct.EncodeOptions.html#example
use libflate::lz77::DefaultLz77Encoder;
use libflate::deflate::{Encoder, EncodeOptions};

let options = EncodeOptions::with_lz77(DefaultLz77Encoder::new());
let encoder = Encoder::with_options(Vec::new(), options);

However, unfortunately, the current libflate only provides DefaultLz77Encoder as a practical built-in LZ77 encoder implementation and it doesn't have the capability to change the compression level. (Actually, there is another Lz77Encode implementation named NoCompressionLz77Encoder but it seems to be of little use in practice)

I fail to see why this story was closed. The issue is no resolved. Even with:

let options = EncodeOptions::with_lz77(DefaultLz77Encoder::new());

there is no way to set the compression level. You also cannot push it through header, the field is private.