Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use a consistent buffer size for downloads #5569

Merged
merged 1 commit into from
Jul 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions crates/uv-extract/src/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ use tracing::warn;

use crate::Error;

const DEFAULT_BUF_SIZE: usize = 128 * 1024;

/// Unzip a `.zip` archive into the target directory, without requiring `Seek`.
///
/// This is useful for unzipping files as they're being downloaded. If the archive
Expand All @@ -18,7 +20,7 @@ pub async fn unzip<R: tokio::io::AsyncRead + Unpin>(
target: impl AsRef<Path>,
) -> Result<(), Error> {
let target = target.as_ref();
let mut reader = futures::io::BufReader::with_capacity(128 * 1024, reader.compat());
let mut reader = futures::io::BufReader::with_capacity(DEFAULT_BUF_SIZE, reader.compat());
let mut zip = async_zip::base::read::stream::ZipFileReader::new(&mut reader);

let mut directories = FxHashSet::default();
Expand Down Expand Up @@ -155,7 +157,7 @@ pub async fn untar_gz<R: tokio::io::AsyncRead + Unpin>(
reader: R,
target: impl AsRef<Path>,
) -> Result<(), Error> {
let reader = tokio::io::BufReader::new(reader);
let reader = tokio::io::BufReader::with_capacity(DEFAULT_BUF_SIZE, reader);
let decompressed_bytes = async_compression::tokio::bufread::GzipDecoder::new(reader);

let mut archive = tokio_tar::ArchiveBuilder::new(decompressed_bytes)
Expand All @@ -172,7 +174,7 @@ pub async fn untar_bz2<R: tokio::io::AsyncRead + Unpin>(
reader: R,
target: impl AsRef<Path>,
) -> Result<(), Error> {
let reader = tokio::io::BufReader::new(reader);
let reader = tokio::io::BufReader::with_capacity(DEFAULT_BUF_SIZE, reader);
let decompressed_bytes = async_compression::tokio::bufread::BzDecoder::new(reader);

let mut archive = tokio_tar::ArchiveBuilder::new(decompressed_bytes)
Expand All @@ -189,7 +191,7 @@ pub async fn untar_zst<R: tokio::io::AsyncRead + Unpin>(
reader: R,
target: impl AsRef<Path>,
) -> Result<(), Error> {
let reader = tokio::io::BufReader::new(reader);
let reader = tokio::io::BufReader::with_capacity(DEFAULT_BUF_SIZE, reader);
let decompressed_bytes = async_compression::tokio::bufread::ZstdDecoder::new(reader);

let mut archive = tokio_tar::ArchiveBuilder::new(decompressed_bytes)
Expand All @@ -205,7 +207,7 @@ pub async fn untar_xz<R: tokio::io::AsyncRead + Unpin>(
reader: R,
target: impl AsRef<Path>,
) -> Result<(), Error> {
let reader = tokio::io::BufReader::new(reader);
let reader = tokio::io::BufReader::with_capacity(DEFAULT_BUF_SIZE, reader);
let decompressed_bytes = async_compression::tokio::bufread::XzDecoder::new(reader);

let mut archive = tokio_tar::ArchiveBuilder::new(decompressed_bytes)
Expand Down
Loading