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

source

pub(crate) fn new() -> Self

source

pub(crate) fn reset(&mut self)

source

pub(crate) fn set_max_total_output(&mut self, n: usize)

source

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.

source

pub(crate) fn ignore_adler32(&self) -> bool

Return the ignore_adler32 flag.

source

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.

source

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.

source

fn prepare_vec_for_appending(&mut self)

Resize the vector to allow allocation of more data.

source

fn decoding_size(&self, len: usize) -> usize

source

fn transfer_finished_data(&mut self, image_data: &mut Vec<u8>) -> usize

source

fn compact_out_buffer_if_needed(&mut self)

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.