Nullus157 / async-compression

Adaptors between compression crates and Rust's async IO types
https://docs.rs/async-compression
Apache License 2.0
403 stars 79 forks source link

expose memlimit settings for xz2 decoders #252

Closed svenrademakers closed 12 months ago

svenrademakers commented 12 months ago

xz2 decoders are by default configured with a memory limit value of u64::max. This is problematic on targets where there is limited memory available for decoding. e.g. one could run out of memory. By exposing an additional function call XzDecoder::with_memlimit(..) and LzmaDecoder::with_memlimit(..) users can initialize a decoder with a given memory limit.

Consequently specifying a too low value means the decoder will fail to decompress. On this occasion the decoder will return an io::Error::Custom value with the message "MemLimit" to signal it needs to be configured with more memory.

This error is propagated by the chosen interface, AsyncBufRead or AsyncWrite, therefore no additional error handling has to be implemented to handle this "side effect"