Change name from Reader to FileDecompressed.
This commit is contained in:
18
src/lib.rs
18
src/lib.rs
@@ -5,31 +5,31 @@ use std::path::Path;
|
|||||||
use bzip2::read::BzDecoder;
|
use bzip2::read::BzDecoder;
|
||||||
use flate2::read::GzDecoder;
|
use flate2::read::GzDecoder;
|
||||||
|
|
||||||
pub enum Reader {
|
pub enum FileDecompressed {
|
||||||
Raw(File),
|
Raw(File),
|
||||||
Gz(GzDecoder<File>),
|
Gz(GzDecoder<File>),
|
||||||
Bz(BzDecoder<File>),
|
Bz(BzDecoder<File>),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Read for Reader {
|
impl Read for FileDecompressed {
|
||||||
fn read(&mut self, buf: &mut [u8]) -> std::io::Result<usize> {
|
fn read(&mut self, buf: &mut [u8]) -> std::io::Result<usize> {
|
||||||
match self {
|
match self {
|
||||||
Reader::Raw(file) => file.read(buf),
|
FileDecompressed::Raw(file) => file.read(buf),
|
||||||
Reader::Gz(file) => file.read(buf),
|
FileDecompressed::Gz(file) => file.read(buf),
|
||||||
Reader::Bz(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
|
where
|
||||||
P: AsRef<Path>,
|
P: AsRef<Path>,
|
||||||
{
|
{
|
||||||
let file = File::open(&path)?;
|
let file = File::open(&path)?;
|
||||||
|
|
||||||
Ok(match mime_guess::from_path(path).first_raw() {
|
Ok(match mime_guess::from_path(path).first_raw() {
|
||||||
Some("application/x-gzip") => Reader::Gz(GzDecoder::new(file)),
|
Some("application/x-gzip") => FileDecompressed::Gz(GzDecoder::new(file)),
|
||||||
Some("application/x-bzip2") => Reader::Bz(BzDecoder::new(file)),
|
Some("application/x-bzip2") => FileDecompressed::Bz(BzDecoder::new(file)),
|
||||||
_ => Reader::Raw(file),
|
_ => FileDecompressed::Raw(file),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user