-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reduce memory usage when updating ZipArchives (#102704)
* Changed behaviour of WriteFile WriteFile now takes a more granular approach to writing the ZipArchive to its stream. Adding a new file to the end of the archive will no longer require every file in the archive to be loaded into memory. Changing fixed-length metadata inside a file will no longer require the entire archive to be re-written. * Added tests for changed WriteFile behaviour * Changes following code review Renamed Dirty and DirtyState to Changed and ChangeState. Explicitly assigned Unchanged as a zero-value ChangeState. * Changed field protection levels Reset _originallyInArchive and _offsetOfLocalHeader to private members, exposed as internal properties. Also changed _versionToExtract to be private - this isn't ever used in System.IO.Compression outside of ZipArchiveEntry. * Following code review feedback * Used named parameter when passing a constant to forceWrite. * Replaced two magic numbers with constants. * Small cleanup of ZipArchive.WriteFile for clarity. * Renamed ZipArchiveEntry.Changed to Changes. * Further code review: initial response * Further code review comments The list of entries in a ZipArchive is now only sorted when opened in Update mode. Added/modified a test to verify that these entries appear in the correct order: offset order when opened in Update mode, central directory entry order when opened in Read mode. * Correct the write counts in tests This accounts for the removal of BinaryReader in an earlier PR * Extra test: Update_PerformMinimalWritesWhenEntriesModifiedAndAdded This test modifies an entry at a specific index, adds N entries after it, then verifies that they've been written in the expected order: existing entries first, new entries afterwards --------- Co-authored-by: Carlos Sánchez López <1175054+carlossanlop@users.noreply.github.com>
- Loading branch information
1 parent
d917005
commit 0a477a8
Showing
8 changed files
with
883 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.