Got XZ files decompressing

This commit is contained in:
specCon18 2023-09-03 00:45:16 -04:00
parent 670a380cd5
commit 17ea4f951c
5 changed files with 50 additions and 42 deletions

17
Cargo.lock generated
View file

@ -354,6 +354,7 @@ dependencies = [
"eyre", "eyre",
"indicatif", "indicatif",
"rayon", "rayon",
"rust-lzma",
"tar", "tar",
"unrar", "unrar",
"zip", "zip",
@ -726,6 +727,16 @@ version = "0.7.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dbb5fb1acd8a1a18b3dd5be62d25485eb770e05afb408a9627d14d451bae12da" checksum = "dbb5fb1acd8a1a18b3dd5be62d25485eb770e05afb408a9627d14d451bae12da"
[[package]]
name = "rust-lzma"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7d62915608f6cee1d7f2fc00f28b4f058ff79d6e4ec3c2fe0006b09b52437c84"
dependencies = [
"pkg-config",
"vcpkg",
]
[[package]] [[package]]
name = "rustc-demangle" name = "rustc-demangle"
version = "0.1.23" version = "0.1.23"
@ -984,6 +995,12 @@ version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d"
[[package]]
name = "vcpkg"
version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426"
[[package]] [[package]]
name = "vec_map" name = "vec_map"
version = "0.8.2" version = "0.8.2"

View file

@ -12,7 +12,7 @@ crossterm = "0.27.0"
eyre = "0.6.8" eyre = "0.6.8"
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"
tar = "0.4.40" tar = "0.4.40"
unrar = "0.5.1" unrar = "0.5.1"
zip = "0.6.6" zip = "0.6.6"

View file

@ -1,5 +1,5 @@
{ {
description = "Spec's NixOS-config"; description = "ExtractRS for all you decompression needs";
inputs = { inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
}; };
@ -19,13 +19,10 @@
clippy clippy
lolcat lolcat
rust-analyzer rust-analyzer
xz # Add xz (liblzma) to the build inputs xz
pkg-config
]; ];
# Add a shellHook to modify PKG_CONFIG_PATH
shellHook = ''
export PKG_CONFIG_PATH="${pkgs.xz}/lib/pkgconfig:$PKG_CONFIG_PATH"
'';
}; };
}; };
} }

View file

@ -1,9 +1,9 @@
/* /*
TODO_2: implement remaining extractor functions and write tests TODO_2: implement remaining extractor functions and write tests
*/ */
use std::{fs, io::{self, Write}, path::Path, fs::File}; use std::{fs::{self, File}, io, path::Path,};
use unrar::Archive; use unrar::Archive;
// use lzma::reader::LzmaReader; use lzma::reader::LzmaReader;
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)?;
@ -76,7 +76,7 @@ pub fn extract_rar(rar_file: &Path) -> Result<(), Box<dyn std::error::Error>> {
Ok(()) Ok(())
} }
pub fn extract_tar(tar_file: &Path) -> io::Result<()> { pub fn extract_tar(tar_file: &Path) -> io::Result<()> {
let tar_file = fs::File::open(tar_file)?; let tar_file = fs::File::open(tar_file)?;
let mut a = tar::Archive::new(tar_file); let mut a = tar::Archive::new(tar_file);
@ -97,31 +97,25 @@ pub fn extract_rar(rar_file: &Path) -> Result<(), Box<dyn std::error::Error>> {
Ok(()) Ok(())
} }
// pub fn extract_xz(xz_file: &Path, output_dir: &Path) -> io::Result<()> { pub fn extract_xz(input_path: &Path, output_directory: &Path) -> Result<(), io::Error> {
// // Open the xz file for reading // Open the input XZ file
// let file = File::open(xz_file)?; let input_file = File::open(input_path)?;
// // Create a LzmaReader to decompress the data // Create a decompression reader
// let mut xz_reader = LzmaReader::new_decompressor(file)?; let mut decompressor = LzmaReader::new_decompressor(input_file)
.map_err(|err| io::Error::new(io::ErrorKind::Other, err))?;
// // Read the decompressed data into a buffer // Determine the output file path
// let mut decompressed_data = Vec::new(); let output_file_path = output_directory.join(input_path.file_stem().unwrap());
// xz_reader.read_to_end(&mut decompressed_data)?;
// // Get the filename from the original path // Create the output file
// let xz_filename = xz_file let mut output_file = File::create(&output_file_path)?;
// .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 // Read from the decompressor and write to the output file
// let mut output_file = File::create(output_path)?; io::copy(&mut decompressor, &mut output_file)?;
// output_file.write_all(&decompressed_data)?;
// Ok(()) Ok(())
// } }
pub fn extract_bz2(){} pub fn extract_bz2(){}
pub fn extract_tbz2(){} pub fn extract_tbz2(){}
pub fn extract_tgz(){} pub fn extract_tgz(){}

View file

@ -17,7 +17,7 @@ use extractors::{
extract_zip, extract_zip,
extract_rar, extract_rar,
extract_tar, extract_tar,
// extract_xz, extract_xz,
// extract_bz2, // extract_bz2,
// extract_tbz2, // extract_tbz2,
// extract_tgz, // extract_tgz,
@ -70,17 +70,17 @@ fn run() -> i32 {
return 1; return 1;
} }
} }
// "xz" => { "xz" => {
// let output_directory = Path::new("output_directory"); // Change this to your desired output directory let output_directory = Path::new("output_directory"); // Change this to your desired output directory
// if let Err(err) = fs::create_dir_all(&output_directory) { if let Err(err) = fs::create_dir_all(&output_directory) {
// println!("Error creating output directory: {}", err); println!("Error creating output directory: {}", err);
// return 1; return 1;
// } }
// if let Err(err) = extract_xz(&fname, &output_directory) { if let Err(err) = extract_xz(&fname, &output_directory) {
// println!("Error extracting XZ: {}", err); println!("Error extracting XZ: {}", err);
// return 1; return 1;
// } }
// } }
/* /*
"gz" => { "gz" => {
if let Err(err) = extract_gz(&fname) { if let Err(err) = extract_gz(&fname) {