Struct png::decoder::zlib::ZlibStream
source · pub(super) struct ZlibStream {
state: Box<Decompressor>,
started: bool,
out_buffer: Vec<u8>,
out_pos: usize,
read_pos: usize,
max_total_output: usize,
ignore_adler32: bool,
}
Expand description
Ergonomics wrapper around miniz_oxide::inflate::stream
for zlib compressed data.
Fields§
§state: Box<Decompressor>
Current decoding state.
started: bool
If there has been a call to decompress already.
out_buffer: Vec<u8>
Remaining buffered decoded bytes. The decoder sometimes wants inspect some already finished bytes for further decoding. So we keep a total of 32KB of decoded data available as long as more data may be appended.
out_pos: usize
The first index of out_buffer
where new data can be written.
read_pos: usize
The first index of out_buffer
that hasn’t yet been passed to our client
(i.e. not yet appended to the image_data
parameter of fn decompress
or fn finish_compressed_chunks
).
max_total_output: usize
Limit on how many bytes can be decompressed in total. This field is mostly used for performance optimizations (e.g. to avoid allocating and zeroing out large buffers when only a small image is being decoded).
ignore_adler32: bool
Ignore and do not calculate the Adler-32 checksum. Defaults to true
.
This flag overrides TINFL_FLAG_COMPUTE_ADLER32
.
This flag should not be modified after decompression has started.
Implementations§
source§impl ZlibStream
impl ZlibStream
pub(crate) fn new() -> Self
pub(crate) fn reset(&mut self)
pub(crate) fn set_max_total_output(&mut self, n: usize)
sourcepub(crate) fn set_ignore_adler32(&mut self, flag: bool) -> bool
pub(crate) fn set_ignore_adler32(&mut self, flag: bool) -> bool
Set the ignore_adler32
flag and return true
if the flag was
successfully set.
The default is true
.
This flag cannot be modified after decompression has started until the ZlibStream is reset.
sourcepub(crate) fn ignore_adler32(&self) -> bool
pub(crate) fn ignore_adler32(&self) -> bool
Return the ignore_adler32
flag.
sourcepub(crate) fn decompress(
&mut self,
data: &[u8],
image_data: &mut Vec<u8>,
) -> Result<usize, DecodingError>
pub(crate) fn decompress( &mut self, data: &[u8], image_data: &mut Vec<u8>, ) -> Result<usize, DecodingError>
Fill the decoded buffer as far as possible from data
.
On success returns the number of consumed input bytes.
sourcepub(crate) fn finish_compressed_chunks(
&mut self,
image_data: &mut Vec<u8>,
) -> Result<(), DecodingError>
pub(crate) fn finish_compressed_chunks( &mut self, image_data: &mut Vec<u8>, ) -> Result<(), DecodingError>
Called after all consecutive IDAT chunks were handled.
The compressed stream can be split on arbitrary byte boundaries. This enables some cleanup within the decompressor and flushing additional data which may have been kept back in case more data were passed to it.
sourcefn prepare_vec_for_appending(&mut self)
fn prepare_vec_for_appending(&mut self)
Resize the vector to allow allocation of more data.