diff options
| author | Igor Tolmachev <me@igorek.dev> | 2024-06-15 03:30:50 +0900 |
|---|---|---|
| committer | Igor Tolmachev <me@igorek.dev> | 2024-06-23 15:34:34 +0900 |
| commit | f8c3c93824645a807d28b760855b4676ea479720 (patch) | |
| tree | 1f91838c2abcb3b0683a061f892b8e2835be4fa1 /src/zip/error.rs | |
| parent | bd77f62e99a5300dfa52aef3a7040414b28ebfd6 (diff) | |
| download | archivator-f8c3c93824645a807d28b760855b4676ea479720.tar.gz archivator-f8c3c93824645a807d28b760855b4676ea479720.zip | |
Add simple zip reader
Diffstat (limited to 'src/zip/error.rs')
| -rw-r--r-- | src/zip/error.rs | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/src/zip/error.rs b/src/zip/error.rs new file mode 100644 index 0000000..ad1989a --- /dev/null +++ b/src/zip/error.rs | |||
| @@ -0,0 +1,58 @@ | |||
| 1 | use crate::{ArchiveError, ArchiveResult}; | ||
| 2 | use std::error::Error; | ||
| 3 | use std::fmt::Display; | ||
| 4 | |||
| 5 | pub type ZipResult<R> = ArchiveResult<R, ZipError>; | ||
| 6 | |||
| 7 | #[derive(Debug)] | ||
| 8 | pub enum ZipError { | ||
| 9 | EOCDRNotFound, | ||
| 10 | InvalidEOCDR, | ||
| 11 | InvalidArchiveComment, | ||
| 12 | |||
| 13 | InvalidEOCDR64Locator, | ||
| 14 | InvalidEOCDR64Signature, | ||
| 15 | InvalidEOCDR64, | ||
| 16 | |||
| 17 | InvalidCDRSignature, | ||
| 18 | InvalidCDR, | ||
| 19 | InvalidFileName, | ||
| 20 | InvalidFileComment, | ||
| 21 | } | ||
| 22 | |||
| 23 | impl From<ZipError> for ArchiveError<ZipError> { | ||
| 24 | fn from(value: ZipError) -> Self { | ||
| 25 | return ArchiveError::Driver { | ||
| 26 | name: "Zip", | ||
| 27 | error: value, | ||
| 28 | }; | ||
| 29 | } | ||
| 30 | } | ||
| 31 | |||
| 32 | impl Display for ZipError { | ||
| 33 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
| 34 | match self { | ||
| 35 | ZipError::EOCDRNotFound => write!(f, "End of central directory record not found"), | ||
| 36 | ZipError::InvalidEOCDR => write!(f, "Invalid end of central directory record"), | ||
| 37 | ZipError::InvalidArchiveComment => write!(f, "Invalid archive comment"), | ||
| 38 | ZipError::InvalidEOCDR64Locator => { | ||
| 39 | write!(f, "Invalid zip64 end of central directory locator") | ||
| 40 | } | ||
| 41 | ZipError::InvalidEOCDR64Signature => { | ||
| 42 | write!( | ||
| 43 | f, | ||
| 44 | "Invalid signature of zip64 end of central directory record" | ||
| 45 | ) | ||
| 46 | } | ||
| 47 | ZipError::InvalidEOCDR64 => write!(f, "Invalid zip64 end of central directory record"), | ||
| 48 | ZipError::InvalidCDRSignature => { | ||
| 49 | write!(f, "Invalid signature of central directory record") | ||
| 50 | } | ||
| 51 | ZipError::InvalidCDR => write!(f, "Invalid central directory record"), | ||
| 52 | ZipError::InvalidFileName => write!(f, "Invalid file name"), | ||
| 53 | ZipError::InvalidFileComment => write!(f, "Invalid file comment"), | ||
| 54 | } | ||
| 55 | } | ||
| 56 | } | ||
| 57 | |||
| 58 | impl Error for ZipError {} | ||
