use crate::{ArchiveError, ArchiveResult}; use std::error::Error; use std::fmt::Display; pub type ZipResult = ArchiveResult; #[derive(Debug)] pub enum ZipError { EOCDRNotFound, InvalidEOCDR64Signature, InvalidCDRSignature, InvalidArchiveComment, InvalidCompressionMethod, UnsupportedCompressionMethod, InvalidDate, InvalidTime, InvalidFileName, InvalidFileComment, } 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::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"), } } } impl Error for ZipError {}