added 7z and lzma support
This commit is contained in:
parent
b85719ed83
commit
6bd66a07e2
4 changed files with 258 additions and 36 deletions
|
|
@ -99,7 +99,7 @@ pub fn extract_tar(tar_file: &Path) -> io::Result<()> {
|
|||
|
||||
Ok(())
|
||||
}
|
||||
pub fn extract_xz(input_path: &Path, output_directory: &Path) -> Result<(), io::Error> {
|
||||
pub fn extract_lzma(input_path: &Path, output_directory: &Path) -> Result<(), io::Error> {
|
||||
// Open the input XZ file
|
||||
let input_file = File::open(input_path)?;
|
||||
|
||||
|
|
@ -166,11 +166,15 @@ pub fn extract_bz2(input_path: &Path, output_directory: &Path) -> Result<(), io:
|
|||
|
||||
Ok(())
|
||||
}
|
||||
pub fn extract_7z(input_path: &Path, output_directory: &Path) -> Result<(), io::Error> {
|
||||
|
||||
sevenz_rust::decompress_file(input_path, output_directory).expect("complete");
|
||||
|
||||
Ok(())
|
||||
}
|
||||
// pub fn extract_tbz2(){}
|
||||
// pub fn extract_tgz(){}
|
||||
// pub fn extract_txz(){}
|
||||
// pub fn extract_lzma(){}
|
||||
// pub fn extract_7z(){}
|
||||
// pub fn extract_arj(){}
|
||||
// pub fn extract_cab(){}
|
||||
// pub fn extract_chm(){}
|
||||
|
|
|
|||
54
src/main.rs
54
src/main.rs
|
|
@ -17,7 +17,7 @@ use extractors::{
|
|||
extract_zip,
|
||||
extract_rar,
|
||||
extract_tar,
|
||||
extract_xz,
|
||||
extract_lzma,
|
||||
extract_bz2,
|
||||
// extract_tbz2,
|
||||
// extract_tgz,
|
||||
|
|
@ -25,7 +25,7 @@ use extractors::{
|
|||
// extract_lzma,
|
||||
extract_gz,
|
||||
// extract_z,
|
||||
// extract_7z,
|
||||
extract_7z,
|
||||
// extract_arj,
|
||||
// extract_cab,
|
||||
// extract_chm,
|
||||
|
|
@ -76,13 +76,17 @@ fn run() -> i32 {
|
|||
println!("Error creating output directory: {}", err);
|
||||
return 1;
|
||||
}
|
||||
if let Err(err) = extract_xz(&fname, &output_directory) {
|
||||
if let Err(err) = extract_lzma(&fname, &output_directory) {
|
||||
println!("Error extracting XZ: {}", err);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
"gz" => {
|
||||
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_gz(&fname, &output_directory) {
|
||||
println!("Error extracting GZ: {}", err);
|
||||
return 1;
|
||||
|
|
@ -90,11 +94,37 @@ fn run() -> i32 {
|
|||
}
|
||||
"bz2" => {
|
||||
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_bz2(&fname, &output_directory) {
|
||||
println!("Error extracting BZ2: {}", err);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
"lzma" => {
|
||||
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_lzma(&fname, &output_directory) {
|
||||
println!("Error extracting LZMA: {}", err);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
"7z" => {
|
||||
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_7z(&fname, &output_directory) {
|
||||
println!("Error extracting 7Z: {}", err);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
/*
|
||||
"tbz2" => {
|
||||
if let Err(err) = extract_tbz2(&fname) {
|
||||
|
|
@ -114,24 +144,6 @@ fn run() -> i32 {
|
|||
return 1;
|
||||
}
|
||||
}
|
||||
"lzma" => {
|
||||
if let Err(err) = extract_lzma(&fname) {
|
||||
println!("Error extracting LZMA: {}", err);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
"z" => {
|
||||
if let Err(err) = extract_z(&fname) {
|
||||
println!("Error extracting Z: {}", err);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
"7z" => {
|
||||
if let Err(err) = extract_7z(&fname) {
|
||||
println!("Error extracting 7Z: {}", err);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
"arj" => {
|
||||
if let Err(err) = extract_arj(&fname) {
|
||||
println!("Error extracting ARJ: {}", err);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue