#lzma #codec #xz #java #ported #lzma2

lzma-rust

LZMA/LZMA2 codec ported from 'tukaani xz for java'

8 releases

0.1.7 Jul 17, 2024
0.1.6 Apr 5, 2024
0.1.5 Sep 29, 2023
0.1.4 Jun 16, 2023
0.1.0 Jan 31, 2023

#179 in Compression

Download history 3159/week @ 2024-07-18 2913/week @ 2024-07-25 2683/week @ 2024-08-01 2945/week @ 2024-08-08 2905/week @ 2024-08-15 3073/week @ 2024-08-22 3950/week @ 2024-08-29 4313/week @ 2024-09-05 3566/week @ 2024-09-12 3446/week @ 2024-09-19 3317/week @ 2024-09-26 3421/week @ 2024-10-03 3064/week @ 2024-10-10 3056/week @ 2024-10-17 3258/week @ 2024-10-24 2678/week @ 2024-10-31

12,613 downloads per month
Used in 27 crates (2 directly)

Apache-2.0

160KB
4.5K SLoC

LZMA/LZMA2 codec ported from tukaani xz for java

Usage

lzma

    use std::io::{Read, Write};
    use lzma_rust::*;

    let s = b"Hello, world!";
    let mut out = Vec::new();
    let mut options = LZMA2Options::with_preset(6);
    options.dict_size = LZMA2Options::DICT_SIZE_DEFAULT;

    let mut w = LZMAWriter::new_use_header(CountingWriter::new(&mut out), &options, None).unwrap();
    w.write_all(s).unwrap();
    w.write(&[]).unwrap();
    let mut r = LZMAReader::new_mem_limit(&out[..], u32::MAX, None).unwrap();
    let mut s2 = vec![0; s.len()];
    r.read_exact(&mut s2).unwrap();
    println!("{:?}", &out[..]);
    assert_eq!(s, &s2[..]);

lzma2

    use std::io::{Read, Write};
    use lzma_rust::*;

    let s = b"Hello, world!";
    let mut out = Vec::new();
    let mut options = LZMA2Options::with_preset(6);
    options.dict_size = LZMA2Options::DICT_SIZE_DEFAULT;
    {
        let mut w = LZMA2Writer::new(CountingWriter::new(&mut out), &options);
        w.write_all(s).unwrap();
        w.write(&[]).unwrap();
    }
    let mut r = LZMA2Reader::new(&out[..], options.dict_size, None);
    let mut s2 = vec![0; s.len()];
    r.read_exact(&mut s2).unwrap();
    println!("{:?}", &out[..]);
    assert_eq!(s, &s2[..]);

Dependencies

~115KB