Added with_capacity for BufDecoder.

This commit is contained in:
2020-09-08 21:36:40 +02:00
parent b1aec7e18b
commit 34352db18f

View File

@@ -26,6 +26,7 @@ pub mod read {
})
}
#[inline]
pub fn stream_len(&mut self) -> std::io::Result<u64> {
let file = match self {
Decoder::Raw(file) => file,
@@ -43,6 +44,7 @@ pub mod read {
Ok(len)
}
#[inline]
pub fn stream_position(&mut self) -> std::io::Result<u64> {
let file = match self {
Decoder::Raw(file) => file,
@@ -94,6 +96,20 @@ pub mod bufread {
})
}
pub fn with_capacity<P>(capacity: usize, path: P) -> Result<BufDecoder, std::io::Error>
where
P: AsRef<Path>,
{
let file = File::open(&path).map(|file| BufReader::with_capacity(capacity, file))?;
Ok(match mime_guess::from_path(path).first_raw() {
Some("application/x-gzip") => BufDecoder::Gz(GzDecoder::new(file)),
Some("application/x-bzip2") => BufDecoder::Bz(BzDecoder::new(file)),
_ => BufDecoder::Raw(file),
})
}
#[inline]
pub fn stream_len(&mut self) -> std::io::Result<u64> {
let file = match self {
BufDecoder::Raw(file) => file,
@@ -111,6 +127,7 @@ pub mod bufread {
Ok(len)
}
#[inline]
pub fn stream_position(&mut self) -> std::io::Result<u64> {
let file = match self {
BufDecoder::Raw(file) => file,