From db4cebed2cfc3a5830c878c5e3846651a85212b6 Mon Sep 17 00:00:00 2001 From: Leonard Lesinski <84378319+Le0X8@users.noreply.github.com> Date: Sat, 3 Aug 2024 00:28:53 +0200 Subject: [PATCH] chore: Added RAR to project structure --- src/archive.rs | 52 ++++++++++++++++++++++++--------------- src/formats.rs | 4 +++ src/formats/rar.rs | 1 + src/formats/rar/parser.rs | 0 4 files changed, 37 insertions(+), 20 deletions(-) create mode 100644 src/formats/rar.rs create mode 100644 src/formats/rar/parser.rs diff --git a/src/archive.rs b/src/archive.rs index acbc711..91df320 100644 --- a/src/archive.rs +++ b/src/archive.rs @@ -40,6 +40,7 @@ pub fn metadata<'a>( } OriginalArchiveMetadata::Zip(metadata) } + Formats::Rar => todo!(), }; Ok(Box::new(metadata)) @@ -72,6 +73,7 @@ pub fn extract( } &metadata.clone() as &dyn ArchiveMetadata } + Formats::Rar => todo!(), }; let files = metadata.get_files(); @@ -84,34 +86,43 @@ pub fn extract( format!("{}/{}", &output, &path) }); } + Formats::Rar => todo!(), } } else if index.is_some() { let index = index.unwrap(); if index >= files.len() as u32 { return Err("Index out of range".to_string()); } - formats::zip::parser::extract( - &mut file, - &formats::zip::to_zip_entries(files), - &buffer_size, - &|path| format!("{}/{}", &output, &path), - ); + match format { + Formats::Zip => formats::zip::parser::extract( + &mut file, + &formats::zip::to_zip_entries(files), + &buffer_size, + &|path| format!("{}/{}", &output, &path), + ), + Formats::Rar => todo!(), + }; } else { let path = path.unwrap(); - let files: Vec = metadata - .get_files() - .iter() - .filter_map(|file| { - if file.get_path().starts_with(&path) { - Some(formats::zip::to_zip_entry(*file)) - } else { - None - } - }) - .collect(); - formats::zip::parser::extract(&mut file, &files, &buffer_size, &|path| { - format!("{}/{}", &output, &path) - }); + match format { + Formats::Zip => { + let files: Vec = metadata + .get_files() + .iter() + .filter_map(|file| { + if file.get_path().starts_with(&path) { + Some(formats::zip::to_zip_entry(*file)) + } else { + None + } + }) + .collect(); + formats::zip::parser::extract(&mut file, &files, &buffer_size, &|path| { + format!("{}/{}", &output, &path) + }); + } + Formats::Rar => todo!(), + } }; Ok(()) @@ -175,6 +186,7 @@ pub fn create( &buffer_size, ); } + _ => return Err("Format not supported for archive creation.".to_string()), } Ok(()) diff --git a/src/formats.rs b/src/formats.rs index ce14a5f..b4c8e44 100644 --- a/src/formats.rs +++ b/src/formats.rs @@ -1,9 +1,11 @@ use crate::archive::ArchiveMetadata; +pub mod rar; pub mod zip; pub enum Formats { Zip, + Rar, } pub fn from_string(format: &str) -> Formats { @@ -16,6 +18,7 @@ pub fn from_string(format: &str) -> Formats { pub fn to_string(format: &Formats) -> String { match format { Formats::Zip => "zip".to_string(), + Formats::Rar => "rar".to_string(), } } @@ -29,5 +32,6 @@ pub fn to_format_metadata<'a>( ) -> FormatMetadata<'a> { match format { Formats::Zip => FormatMetadata::Zip(zip::to_zip_archive_metadata(metadata)), + Formats::Rar => todo!(), } } diff --git a/src/formats/rar.rs b/src/formats/rar.rs new file mode 100644 index 0000000..67c567f --- /dev/null +++ b/src/formats/rar.rs @@ -0,0 +1 @@ +pub mod parser; diff --git a/src/formats/rar/parser.rs b/src/formats/rar/parser.rs new file mode 100644 index 0000000..e69de29