Explode

Struct Explode 

Source
pub struct Explode { /* private fields */ }
Expand description

Low-level decompression interface.

This provides low-level access to the decompression algorithm. If possible, prefer using explode or ExplodeReader as they are simpler to use.

The usual control flow with this interface is to provide a buffer to decompress into with with_buffer, and then to feed the resulting ExplodeBuffer handle with bytes until it returns Ok. Then you can retrieve the filled portion of the buffer containing your decompressed data.

use explode::{Error, Explode};

// some test data to decompress
let input = vec![0x00, 0x04, 0x82, 0x24, 0x25, 0x8f, 0x80, 0x7f];
// which byte we are currently feeding in
let mut i = 0;
// our output buffer
let mut outbuf: [u8; 256] = [0; 256];

// decompress
let mut ex = explode::Explode::new();
let mut exbuf = ex.with_buffer(&mut outbuf);
// loop while we have more input, and decompression is not done
while i < input.len() && !exbuf.done() {
    // note we feed exbuf the *same byte* every loop, until it requests
    // more input with Error::IncompleteInput.
    match exbuf.feed(input[i]) {
        Ok(()) => {
            // buffer is full. use exbuf.get() to get the filled portion
            println!("{:?}", exbuf.get());
            // compression may not be finished, so reset and loop again
            exbuf.reset();
        }

        Err(Error::IncompleteInput) => {
            // advance our input cursor
            i += 1;
        }

        Err(e) => {
            // any other error is a sign the input is invalid
            panic!("{:?}", e);
        }
    }
}

if !exbuf.done() {
    // we ran out of input, but decompression isn't done!
    panic!("unexpected end of input");
}

Be careful that the input byte you provide to ExplodeBuffer::feed only changes when requested by Error::IncompleteInput. If the input changes at any other time, decompression will fail or produce incorrect output.

Implementations§

Source§

impl Explode

Source

pub fn new() -> Self

Create a new Explode decompression state.

Source

pub fn with_buffer<'a>(&'a mut self, buf: &'a mut [u8]) -> ExplodeBuffer<'a>

Provide a buffer to decompress into.

This returns a ExplodeBuffer handle that is used for feeding input to decompress and other operations.

Source

pub fn done(&self) -> bool

Returns true if decompression is finished.

If this function can’t be used because a ExplodeBuffer is currently borrowing this object mutably, you can use ExplodeBuffer::done instead.

Trait Implementations§

Source§

impl Debug for Explode

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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>,

Source§

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>,

Source§

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.