added support for gz

This commit is contained in:
specCon18 2023-09-03 01:00:10 -04:00
parent 17ea4f951c
commit 5e152b4a1b
4 changed files with 47 additions and 25 deletions

1
Cargo.lock generated
View file

@ -352,6 +352,7 @@ dependencies = [
"color-eyre", "color-eyre",
"crossterm", "crossterm",
"eyre", "eyre",
"flate2",
"indicatif", "indicatif",
"rayon", "rayon",
"rust-lzma", "rust-lzma",

View file

@ -10,6 +10,7 @@ clap = "2.33.3"
color-eyre = "0.6.2" color-eyre = "0.6.2"
crossterm = "0.27.0" crossterm = "0.27.0"
eyre = "0.6.8" eyre = "0.6.8"
flate2 = "1.0.27"
indicatif = "0.17.6" indicatif = "0.17.6"
rayon = "1.7.0" rayon = "1.7.0"
rust-lzma = "0.6.0" rust-lzma = "0.6.0"

View file

@ -1,9 +1,10 @@
/* /*
TODO_2: implement remaining extractor functions and write tests TODO_2: implement remaining extractor functions and write tests
*/ */
use std::{fs::{self, File}, io, path::Path,}; use std::{fs::{self, File}, io::{self, ErrorKind}, path::Path,};
use unrar::Archive; use unrar::Archive;
use lzma::reader::LzmaReader; use lzma::reader::LzmaReader;
use flate2::read::GzDecoder;
pub fn extract_zip(zip_file: &Path) -> io::Result<()> { pub fn extract_zip(zip_file: &Path) -> io::Result<()> {
let file = fs::File::open(zip_file)?; let file = fs::File::open(zip_file)?;
let mut archive = zip::ZipArchive::new(file)?; let mut archive = zip::ZipArchive::new(file)?;
@ -116,24 +117,42 @@ pub fn extract_xz(input_path: &Path, output_directory: &Path) -> Result<(), io::
Ok(()) Ok(())
} }
pub fn extract_bz2(){} pub fn extract_gz(input_path: &Path, output_directory: &Path) -> Result<(), io::Error> {
pub fn extract_tbz2(){} // Open the input GZ file
pub fn extract_tgz(){} let input_file = File::open(input_path)?;
pub fn extract_txz(){}
pub fn extract_lzma(){} // Create a GZ decompression reader
pub fn extract_gz(){} let mut decompressor = GzDecoder::new(input_file);
pub fn extract_z(){}
pub fn extract_7z(){} // Determine the output file path
pub fn extract_arj(){} let output_file_path = output_directory.join(input_path.file_stem().unwrap());
pub fn extract_cab(){}
pub fn extract_chm(){} // Create the output file
pub fn extract_deb(){} let mut output_file = File::create(&output_file_path)?;
pub fn extract_dmg(){}
pub fn extract_iso(){} // Read from the decompressor and write to the output file
pub fn extract_lzh(){} match io::copy(&mut decompressor, &mut output_file) {
pub fn extract_msi(){} Ok(_) => Ok(()),
pub fn extract_rpm(){} Err(err) => Err(io::Error::new(ErrorKind::Other, err.to_string())),
pub fn extract_udf(){} }
pub fn extract_wim(){} }
pub fn extract_xar(){} // pub fn extract_bz2(){}
pub fn extract_exe(){} // pub fn extract_tbz2(){}
// pub fn extract_tgz(){}
// pub fn extract_txz(){}
// pub fn extract_lzma(){}
// pub fn extract_z(){}
// pub fn extract_7z(){}
// pub fn extract_arj(){}
// pub fn extract_cab(){}
// pub fn extract_chm(){}
// pub fn extract_deb(){}
// pub fn extract_dmg(){}
// pub fn extract_iso(){}
// pub fn extract_lzh(){}
// pub fn extract_msi(){}
// pub fn extract_rpm(){}
// pub fn extract_udf(){}
// pub fn extract_wim(){}
// pub fn extract_xar(){}
// pub fn extract_exe(){}

View file

@ -23,7 +23,7 @@ use extractors::{
// extract_tgz, // extract_tgz,
// extract_txz, // extract_txz,
// extract_lzma, // extract_lzma,
// extract_gz, extract_gz,
// extract_z, // extract_z,
// extract_7z, // extract_7z,
// extract_arj, // extract_arj,
@ -81,13 +81,14 @@ fn run() -> i32 {
return 1; return 1;
} }
} }
/*
"gz" => { "gz" => {
if let Err(err) = extract_gz(&fname) { let output_directory = Path::new("output_directory"); // Change this to your desired output directory
if let Err(err) = extract_gz(&fname, &output_directory) {
println!("Error extracting GZ: {}", err); println!("Error extracting GZ: {}", err);
return 1; return 1;
} }
} }
/*
"bz2" => { "bz2" => {
if let Err(err) = extract_bz2(&fname) { if let Err(err) = extract_bz2(&fname) {
println!("Error extracting BZ2: {}", err); println!("Error extracting BZ2: {}", err);