Set buffer size when unzipping (#1101)

The zip archive includes an uncompressed size header, which we can use
to preallocate.
This commit is contained in:
Charlie Marsh 2024-01-25 09:58:36 -08:00 committed by GitHub
parent e0902d7d5a
commit 3e86c80874
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 3 additions and 1 deletions

View File

@ -50,7 +50,9 @@ pub async fn unzip_no_seek<R: tokio::io::AsyncRead + Unpin>(
fs_err::tokio::create_dir_all(parent).await?;
}
let file = fs_err::tokio::File::create(path).await?;
let mut writer = tokio::io::BufWriter::new(file);
let size =
usize::try_from(entry.reader().entry().uncompressed_size()).unwrap_or(usize::MAX);
let mut writer = tokio::io::BufWriter::with_capacity(size, file);
let mut reader = entry.reader_mut().compat();
tokio::io::copy(&mut reader, &mut writer).await?;
}