Remove libdeflate slack space no longer needed
This commit is contained in:
parent
2293b32cce
commit
8eb5a3f419
1 changed files with 2 additions and 4 deletions
|
|
@ -4,16 +4,14 @@ use libdeflater::*;
|
|||
|
||||
pub fn deflate(data: &[u8], level: u8, max_size: &AtomicMin) -> PngResult<Vec<u8>> {
|
||||
let mut compressor = Compressor::new(CompressionLvl::new(level.into()).unwrap());
|
||||
// If adhering to a max_size we need to include at least 9 extra bytes of slack space (as specified in docs).
|
||||
let capacity = max_size
|
||||
.get()
|
||||
.unwrap_or_else(|| compressor.zlib_compress_bound(data.len()))
|
||||
+ 9;
|
||||
.unwrap_or_else(|| compressor.zlib_compress_bound(data.len()));
|
||||
let mut dest = vec![0; capacity];
|
||||
let len = compressor
|
||||
.zlib_compress(data, &mut dest)
|
||||
.map_err(|err| match err {
|
||||
CompressionError::InsufficientSpace => PngError::DeflatedDataTooLong(capacity - 9),
|
||||
CompressionError::InsufficientSpace => PngError::DeflatedDataTooLong(capacity),
|
||||
})?;
|
||||
dest.truncate(len);
|
||||
Ok(dest)
|
||||
|
|
|
|||
Loading…
Reference in a new issue