Workaround weird regression with &[u8] and zopfli

This commit is contained in:
Andrew 2024-02-20 16:41:29 +13:00 committed by Alejandro González
parent f602e84fa6
commit 86ff1e5833
No known key found for this signature in database

View file

@ -8,7 +8,9 @@ pub fn deflate(data: &[u8], iterations: NonZeroU8) -> PngResult<Vec<u8>> {
iteration_count: iterations.into(),
..Default::default()
};
match zopfli::compress(options, zopfli::Format::Zlib, data, &mut output) {
// Since Rust v1.74, passing &[u8] directly into zopfli causes a regression in compressed size
// for some files. Wrapping the slice in another Read implementer such as Box fixes it for now.
match zopfli::compress(options, zopfli::Format::Zlib, Box::new(data), &mut output) {
Ok(_) => (),
Err(_) => return Err(PngError::new("Failed to compress in zopfli")),
};