From f8c3c93824645a807d28b760855b4676ea479720 Mon Sep 17 00:00:00 2001 From: Igor Tolmachev Date: Sat, 15 Jun 2024 03:30:50 +0900 Subject: Add simple zip reader --- src/zip/error.rs | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 src/zip/error.rs (limited to 'src/zip/error.rs') 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 @@ +use crate::{ArchiveError, ArchiveResult}; +use std::error::Error; +use std::fmt::Display; + +pub type ZipResult = ArchiveResult; + +#[derive(Debug)] +pub enum ZipError { + EOCDRNotFound, + InvalidEOCDR, + InvalidArchiveComment, + + InvalidEOCDR64Locator, + InvalidEOCDR64Signature, + InvalidEOCDR64, + + InvalidCDRSignature, + InvalidCDR, + InvalidFileName, + InvalidFileComment, +} + +impl From for ArchiveError { + fn from(value: ZipError) -> Self { + return ArchiveError::Driver { + name: "Zip", + error: value, + }; + } +} + +impl Display for ZipError { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + ZipError::EOCDRNotFound => write!(f, "End of central directory record not found"), + ZipError::InvalidEOCDR => write!(f, "Invalid end of central directory record"), + ZipError::InvalidArchiveComment => write!(f, "Invalid archive comment"), + ZipError::InvalidEOCDR64Locator => { + write!(f, "Invalid zip64 end of central directory locator") + } + ZipError::InvalidEOCDR64Signature => { + write!( + f, + "Invalid signature of zip64 end of central directory record" + ) + } + ZipError::InvalidEOCDR64 => write!(f, "Invalid zip64 end of central directory record"), + ZipError::InvalidCDRSignature => { + write!(f, "Invalid signature of central directory record") + } + ZipError::InvalidCDR => write!(f, "Invalid central directory record"), + ZipError::InvalidFileName => write!(f, "Invalid file name"), + ZipError::InvalidFileComment => write!(f, "Invalid file comment"), + } + } +} + +impl Error for ZipError {} -- cgit v1.2.3