-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Configure FileStreamOptions with PreallocationSize and async access in ZipArchiveEntry extract methods #125260
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -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; | ||||||||||||||||||
| } | ||||||||||||||||||
| catch (InvalidOperationException) { } | ||||||||||||||||||
|
||||||||||||||||||
| 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. | |
| } |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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