DotNetZip.Semverd icon indicating copy to clipboard operation
DotNetZip.Semverd copied to clipboard

Unable To Control Memory When Using AddEntry()

Open bruestle2 opened this issue 6 years ago • 2 comments

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

bruestle2 avatar Jun 14 '19 21:06 bruestle2

Some ability to flush the entry buffer into the zip file would solve the issue. I have found two workarounds:

  1. Write the data to disk, then call AddFile, or
  2. 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.

bruestle2 avatar Jun 17 '19 17:06 bruestle2

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.

haf avatar Sep 11 '19 07:09 haf