| Crates.io | lzs |
| lib.rs | lzs |
| version | 0.1.1 |
| created_at | 2025-05-10 20:08:49.503364+00 |
| updated_at | 2025-05-11 19:56:04.469951+00 |
| description | A LZSS (early implementation) en-/decompressor (lossless data compression, no_std capable, in pure Rust) |
| homepage | |
| repository | https://github.com/myst6re/lzs |
| max_upload_size | |
| id | 1668772 |
| size | 67,109 |
LZSS is a lossless data compression algorithm in pure Rust.
This crate is built for embedded systems:
no_std featureThis crate (lzs) implements an early version of the LZSS algorithm published by Haruhiko Okumura in 1989.
In this version, only the initial character (C) in configurable.
The lzss crate implements a version of LZSS that can work bit by bit, instead of byte by byte. Also the structure is different, meaning lzss crate output is incompatible with lzs crate output.
This algorithm has by design no header at all. Please be aware that it is not possible to check if the contents is correct, or even the length matches. It is recommended to add a header based on the requirements.
This code is based on the LZSS encoder-decoder by Haruhiko Okumura, public domain.
In order to create an encoder-decoder which is compatible to the program above
the following is required: C = 0x20
alloc - Allows de-/compression with buffer on the heap and the VecWriter.safe - Only use safe code (see Safety below).std - Enables alloc and additional IOSimpleReader, IOSimpleWriter,
and the Error instance for LzsError.std and safe are enabled by default.
With defaults (std and safe):
[dependencies]
lzs = "0.9"
With no_std (and without safe):
[dependencies]
lzs = { version = "0.9", default-features = false }
let input = b"Example Data";
let mut output = [0; 30];
let result = Lzs::new(0x20).compress(
SliceReader::new(input),
SliceWriter::new(&mut output),
);
assert_eq!(result, Ok(14)); // there was no overflow and the output is 14 bytes long
With the safe feature the code is not using any unsafe code (forbid(unsafe_code)), but at
the cost of performance and size - though on modern systems that is not to mention.
But on smaller systems (like microcontrollers, where no_std is needed) it may be noticeable.
Which is the reason wht it can be switched on/off.
In oder to de-/compress files in the cli, install lzs-cli:
cargo install lzs-cli
Example:
lzs e 10,4,0x20 <input >outout