diff options
| author | Igor Tolmachev <me@igorek.dev> | 2024-06-16 21:36:13 +0900 |
|---|---|---|
| committer | Igor Tolmachev <me@igorek.dev> | 2024-06-23 15:34:34 +0900 |
| commit | d6055b5ac4f3ff5016bc4881cf1cc109a22c40ba (patch) | |
| tree | 40a9044f923945e6effc13c627261630dddc574c /src/zip | |
| parent | 6444bee8f3e188be014841ea8cd7cfb53eb03ed9 (diff) | |
| download | archivator-d6055b5ac4f3ff5016bc4881cf1cc109a22c40ba.tar.gz archivator-d6055b5ac4f3ff5016bc4881cf1cc109a22c40ba.zip | |
Implement serialize
Diffstat (limited to 'src/zip')
| -rw-r--r-- | src/zip/driver.rs | 4 | ||||
| -rw-r--r-- | src/zip/error.rs | 8 | ||||
| -rw-r--r-- | src/zip/mod.rs | 1 |
3 files changed, 7 insertions, 6 deletions
diff --git a/src/zip/driver.rs b/src/zip/driver.rs index 313bf8d..d575509 100644 --- a/src/zip/driver.rs +++ b/src/zip/driver.rs | |||
| @@ -4,7 +4,7 @@ use crate::zip::structs::{EOCDR64Locator, CDR, EOCDR, EOCDR64}; | |||
| 4 | use crate::zip::ZipFile; | 4 | use crate::zip::ZipFile; |
| 5 | use std::collections::HashMap as Map; | 5 | use std::collections::HashMap as Map; |
| 6 | use std::fs::File; | 6 | use std::fs::File; |
| 7 | use std::io::{Cursor, Read, Seek, SeekFrom, Write}; | 7 | use std::io::{Read, Seek, SeekFrom, Write}; |
| 8 | 8 | ||
| 9 | pub struct Zip<IO = File> { | 9 | pub struct Zip<IO = File> { |
| 10 | io: IO, | 10 | io: IO, |
| @@ -43,7 +43,7 @@ impl<IO: Read + Seek> ArchiveRead for Zip<IO> { | |||
| 43 | }; | 43 | }; |
| 44 | let eocdr: EOCDR = bincode::deserialize(&buf).map_err(|_| ZipError::InvalidEOCDR)?; | 44 | let eocdr: EOCDR = bincode::deserialize(&buf).map_err(|_| ZipError::InvalidEOCDR)?; |
| 45 | let comment = { | 45 | let comment = { |
| 46 | let mut buf = vec![0; eocdr.comment_len as usize]; | 46 | let mut buf: Vec<u8> = vec![0; eocdr.comment_len as usize]; |
| 47 | io.read(&mut buf)?; | 47 | io.read(&mut buf)?; |
| 48 | String::from_utf8(buf).map_err(|_| ZipError::InvalidArchiveComment)? | 48 | String::from_utf8(buf).map_err(|_| ZipError::InvalidArchiveComment)? |
| 49 | }; | 49 | }; |
diff --git a/src/zip/error.rs b/src/zip/error.rs index ad1989a..18bbb22 100644 --- a/src/zip/error.rs +++ b/src/zip/error.rs | |||
| @@ -2,7 +2,7 @@ use crate::{ArchiveError, ArchiveResult}; | |||
| 2 | use std::error::Error; | 2 | use std::error::Error; |
| 3 | use std::fmt::Display; | 3 | use std::fmt::Display; |
| 4 | 4 | ||
| 5 | pub type ZipResult<R> = ArchiveResult<R, ZipError>; | 5 | pub type ZipResult<T> = ArchiveResult<T, ZipError>; |
| 6 | 6 | ||
| 7 | #[derive(Debug)] | 7 | #[derive(Debug)] |
| 8 | pub enum ZipError { | 8 | pub enum ZipError { |
| @@ -22,10 +22,10 @@ pub enum ZipError { | |||
| 22 | 22 | ||
| 23 | impl From<ZipError> for ArchiveError<ZipError> { | 23 | impl From<ZipError> for ArchiveError<ZipError> { |
| 24 | fn from(value: ZipError) -> Self { | 24 | fn from(value: ZipError) -> Self { |
| 25 | return ArchiveError::Driver { | 25 | Self::Archivator { |
| 26 | name: "Zip", | 26 | module: "Zip".to_string(), |
| 27 | error: value, | 27 | error: value, |
| 28 | }; | 28 | } |
| 29 | } | 29 | } |
| 30 | } | 30 | } |
| 31 | 31 | ||
diff --git a/src/zip/mod.rs b/src/zip/mod.rs index 612a946..5aeca97 100644 --- a/src/zip/mod.rs +++ b/src/zip/mod.rs | |||
| @@ -4,4 +4,5 @@ mod file; | |||
| 4 | mod structs; | 4 | mod structs; |
| 5 | 5 | ||
| 6 | pub use driver::Zip; | 6 | pub use driver::Zip; |
| 7 | pub use error::ZipError; | ||
| 7 | pub use file::ZipFile; | 8 | pub use file::ZipFile; |
