Crate weezl[−][src]
LZW decoder and encoder
This crates provides an Encoder
and a Decoder
in their respective modules. The code words
are written from and to bit byte slices (or streams) where it is possible to write either the
most or least significant bits first. The maximum possible code size is 12 bits, the smallest
available code size is 2 bits.
The de- and encoder expect the LZW stream to start with a clear code and end with an end code which are defined as follows:
CLEAR_CODE == 1 << min_code_size
END_CODE == CLEAR_CODE + 1
For optimal performance, all buffers and input and output slices should be as large as possible
and at least 2048 bytes long. This extends to input streams which should have similarly sized
buffers. This library uses Rust’s standard allocation interfaces (Box
and Vec
to be
precise). Since there are no ways to handle allocation errors it is not recommended to operate
it on 16-bit targets.
Exemplary use of the encoder:
use weezl::{BitOrder, encode::Encoder}; let size = 8; let data = b"TOBEORNOTTOBEORTOBEORNOT"; let mut compressed = vec![]; let mut enc = Encoder::new(BitOrder::Msb, size); let result = enc.into_stream(&mut compressed).encode(&data[..]); result.status.unwrap();
The main algorithm can be used in no_std
as well, although it requires an allocator. This
restriction might be lifted at a later stage. For this you should deactivate the std
feature.
The main interfaces stay intact but the into_stream
combinator is no available.
Modules
decode | A module for all decoding needs. |
encode | A module for all encoding needs. |
Structs
BufferResult | The result of a coding operation on a pair of buffer. |
StreamResult | The result of coding into an output stream. |
Enums
BitOrder | The order of bits in bytes. |
LzwError | The error kind after unsuccessful coding of an LZW stream. |
LzwStatus | The status after successful coding of an LZW stream. |