Unable To Control Memory When Using AddEntry()
When using ZipFile.AddEntry(), memory usage continually increases. If one has a sufficient quantity/size of new entries, an out of memory exception occurs. This problem does not occur when AddFile() is used, nor is it solved by calling ZipFile.Save() after each AddEntry() call.
Sample code:
Using zipFile = New ZipFile(exportFileName)
zipFile.Password = password
zipFile.Encryption = EncryptionAlgorithm.WinZipAes256
For Each entryName in dataToSave
Dim entryData = GetXmlFromSource(entryName)
zipFile.AddEntry(entryName, entryData)
Next
zipFile.Save()
End Using
Some ability to flush the entry buffer into the zip file would solve the issue. I have found two workarounds:
- Write the data to disk, then call AddFile, or
- Finalize the file periodically, then re-open and add more entries
Workaround 1 causes increased disk read/write and presents additional issues if one is trying to make a passwored-protected zip. Workaround 2 exponentially increases cpu and disk read/write as the zip gets larger.
Thanks for reporting this bug/problem, and sorry about the delay in getting back to you. This is a self-service repository, where I merge PRs and where the merging of PRs causes nugets to be pushed automatically (if you bump the version number in your PR). I'll leave this issue open until someone (or yourself) fixes it.