added xz support

This commit is contained in:
specCon18 2023-09-02 15:11:48 -04:00
parent 3dc2c9cc5f
commit 670a380cd5
8 changed files with 136 additions and 66 deletions

View file

@ -8,7 +8,6 @@ pub enum Extensions{
Txz,
Lzma,
Gz,
Gz,
Xz,
Z,
Sevenz,

View file

@ -1,6 +1,9 @@
use std::{fs, io, path::Path};
/*
TODO_2: implement remaining extractor functions and write tests
*/
use std::{fs, io::{self, Write}, path::Path, fs::File};
use unrar::Archive;
// use lzma::reader::LzmaReader;
pub fn extract_zip(zip_file: &Path) -> io::Result<()> {
let file = fs::File::open(zip_file)?;
let mut archive = zip::ZipArchive::new(file)?;
@ -94,13 +97,37 @@ pub fn extract_rar(rar_file: &Path) -> Result<(), Box<dyn std::error::Error>> {
Ok(())
}
// pub fn extract_xz(xz_file: &Path, output_dir: &Path) -> io::Result<()> {
// // Open the xz file for reading
// let file = File::open(xz_file)?;
// // Create a LzmaReader to decompress the data
// let mut xz_reader = LzmaReader::new_decompressor(file)?;
// // Read the decompressed data into a buffer
// let mut decompressed_data = Vec::new();
// xz_reader.read_to_end(&mut decompressed_data)?;
// // Get the filename from the original path
// let xz_filename = xz_file
// .file_name()
// .ok_or_else(|| io::Error::new(io::ErrorKind::InvalidInput, "Invalid file name"))?;
// // Create the output file path by appending the filename to the output directory
// let output_path = output_dir.join(xz_filename);
// // Create or overwrite the output file and write the decompressed data to it
// let mut output_file = File::create(output_path)?;
// output_file.write_all(&decompressed_data)?;
// Ok(())
// }
pub fn extract_bz2(){}
pub fn extract_tbz2(){}
pub fn extract_tgz(){}
pub fn extract_txz(){}
pub fn extract_lzma(){}
pub fn extract_gz(){}
pub fn extract_xz(){}
pub fn extract_z(){}
pub fn extract_7z(){}
pub fn extract_arj(){}

View file

@ -1,44 +1,48 @@
/*
TODO_3: setup rayon to handle parallel file processsing when passed
more than one file and square up concurrency model for files with
more than one extension.
*/
/*
TODO_1: define supported extensions as structs and write an extensions enum
*/
mod extractors;
// mod extensions;
// use extenstions::{
// File,
// Extensions
// }
use std::{path::Path, fs};
use extractors::{
extract_zip,
extract_rar,
extract_tar,
extract_bz2,
extract_tbz2,
extract_tgz,
extract_txz,
extract_lzma,
extract_gz,
extract_gz,
extract_xz,
extract_z,
extract_7z,
extract_arj,
extract_cab,
extract_chm,
extract_deb,
extract_dmg,
extract_iso,
extract_lzh,
extract_msi,
extract_rpm,
extract_udf,
extract_wim,
extract_xar,
extract_exe
// extract_xz,
// extract_bz2,
// extract_tbz2,
// extract_tgz,
// extract_txz,
// extract_lzma,
// extract_gz,
// extract_z,
// extract_7z,
// extract_arj,
// extract_cab,
// extract_chm,
// extract_deb,
// extract_dmg,
// extract_iso,
// extract_lzh,
// extract_msi,
// extract_rpm,
// extract_udf,
// extract_wim,
// extract_xar,
// extract_exe
};
fn main() {
std::process::exit(run());
}
/*
TODO: [ ] setup rayon to handle concurrent file processsing when passed
more than one file
*/
/*
TODO: [ ] Write for loop to iter over all extensions of a file to handle
files that are tared and then compressed ex: foo.tar.gz, foo.tar.gz
*/
fn run() -> i32 {
let args: Vec<_> = std::env::args().collect();
if args.len() < 2 {
@ -66,13 +70,18 @@ fn run() -> i32 {
return 1;
}
}
// "xz" => {
// let output_directory = Path::new("output_directory"); // Change this to your desired output directory
// if let Err(err) = fs::create_dir_all(&output_directory) {
// println!("Error creating output directory: {}", err);
// return 1;
// }
// if let Err(err) = extract_xz(&fname, &output_directory) {
// println!("Error extracting XZ: {}", err);
// return 1;
// }
// }
/*
"xz" => {
if let Err(err) = extract_xz(&fname) {
println!("Error extracting XZ: {}", err);
return 1;
}
}
"gz" => {
if let Err(err) = extract_gz(&fname) {
println!("Error extracting GZ: {}", err);