Skip to content

Commit

Permalink
Skip copying to empty entries in seekable zip (#5571)
Browse files Browse the repository at this point in the history
## Summary

We cannot do this when streaming, since we may not have the metadata for
the entry.

Closes #5565.
  • Loading branch information
charliermarsh committed Jul 29, 2024
1 parent f70501a commit cf94a10
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions crates/uv-extract/src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,14 @@ pub fn unzip<R: Send + std::io::Read + std::io::Seek + HasLength>(
// Copy the file contents.
let outfile = fs_err::File::create(&path)?;
let size = file.size();
let mut writer = if let Ok(size) = usize::try_from(size) {
std::io::BufWriter::with_capacity(std::cmp::min(size, 1024 * 1024), outfile)
} else {
std::io::BufWriter::new(outfile)
};
std::io::copy(&mut file, &mut writer)?;
if size > 0 {
let mut writer = if let Ok(size) = usize::try_from(size) {
std::io::BufWriter::with_capacity(std::cmp::min(size, 1024 * 1024), outfile)
} else {
std::io::BufWriter::new(outfile)
};
std::io::copy(&mut file, &mut writer)?;
}

// See `uv_extract::stream::unzip`. For simplicity, this is identical with the code there except for being
// sync.
Expand Down

0 comments on commit cf94a10

Please sign in to comment.