1 unstable release
0.1.0 | Jan 2, 2019 |
---|
#496 in Compression
244 downloads per month
Used in 4 crates
12KB
170 lines
rust-smaz
rust-smaz is a pure Rust implementation of smaz - algorithm for compressing very short strings. See original C implementation smaz by antirez for information on smaz and the algorithm itself.
Usage
Add this to your Cargo.toml
:
[dependencies]
smaz = "0.1.0"
Quick start
extern crate smaz;
use smaz::{compress,decompress};
fn main() {
let s = "string";
let compressed = compress(&s.as_bytes());
println!("compress bytes: {:?}", &compressed);
let decompressed = decompress(&compressed).unwrap();
let origin = str::from_utf8(&decompressed).unwrap();
assert_eq!(s, origin);
}
lib.rs
:
This crate implements the smaz algorithm for compressing very short strings.
Smaz instead is not good for compressing general purpose data, but can compress text by 40-50% in the average case (works better with English), and is able to perform a bit of compression for HTML and urls as well. The important point is that Smaz is able to compress even strings of two or three bytes!
See original library by antirez for information on smaz and the algorithm itself.
Quick Start
extern crate smaz;
use smaz::{compress,decompress};
fn main() {
let s = "my long string";
let compressed = compress(&s.as_bytes());
println!("bytes: {:?}", &compressed);
let decompressed = decompress(&compressed);
if let Ok(v) = decompressed {
println!("bytes: {:?}", &v);
}
}
Compression examples
This is a small string
compressed by 50%foobar
compressed by 34%the end
compressed by 58%not-a-g00d-Exampl333
enlarged by 15%Smaz is a simple compression library
compressed by 39%Nothing is more difficult, and therefore more precious, than to be able to decide
compressed by 49%this is an example of what works very well with smaz
compressed by 49%1000 numbers 2000 will 10 20 30 compress very little
compressed by 10%and now a few italian sentences:
compressed by 41%Nel mezzo del cammin di nostra vita, mi ritrovai in una selva oscura
compressed by 33%Mi illumino di immenso
compressed by 37%L'autore di questa libreria vive in Sicilia
compressed by 28%try it against urls
compressed by 37%http://google.com
compressed by 59%http://programming.reddit.com
compressed by 52%
Dependencies
~17KB