#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

#496 in Compression

Download history 41/week @ 2023-11-27 24/week @ 2023-12-04 30/week @ 2023-12-11 40/week @ 2023-12-18 29/week @ 2023-12-25 20/week @ 2024-01-01 34/week @ 2024-01-08 36/week @ 2024-01-15 22/week @ 2024-01-22 26/week @ 2024-01-29 33/week @ 2024-02-05 41/week @ 2024-02-12 47/week @ 2024-02-19 63/week @ 2024-02-26 49/week @ 2024-03-04 78/week @ 2024-03-11

244 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

~17KB