Extract lzma file

Hello, I’m trying to use curl and xz2 to download and extract lzma file.
Program panic at decompressor.read_to_end(&mut buf).unwrap(); and I’m don’t know how to fix it. data parameter in the closure is byte array.

thread 'main' panicked at 'calledResult::unwrap()on anErrvalue: Custom { kind: Other, error: Format }', src/libcore/result.rs:997:5

use curl::easy::Easy;
use std::io::prelude::*;
use xz2::read::XzDecoder;
use std::fs::File;

fn main() {
    let mut easy = Easy::new();
    easy.write_function(|data| {
        let mut decompressor = XzDecoder::new(data);
        let mut buf = vec![];
        decompressor.read_to_end(&mut buf).unwrap();
        println!("{}", data.len());

Edit: I just found out my file format is legacy LZMA, xz2 crate only support LZMA2.

There are many variants of LZMA compression formats with different headers and properties. Would be awesome at some point to have something like 7z SDK, but completely in Rust.

Currently there is a number of implementations/bindings, but all of them are relatively incomplete: https://crates.io/keywords/lzma

There is lzma-rs but it misses many things still.

Hi, @ [zufatyn]
I think this is kinda old, but i would try to get some help anyway. I can decompress these files in python and also in bash command-line. I could not get them to work I am trying to use lzma_sys unsafe c interface. But no dice.

Did you have any luck? I am new to the language and trying to learn . I appreciate all the help and thank you in advance.

Thank you

Try this one - https://github.com/gendx/lzma-rs.
I was updated recently and fixed many things since my last mention. Be sure to pin to the git repository for a while.

1 Like

Hi @XVilka
want to start by thanking you for the heads up and community support. As i am new to rust, it is very encouraging to see support for obscure problems.

I went though the projects new developments.

lzma_rs::lzma_decompress_with_options looks really promising.

it is still reading 8 byte header. the old lzma files contain 13 byte headers.

it now does allow the option to use a user provided unpack size, UnpackedSize::UseProvided(Some(UNPACKED_SIZE))

However, i could not get the unpack size correctly as i am not reading the header properly. ( as it is 13 byte)

I will grind at it some more.

Thank you again

Did you mean this issue? https://github.com/gendx/lzma-rs/issues/13