Skip to content

Commit

Permalink
chore: Added RAR to project structure
Browse files Browse the repository at this point in the history
  • Loading branch information
Le0X8 committed Aug 2, 2024
1 parent 724fc97 commit db4cebe
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 20 deletions.
52 changes: 32 additions & 20 deletions src/archive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ pub fn metadata<'a>(
}
OriginalArchiveMetadata::Zip(metadata)
}
Formats::Rar => todo!(),
};

Ok(Box::new(metadata))
Expand Down Expand Up @@ -72,6 +73,7 @@ pub fn extract(
}
&metadata.clone() as &dyn ArchiveMetadata
}
Formats::Rar => todo!(),
};

let files = metadata.get_files();
Expand All @@ -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<ZipFileEntry> = 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<ZipFileEntry> = 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(())
Expand Down Expand Up @@ -175,6 +186,7 @@ pub fn create(
&buffer_size,
);
}
_ => return Err("Format not supported for archive creation.".to_string()),
}

Ok(())
Expand Down
4 changes: 4 additions & 0 deletions src/formats.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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(),
}
}

Expand All @@ -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!(),
}
}
1 change: 1 addition & 0 deletions src/formats/rar.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod parser;
Empty file added src/formats/rar/parser.rs
Empty file.

0 comments on commit db4cebe

Please sign in to comment.