From 9003b81813ff171edfc6101868c226c5c7d1957c Mon Sep 17 00:00:00 2001 From: Igor Tolmachov Date: Fri, 8 Sep 2023 17:33:59 +0900 Subject: Add basic zip reader --- src/result.rs | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) (limited to 'src/result.rs') diff --git a/src/result.rs b/src/result.rs index 715f10c..9f35920 100644 --- a/src/result.rs +++ b/src/result.rs @@ -7,7 +7,12 @@ pub type ArchiveResult = Result; #[derive(Debug)] pub enum ArchiveError { IO(io::Error), - WrongSignature { expected: u32, received: u32 }, + BadArchive { reason: &'static str }, + IncorrectSignature { expected: u32, received: u32 }, + IncorrectString { location: &'static str }, + IncorrectDate { year: u16, month: u16, day: u16 }, + IncorrectTime { hour: u16, min: u16, sec: u16 }, + UnsupportedCompressionMethod { method: u16 }, } impl From for ArchiveError { @@ -20,12 +25,30 @@ impl Display for ArchiveError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { Self::IO(err) => write!(f, "{err}"), - Self::WrongSignature { expected, received } => { + Self::BadArchive { reason } => { + write!(f, "Bad archive because {reason}") + } + Self::IncorrectSignature { expected, received } => { + write!( + f, + "Wrong signature (expected: {expected}, received: {received})" + ) + } + Self::IncorrectString { location } => { + write!(f, "Incorrect string in {location}") + } + Self::IncorrectDate { year, month, day } => { write!( f, - "Wrong signature. Expected: {expected}, received: {received}" + "Incorrect date (year: {year}, month: {month}, day: {day})" ) } + Self::IncorrectTime { hour, min, sec } => { + write!(f, "Incorrect time (hour: {hour}, min: {min}, sec: {sec})") + } + Self::UnsupportedCompressionMethod { method } => { + write!(f, "Unsupported compression method (method: {method})") + } } } } -- cgit v1.2.3