Added with_capacity for BufDecoder.
This commit is contained in:
17
src/lib.rs
17
src/lib.rs
@@ -26,6 +26,7 @@ pub mod read {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
pub fn stream_len(&mut self) -> std::io::Result<u64> {
|
pub fn stream_len(&mut self) -> std::io::Result<u64> {
|
||||||
let file = match self {
|
let file = match self {
|
||||||
Decoder::Raw(file) => file,
|
Decoder::Raw(file) => file,
|
||||||
@@ -43,6 +44,7 @@ pub mod read {
|
|||||||
Ok(len)
|
Ok(len)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
pub fn stream_position(&mut self) -> std::io::Result<u64> {
|
pub fn stream_position(&mut self) -> std::io::Result<u64> {
|
||||||
let file = match self {
|
let file = match self {
|
||||||
Decoder::Raw(file) => file,
|
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> {
|
pub fn stream_len(&mut self) -> std::io::Result<u64> {
|
||||||
let file = match self {
|
let file = match self {
|
||||||
BufDecoder::Raw(file) => file,
|
BufDecoder::Raw(file) => file,
|
||||||
@@ -111,6 +127,7 @@ pub mod bufread {
|
|||||||
Ok(len)
|
Ok(len)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
pub fn stream_position(&mut self) -> std::io::Result<u64> {
|
pub fn stream_position(&mut self) -> std::io::Result<u64> {
|
||||||
let file = match self {
|
let file = match self {
|
||||||
BufDecoder::Raw(file) => file,
|
BufDecoder::Raw(file) => file,
|
||||||
|
|||||||
Reference in New Issue
Block a user