Skip to content

Configure FileStreamOptions with PreallocationSize and async access in ZipArchiveEntry extract methods#125260

Merged
rzikm merged 5 commits intodotnet:mainfrom
rzikm:ziparchiveentry-extracttofile-options-98cb
Mar 19, 2026
Merged

Configure FileStreamOptions with PreallocationSize and async access in ZipArchiveEntry extract methods#125260
rzikm merged 5 commits intodotnet:mainfrom
rzikm:ziparchiveentry-extracttofile-options-98cb

Conversation

@rzikm
Copy link
Member

@rzikm rzikm commented Mar 6, 2026

Set PreallocationSize on FileStreamOptions based on the entry's uncompressed size (ZipArchiveEntry.Length) to allow the file system to pre-allocate disk space, reducing fragmentation and improving write performance.

Configure FileOptions.Asynchronous when extracting from async methods (ExtractToFileAsync) so the FileStream uses async I/O.

Copilot AI review requested due to automatic review settings March 6, 2026 08:44
@rzikm rzikm requested a review from a team March 6, 2026 08:48
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Improves ZipArchiveEntry extraction performance/behavior by configuring FileStreamOptions to (1) preallocate disk space based on the entry’s uncompressed size and (2) enable async file I/O when extracting via async APIs.

Changes:

  • Set FileStreamOptions.PreallocationSize from ZipArchiveEntry.Length during extraction initialization.
  • Thread an async flag into the shared initialization helper to set FileOptions.Asynchronous for ExtractToFileAsync.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
src/libraries/System.IO.Compression.ZipFile/src/System/IO/Compression/ZipFileExtensions.ZipArchiveEntry.Extract.cs Adds preallocation and async/sync option selection to the shared file-creation options.
src/libraries/System.IO.Compression.ZipFile/src/System/IO/Compression/ZipFileExtensions.ZipArchiveEntry.Extract.Async.cs Passes the async flag so extracted file streams use async I/O.

You can also share your feedback on Copilot code review. Take the survey.

…n ZipArchiveEntry extract methods

Set PreallocationSize based on the entry's uncompressed size to allow the
file system to pre-allocate disk space, reducing fragmentation and improving
write performance.

Configure FileOptions.Asynchronous when extracting from async methods so
that the FileStream uses async I/O.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@rzikm rzikm force-pushed the ziparchiveentry-extracttofile-options-98cb branch from 1d2f2aa to 3c51c56 Compare March 6, 2026 09:14
ZipArchiveEntry.Length throws InvalidOperationException when the entry
has been opened for writing (e.g. in Update mode). Read it in a
try/catch and fall back to 0 (no preallocation) to avoid regressing
that scenario.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings March 6, 2026 10:49
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.


You can also share your feedback on Copilot code review. Take the survey.

Copilot AI review requested due to automatic review settings March 16, 2026 08:45
@rzikm rzikm requested review from iremyux and stephentoub March 16, 2026 08:50
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.


You can also share your feedback on Copilot code review. Take the survey.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings March 18, 2026 11:01
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.


You can also share your feedback on Copilot code review. Take the survey.

@rzikm rzikm requested a review from alinpahontu2912 March 18, 2026 13:19
@iremyux
Copy link
Contributor

iremyux commented Mar 19, 2026

I see that we do not have new tests for the new behavior - is it intentional?

Copy link
Contributor

@iremyux iremyux left a comment

Choose a reason for hiding this comment

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

LGTM

@rzikm
Copy link
Member Author

rzikm commented Mar 19, 2026

There is no way to functionally test the new behavior.

@rzikm rzikm merged commit 34dd74d into dotnet:main Mar 19, 2026
91 of 94 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants