diff --git a/src/lib.rs b/src/lib.rs index 4a57860..568dee3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -26,6 +26,7 @@ pub mod read { }) } + #[inline] pub fn stream_len(&mut self) -> std::io::Result { 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 { let file = match self { Decoder::Raw(file) => file, @@ -94,6 +96,20 @@ pub mod bufread { }) } + pub fn with_capacity

(capacity: usize, path: P) -> Result + where + P: AsRef, + { + 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 { 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 { let file = match self { BufDecoder::Raw(file) => file,