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.