[][src]Struct explode::Explode

pub struct Explode { /* fields omitted */ }

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

impl Explode[src]

pub fn new() -> Self[src]

Create a new Explode decompression state.

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

Provide a buffer to decompress into.

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

pub fn done(&self) -> bool[src]

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

impl Debug for Explode[src]

Auto Trait Implementations

impl RefUnwindSafe for Explode

impl Send for Explode

impl Sync for Explode

impl Unpin for Explode

impl UnwindSafe for Explode

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.