mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-04-21 04:58:42 +00:00
Use BufRead
inextract_compressed_from_readable
Use `BufRead` instead of `Read` to avoid copying of data and improve efficiency. `GzDecoder` and `XzDecoder` both have their `BufRead` counterpart in mod `bufread` and their `read` counterpart merely wraps the input in a `std::io::BufReader`. `ZstdDecoder::new` also wraps it in a `BufReader` and pass it to `ZstdDecoder::with_buffer`. Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
parent
e753c9ec30
commit
4a882dc2cb
1 changed files with 5 additions and 5 deletions
|
@ -1,11 +1,11 @@
|
||||||
use std::fs::{self, File};
|
use std::fs::{self, File};
|
||||||
use std::io::Read;
|
use std::io::{BufRead, Read};
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
use flate2::read::GzDecoder;
|
use flate2::bufread::GzDecoder;
|
||||||
use log::debug;
|
use log::debug;
|
||||||
use tar::Archive;
|
use tar::Archive;
|
||||||
use xz2::read::XzDecoder;
|
use xz2::bufread::XzDecoder;
|
||||||
use zip::read::ZipArchive;
|
use zip::read::ZipArchive;
|
||||||
use zstd::stream::Decoder as ZstdDecoder;
|
use zstd::stream::Decoder as ZstdDecoder;
|
||||||
|
|
||||||
|
@ -55,7 +55,7 @@ fn untar<Filter: FnMut(&Path) -> bool>(
|
||||||
/// Note that this is a best-effort and it only works when `fmt`
|
/// Note that this is a best-effort and it only works when `fmt`
|
||||||
/// is not `PkgFmt::Bin` or `PkgFmt::Zip`.
|
/// is not `PkgFmt::Bin` or `PkgFmt::Zip`.
|
||||||
pub(crate) fn extract_compressed_from_readable<Filter: FnMut(&Path) -> bool>(
|
pub(crate) fn extract_compressed_from_readable<Filter: FnMut(&Path) -> bool>(
|
||||||
dat: impl Read,
|
dat: impl BufRead,
|
||||||
fmt: PkgFmt,
|
fmt: PkgFmt,
|
||||||
path: &Path,
|
path: &Path,
|
||||||
filter: Option<Filter>,
|
filter: Option<Filter>,
|
||||||
|
@ -89,7 +89,7 @@ pub(crate) fn extract_compressed_from_readable<Filter: FnMut(&Path) -> bool>(
|
||||||
// as of zstd 0.10.2 and 0.11.2, which is specified
|
// as of zstd 0.10.2 and 0.11.2, which is specified
|
||||||
// as &[] by ZstdDecoder::new, thus ZstdDecoder::new
|
// as &[] by ZstdDecoder::new, thus ZstdDecoder::new
|
||||||
// should not return any error.
|
// should not return any error.
|
||||||
let tar = ZstdDecoder::new(dat)?;
|
let tar = ZstdDecoder::with_buffer(dat)?;
|
||||||
untar(tar, path, filter)?;
|
untar(tar, path, filter)?;
|
||||||
}
|
}
|
||||||
PkgFmt::Zip => panic!("Unexpected PkgFmt::Zip!"),
|
PkgFmt::Zip => panic!("Unexpected PkgFmt::Zip!"),
|
||||||
|
|
Loading…
Add table
Reference in a new issue