pub struct Decoder { /* private fields */ }
Expand description

The state for decoding data with an LZW algorithm.

The same structure can be utilized with streams as well as your own buffers and driver logic. It may even be possible to mix them if you are sufficiently careful not to lose or skip any already decode data in the process.

This is a sans-IO implementation, meaning that it only contains the state of the decoder and the caller will provide buffers for input and output data when calling the basic decode_bytes method. Nevertheless, a number of adapters are provided in the into_* methods for decoding with a particular style of common IO.

  • decode for decoding once without any IO-loop.
  • into_async for decoding with the futures traits for asynchronous IO.
  • into_stream for decoding with the standard io traits.
  • into_vec for in-memory decoding.

Implementations

Create a new decoder with the specified bit order and symbol size.

The algorithm for dynamically increasing the code symbol bit width is compatible with the original specification. In particular you will need to specify an Lsb bit oder to decode the data portion of a compressed gif image.

Panics

The size needs to be in the interval 0..=12.

Create a TIFF compatible decoder with the specified bit order and symbol size.

The algorithm for dynamically increasing the code symbol bit width is compatible with the TIFF specification, which is a misinterpretation of the original algorithm for increasing the code size. It switches one symbol sooner.

Panics

The size needs to be in the interval 0..=12.

Decode some bytes from inp and write result to out.

This will consume a prefix of the input buffer and write decoded output into a prefix of the output buffer. See the respective fields of the return value for the count of consumed and written bytes. For the next call You should have adjusted the inputs accordingly.

The call will try to decode and write as many bytes of output as available. It will be much more optimized (and avoid intermediate buffering) if it is allowed to write a large contiguous chunk at once.

See into_stream for high-level functions (that are only available with the std feature).

Decode a single chunk of lzw encoded data.

This method requires the data to contain an end marker, and returns an error otherwise.

This is a convenience wrapper around into_vec. Use the into_vec adapter to customize buffer size, to supply an existing vector, to control whether an end marker is required, or to preserve partial data in the case of a decoding error.

Example
use weezl::{BitOrder, decode::Decoder};

// Encoded that was created with an encoder.
let data = b"\x80\x04\x81\x94l\x1b\x06\xf0\xb0 \x1d\xc6\xf1\xc8l\x19 \x10";
let decoded = Decoder::new(BitOrder::Msb, 9)
    .decode(data)
    .unwrap();
assert_eq!(decoded, b"Hello, world");

Construct a decoder into a writer.

Construct a decoder into an async writer.

Construct a decoder into a vector.

All decoded data is appended and the vector is not cleared.

Compared to into_stream this interface allows a high-level access to decoding without requires the std-feature. Also, it can make full use of the extra buffer control that the special target exposes.

Check if the decoding has finished.

No more output is produced beyond the end code that marked the finish of the stream. The decoder may have read additional bytes, including padding bits beyond the last code word but also excess bytes provided.

Reset all internal state.

This produce a decoder as if just constructed with new but taking slightly less work. In particular it will not deallocate any internal allocations. It will also avoid some duplicate setup work.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.