use crate::{ArchiveError, ArchiveResult}; use std::error::Error; use std::fmt::Display; pub type ZipResult = ArchiveResult; #[derive(Debug, PartialEq, Eq)] pub enum ZipError { EocdrNotFound, InvalidEOCDR64Signature, InvalidFileHeaderSignature, InvalidCDRSignature, InvalidCompressionMethod(u16), UnsupportedCompressionMethod(u16), UnsupportedEncryptionMethod, InvalidDate, InvalidTime, InvalidFileName, InvalidFileComment, FileNotFound, IncorrectPassword, PasswordIsNotSpecified, CompressedDataIsUnseekable, EncryptedDataIsUnseekable, } impl From for ArchiveError { 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::InvalidCompressionMethod(id) => { writeln!(f, "Invalid compression method {}", id) } Self::UnsupportedCompressionMethod(id) => { writeln!(f, "Unsupported compression method {}", id) } Self::UnsupportedEncryptionMethod => { writeln!(f, "Unsupported encryption 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::FileNotFound => write!(f, "File not found"), Self::IncorrectPassword => write!(f, "Incorrect password"), Self::PasswordIsNotSpecified => write!(f, "Password is not specified"), Self::CompressedDataIsUnseekable => write!(f, "Compressed data is unseekable"), Self::EncryptedDataIsUnseekable => write!(f, "Encrypted data is unseekable"), } } } impl Error for ZipError {}