| 1 |
use std::error::Error as StdError; |
| 2 |
use std::fmt::{self, Display, Formatter}; |
| 3 |
use std::io; |
| 4 |
|
| 5 |
/// An error returned by [`Header`] |
| 6 |
/// |
| 7 |
/// [`Header`]: crate::header::Header |
| 8 |
#[derive(Debug, Clone, PartialEq)] |
| 9 |
pub enum HeaderError { |
| 10 |
/// The file signature isn't valid (should be `BZ`) |
| 11 |
InvalidSignature, |
| 12 |
/// The bzip2 version isn't supported (only the huffman version is supported) |
| 13 |
UnsupportedVersion, |
| 14 |
/// The blocksize isn't `1..=9` |
| 15 |
InvalidBlockSize, |
| 16 |
} |
| 17 |
|
| 18 |
impl Display for HeaderError { |
| 19 |
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { |
| 20 |
f.write_str(match self { |
| 21 |
HeaderError::InvalidSignature => "invalid file signature", |
| 22 |
HeaderError::UnsupportedVersion => "unsupported bzip2 version", |
| 23 |
HeaderError::InvalidBlockSize => "invalid block-size", |
| 24 |
}) |
| 25 |
} |
| 26 |
} |
| 27 |
|
| 28 |
impl StdError for HeaderError {} |
| 29 |
|
| 30 |
impl From<HeaderError> for io::Error { |
| 31 |
fn from(err: HeaderError) -> io::Error { |
| 32 |
io::Error::new(io::ErrorKind::InvalidData, err) |
| 33 |
} |
| 34 |
} |