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
impl Explode
Sourcepub fn with_buffer<'a>(&'a mut self, buf: &'a mut [u8]) -> ExplodeBuffer<'a>
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.
Sourcepub fn done(&self) -> bool
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.