aboutsummaryrefslogtreecommitdiff
path: root/src/zip/error.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/zip/error.rs')
-rw-r--r--src/zip/error.rs58
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 @@
1use crate::{ArchiveError, ArchiveResult};
2use std::error::Error;
3use std::fmt::Display;
4
5pub type ZipResult<R> = ArchiveResult<R, ZipError>;
6
7#[derive(Debug)]
8pub 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
23impl 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
32impl 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
58impl Error for ZipError {}