Skip to content
Merged
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,27 @@ private static void ExtractToFileInitialize(ZipArchiveEntry source, string desti
ArgumentNullException.ThrowIfNull(source);
ArgumentNullException.ThrowIfNull(destinationFileName);

long preallocationSize = 0;
try
{
// .Length can throw if the entry stream has been opened for write.
// For archives in Update mode, we have no way to check if the entry
// was opened for write, so we attempt to get the length and if it fails
// we just skip preallocation.
if (source.Archive is ZipArchive archive && archive.Mode != ZipArchiveMode.Create)
{
preallocationSize = source.Length;
}
}
catch (InvalidOperationException) { }
Comment thread
rzikm marked this conversation as resolved.
Comment thread
rzikm marked this conversation as resolved.

fileStreamOptions = new()
{
Access = FileAccess.Write,
Mode = overwrite ? FileMode.Create : FileMode.CreateNew,
Share = FileShare.None,
BufferSize = ZipFile.FileStreamBufferSize,
PreallocationSize = preallocationSize,
Comment thread
rzikm marked this conversation as resolved.
Comment thread
rzikm marked this conversation as resolved.
Comment thread
rzikm marked this conversation as resolved.
Options = useAsync ? FileOptions.Asynchronous : FileOptions.None
Comment thread
rzikm marked this conversation as resolved.
};
Comment thread
rzikm marked this conversation as resolved.

Expand Down
Loading