Change name from Reader to FileDecompressed.

This commit is contained in:
2020-07-26 14:14:03 +02:00
parent a168030929
commit f8c94a3b61

View File

@@ -5,31 +5,31 @@ use std::path::Path;
use bzip2::read::BzDecoder;
use flate2::read::GzDecoder;
pub enum Reader {
pub enum FileDecompressed {
Raw(File),
Gz(GzDecoder<File>),
Bz(BzDecoder<File>),
}
impl Read for Reader {
impl Read for FileDecompressed {
fn read(&mut self, buf: &mut [u8]) -> std::io::Result<usize> {
match self {
Reader::Raw(file) => file.read(buf),
Reader::Gz(file) => file.read(buf),
Reader::Bz(file) => file.read(buf),
FileDecompressed::Raw(file) => file.read(buf),
FileDecompressed::Gz(file) => file.read(buf),
FileDecompressed::Bz(file) => file.read(buf),
}
}
}
pub fn open<P>(path: P) -> Result<Reader, std::io::Error>
pub fn open<P>(path: P) -> Result<FileDecompressed, std::io::Error>
where
P: AsRef<Path>,
{
let file = File::open(&path)?;
Ok(match mime_guess::from_path(path).first_raw() {
Some("application/x-gzip") => Reader::Gz(GzDecoder::new(file)),
Some("application/x-bzip2") => Reader::Bz(BzDecoder::new(file)),
_ => Reader::Raw(file),
Some("application/x-gzip") => FileDecompressed::Gz(GzDecoder::new(file)),
Some("application/x-bzip2") => FileDecompressed::Bz(BzDecoder::new(file)),
_ => FileDecompressed::Raw(file),
})
}