use std::io;
pub type Result<T> = std::result::Result<T, SZipError>;
#[derive(Debug)]
pub enum SZipError {
Io(io::Error),
InvalidFormat(String),
EntryNotFound(String),
UnsupportedCompression(u16),
#[cfg(feature = "encryption")]
EncryptionError(String),
#[cfg(feature = "encryption")]
IncorrectPassword,
}
impl std::fmt::Display for SZipError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
SZipError::Io(e) => write!(f, "I/O error: {}", e),
SZipError::InvalidFormat(msg) => write!(f, "Invalid ZIP format: {}", msg),
SZipError::EntryNotFound(name) => write!(f, "Entry not found: {}", name),
SZipError::UnsupportedCompression(method) => {
write!(f, "Unsupported compression method: {}", method)
}
#[cfg(feature = "encryption")]
SZipError::EncryptionError(msg) => write!(f, "Encryption error: {}", msg),
#[cfg(feature = "encryption")]
SZipError::IncorrectPassword => write!(f, "Incorrect password"),
}
}
}
impl std::error::Error for SZipError {}
impl From<io::Error> for SZipError {
fn from(err: io::Error) -> Self {
SZipError::Io(err)
}
}