Description
If a ZipArchive
is opened in Update mode, calling ZipArchiveEntry.Open
will always result in the entry's data being decompressed and stored in memory.
This is because ZipArchiveEntry.Open
calls ZipArchiveEntry.OpenInUpdateMode
, which in return gets the value of the ZipArchiveEntry.UncompressedData
property, which will decompress the data and store it in a MemoryStream
.
This in its own is already fairly inconvenient - if I'm updating a large file (say 1GB) that's compressed in a zip archive, I would want to read it from the ZipArchiveEntry
in smaller chunks, save it to a temporary file, and update the entry in the ZipArchive
in a similar way (i.e. limiting the memory overhead and preferring temporary files instead).
This also means that as soon as a ZipArchive
is opened in Update mode, even reading an ZipArchiveEntry
which you'll never update incurs the additional cost.
A short-term fix may be to expose ZipArchiveEntry.OpenInReadMode
, which will return a DeflateStream
instead. If you're doing mixed reading/writing of entries in a single ZipArchive
, this should already help you avoid some of the memory overhead.
Activity