evtc_parse/
zip.rs

1use crate::{Log, Parse, ParseError};
2use std::io;
3use zip::{result::ZipError, ZipArchive};
4
5/// Parses a [`Log`] from a compressed `zevtc` input.
6pub fn parse_zevtc(input: impl io::Read + io::Seek) -> Result<Log, ParseError> {
7    Log::parse_zevtc(input)
8}
9
10impl Log {
11    /// Parses a [`Log`] from a compressed `zevtc` input.
12    pub fn parse_zevtc(input: impl io::Read + io::Seek) -> Result<Log, ParseError> {
13        let mut archive = ZipArchive::new(input).expect("input log file not compressed");
14        let mut file = archive.by_index(0).expect("input log file empty");
15        Log::parse(&mut file)
16    }
17}
18
19impl From<ZipError> for ParseError {
20    fn from(err: ZipError) -> Self {
21        match err {
22            ZipError::Io(io) => Self::IoError(io),
23            _ => Self::NotEvtc,
24        }
25    }
26}