How to unzip tar.gz file with Rust?

100 Views Asked by At

I'm building a cli tool that unzips a file (probably tar.gz) and then move it to a target directory using the zip_extract crate. But I got stuck. I don't really understand much yet about compression neither Rust.

Code

#[derive(Parser)]
struct Cli {
    zip_path: std::path::PathBuf
}


fn main() -> std::io::Result<()>{

    let args = Cli::parse();

    let default_path = Path::new("/home/hal/jetbrains");

    let file = File::open(&args.zip_path)?;
    match zip_extract::extract(file, default_path, true){
        Ok(res) => res,
        Err(err) => panic!("Error {}", err)
    }

    Ok(())
}

Error

  • invalid Zip archive: Could not find central directory end

Tries

I figured the problem could be about which format zip_extract crate accepts. I made sure to pass a valid compressed file path, and even used different files with different compressed formats. First I used a .tar.gz, which gave me this error, then I've tried passing a .bz2, which gave me the same error.

Any ideas?

0

There are 0 best solutions below