refactored extractors to lib
This commit is contained in:
parent
b54eba4428
commit
acd33b44af
5 changed files with 11 additions and 86 deletions
|
|
@ -19,3 +19,12 @@ sevenz-rust = "0.5.2"
|
|||
tar = "0.4.40"
|
||||
unrar = "0.5.1"
|
||||
zip = "0.6.6"
|
||||
|
||||
|
||||
[[bin]]
|
||||
name = "sk_extract_cli"
|
||||
path = "src/main.rs"
|
||||
|
||||
[lib]
|
||||
name = "sk_extract_lib"
|
||||
path = "src/lib/lib.rs"
|
||||
|
|
|
|||
|
|
@ -1,60 +0,0 @@
|
|||
pub enum Extensions{
|
||||
Zip,
|
||||
Rar,
|
||||
Tar,
|
||||
Bz2,
|
||||
Tbz2,
|
||||
Tgz,
|
||||
Txz,
|
||||
Lzma,
|
||||
Gz,
|
||||
Xz,
|
||||
Z,
|
||||
Sevenz,
|
||||
Arj,
|
||||
Cab,
|
||||
Chm,
|
||||
Deb,
|
||||
Dmg,
|
||||
Iso,
|
||||
Lzh,
|
||||
Msi,
|
||||
Rpm,
|
||||
Udf,
|
||||
Wim,
|
||||
Xar,
|
||||
Exe
|
||||
};
|
||||
|
||||
pub struct File{
|
||||
filename: String;
|
||||
extensions: <Extensions>;
|
||||
path: String;
|
||||
};
|
||||
|
||||
pub struct Zip{};
|
||||
pub struct Rar{};
|
||||
pub struct Tar{};
|
||||
pub struct Bz2{};
|
||||
pub struct Tbz2{};
|
||||
pub struct Tgz{};
|
||||
pub struct Txz{};
|
||||
pub struct Lzma{};
|
||||
pub struct Gz{};
|
||||
pub struct Gz{};
|
||||
pub struct Xz{};
|
||||
pub struct Z{};
|
||||
pub struct Sevenz{};
|
||||
pub struct Arj{};
|
||||
pub struct Cab{};
|
||||
pub struct Chm{};
|
||||
pub struct Deb{};
|
||||
pub struct Dmg{};
|
||||
pub struct Iso{};
|
||||
pub struct Lzh{};
|
||||
pub struct Msi{};
|
||||
pub struct Rpm{};
|
||||
pub struct Udf{};
|
||||
pub struct Wim{};
|
||||
pub struct Xar{};
|
||||
pub struct Exe{};
|
||||
|
|
@ -28,15 +28,8 @@ pub fn extract_zip(input_path: &Path, output_directory: &Path) -> Result<(), io:
|
|||
}
|
||||
|
||||
if (*file.name()).ends_with('/') {
|
||||
println!("File {} extracted to \"{}\"", i, full_outpath.display());
|
||||
fs::create_dir_all(&full_outpath).unwrap();
|
||||
} else {
|
||||
println!(
|
||||
"File {} extracted to \"{}\" ({} bytes)",
|
||||
i,
|
||||
full_outpath.display(),
|
||||
file.size()
|
||||
);
|
||||
if let Some(p) = full_outpath.parent() {
|
||||
if !p.exists() {
|
||||
fs::create_dir_all(p).unwrap();
|
||||
|
|
@ -65,11 +58,6 @@ pub fn extract_rar(input_path: &Path, output_directory: &Path) -> Result<(), Box
|
|||
.open_for_processing()
|
||||
.unwrap();
|
||||
while let Some(header) = archive.read_header()? {
|
||||
println!(
|
||||
"{} bytes: {}",
|
||||
header.entry().unpacked_size,
|
||||
header.entry().filename.to_string_lossy(),
|
||||
);
|
||||
// Create the complete output path by combining the output_directory and the filename
|
||||
let output_path = output_directory.join(&header.entry().filename);
|
||||
|
||||
1
src/lib/lib.rs
Normal file
1
src/lib/lib.rs
Normal file
|
|
@ -0,0 +1 @@
|
|||
pub mod extractors;
|
||||
15
src/main.rs
15
src/main.rs
|
|
@ -1,19 +1,6 @@
|
|||
/*
|
||||
TODO_3: setup rayon to handle parallel file processsing when passed
|
||||
more than one file
|
||||
*/
|
||||
/*
|
||||
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 rayon::prelude::*;
|
||||
use extractors::{
|
||||
use sk_extract_lib::extractors::{
|
||||
extract_zip,
|
||||
extract_rar,
|
||||
extract_tar,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue