aboutsummaryrefslogtreecommitdiff
path: root/src/zip/error.rs
blob: 963daad3153796f1a073284a9c896b080c9999a0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
use crate::{ArchiveError, ArchiveResult};
use std::error::Error;
use std::fmt::Display;

pub type ZipResult<T> = ArchiveResult<T, ZipError>;

#[derive(Debug)]
pub enum ZipError {
    EOCDRNotFound,
    InvalidEOCDR64Signature,
    InvalidFileHeaderSignature,
    InvalidCDRSignature,

    InvalidArchiveComment,
    InvalidCompressionMethod,
    UnsupportedCompressionMethod,
    InvalidDate,
    InvalidTime,
    InvalidFileName,
    InvalidFileComment,

    NegativeFileOffset,
    FileNotFound,
    CompressedDataIsUnseekable,
}

impl From<ZipError> for ArchiveError<ZipError> {
    fn from(value: ZipError) -> Self {
        Self::Archivator {
            module: "Zip".to_string(),
            error: value,
        }
    }
}

impl Display for ZipError {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Self::EOCDRNotFound => write!(f, "End of central directory record not found"),
            Self::InvalidEOCDR64Signature => {
                write!(
                    f,
                    "Invalid signature of zip64 end of central directory record"
                )
            }
            Self::InvalidFileHeaderSignature => {
                write!(f, "Invalid file header signature")
            }
            Self::InvalidCDRSignature => {
                write!(f, "Invalid signature of central directory record")
            }

            Self::InvalidArchiveComment => write!(f, "Invalid archive comment"),
            Self::InvalidCompressionMethod => writeln!(f, "Invalid compression method"),
            Self::UnsupportedCompressionMethod => writeln!(f, "Unsupported compression method"),
            Self::InvalidDate => write!(f, "Invalid date"),
            Self::InvalidTime => write!(f, "Invalid time"),
            Self::InvalidFileName => write!(f, "Invalid file name"),
            Self::InvalidFileComment => write!(f, "Invalid file comment"),

            Self::NegativeFileOffset => write!(f, "Negative file offset"),
            Self::FileNotFound => write!(f, "File not found"),
            Self::CompressedDataIsUnseekable => write!(f, "Compressed data is unseekable"),
        }
    }
}

impl Error for ZipError {}