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

smaz

Smaz是一个适用于压缩非常短字符串的简单压缩库

1 个不稳定版本

0.1.0 2019年1月2日

#496压缩

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 每月下载量
4 crates 中使用

MIT 许可证

12KB
170

rust-smaz

Build Status Crate Docs

rust-smaz是smaz算法的纯Rust实现,用于压缩非常短的字符串。有关smaz及其算法本身的信息,请参阅antirez的原始C实现smaz

使用

将此添加到您的 Cargo.toml

[dependencies]
smaz = "0.1.0"

快速入门

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:

此crate实现了用于压缩非常短字符串的smaz算法。

Smaz不适用于压缩通用数据,但平均情况下可以压缩文本40-50%(对英文更有效),并且能够对HTML和URL进行一些压缩。重要的是,Smaz甚至可以压缩只有两个或三个字节的字符串!

有关smaz及其算法本身的信息,请参阅antirez的原始库

快速入门

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);
    }
}

压缩示例

  • 这是一个小字符串 压缩了50%
  • foobar 压缩了34%
  • the end 压缩了58%
  • not-a-g00d-Exampl333 扩大了15%
  • Smaz是一个简单的压缩库 压缩了39%
  • Nothing is more difficult, and therefore more precious, than to be able to decide 压缩了49%
  • this is an example of what works very well with smaz 压缩了49%
  • 1000 numbers 2000 will 10 20 30 compress very little 压缩了10%
  • and now a few italian sentences: 压缩了41%
  • Nel mezzo del cammin di nostra vita, mi ritrovai in una selva oscura 压缩了33%
  • Mi illumino di immenso 压缩了37%
  • L'autore di questa libreria vive in Sicilia 压缩了28%
  • try it against urls 压缩了37%
  • http://google.com 压缩了59%
  • http://programming.reddit.com 压缩了52%

依赖项

~17KB