#string #compressing #short #algorithm #pure #byte

smaz

Smaz is a simple compression library suitable for compressing very short strings

1 unstable release

0.1.0 Jan 2, 2019

#678 in Compression

Download history 47/week @ 2024-07-19 59/week @ 2024-07-26 81/week @ 2024-08-02 74/week @ 2024-08-09 68/week @ 2024-08-16 136/week @ 2024-08-23 319/week @ 2024-08-30 97/week @ 2024-09-06 159/week @ 2024-09-13 159/week @ 2024-09-20 131/week @ 2024-09-27 77/week @ 2024-10-04 68/week @ 2024-10-11 55/week @ 2024-10-18 49/week @ 2024-10-25 51/week @ 2024-11-01

229 downloads per month
Used in 4 crates

MIT license

12KB
170 lines

rust-smaz

Build Status Crate Docs

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

~10KB