Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,20 @@ private static void ExtractToFileInitialize(ZipArchiveEntry source, string desti
ArgumentNullException.ThrowIfNull(source);
ArgumentNullException.ThrowIfNull(destinationFileName);

long preallocationSize = 0;
try
{
preallocationSize = source.Length;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the try/catch because the stream may not be seekable? It should instead check CanSeek

}
catch (InvalidOperationException) { }
Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The empty catch (InvalidOperationException) { } makes it unclear why ZipArchiveEntry.Length is expected to fail here and why it’s safe to ignore. Please add a short comment explaining the specific scenario(s) (e.g., entry not readable / length not available) and that preallocation is best-effort, so future changes don’t accidentally rely on preallocationSize being accurate.

Suggested change
catch (InvalidOperationException) { }
catch (InvalidOperationException)
{
// Length can throw if the entry is not readable or its size is not yet available (for example,
// when the archive is in a mode that does not expose the entry length). In that case we skip
// preallocation and leave preallocationSize as 0. This is a best-effort optimization only and
// callers must not rely on PreallocationSize matching the final file size.
}

Copilot uses AI. Check for mistakes.

fileStreamOptions = new()
{
Access = FileAccess.Write,
Mode = overwrite ? FileMode.Create : FileMode.CreateNew,
Share = FileShare.None,
BufferSize = ZipFile.FileStreamBufferSize,
PreallocationSize = preallocationSize,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you measure any impact from this?

Options = useAsync ? FileOptions.Asynchronous : FileOptions.None
};

Expand Down
Loading