5

I'll try to create an zip file with the DotNetZip-Libary with 106 Images (675MB) with the following code:

Public Function GetZip() As Byte()
    Dim zip As New Ionic.Zip.ZipFile(String.Format("{0}.zip", Me.GallerySystemName))
    AddHandler zip.SaveProgress, AddressOf SaveProgress

    For Each img In Me.Images
        zip.AddFile(img.OriginalFile.FullName, "")
    Next

    Dim bytZip As Byte()

    Using ms As New MemoryStream
        zip.Save(ms)
        bytZip = ms.ToArray
    End Using

    Return bytZip
End Function

When I run this code, the execution stops usally at image 40 (sometimes earlier) without any exeption. Nothing happens. I tried to save the zip directly to a file. It works.

Any ideas?

Jan

Jan
  • 363
  • 1
  • 4
  • 10
  • 2
    Debug + Break All. Debug + Windows + Threads, select the active thread. Debug + Windows + Call stack, copy and paste the stack trace into your question. – Hans Passant Jan 16 '11 at 22:02
  • Where does it stop? Programs don't just stop like this by themselves. They stop on some specific line of code. There might also be some exception. Something must be happening. How much available memory do you have? Does the process die? – Darin Dimitrov Jan 16 '11 at 22:02
  • 1
    If you remove the offending file, will it finish zipping the rest of them? – David Weiser Jan 16 '11 at 22:15
  • @Hans Passant: Could you explain what you mean. It's quite difficult for me to understand. – Jan Jan 17 '11 at 08:04
  • @Darin Dimitrov: I know that usally programs are stopping. In this case nothing happens. If I set a breakpoint at and after the zip.Save method, the bytZip = ms.ToArray line is never reached. The memory is enough after a view in the Taskmanager. – Jan Jan 17 '11 at 08:07
  • @David: I don't think that a single image reason for this, because sometimes the code stops earlier. And also the Zip.Save("c:\temp\images.zip") Method is running quite good. – Jan Jan 17 '11 at 08:08
  • Simplify. For example, take away the SaveProgress event. Does it still stop (hang)? – Cheeso Jan 18 '11 at 23:40
  • @Cheeso: Thanks for this advise, but with is I there is also no success. :-( I've opend an issue at codeplex. I will report. – Jan Jan 21 '11 at 21:32

2 Answers2

16

SET the zip object property ParallelDeflateThreshold to -1 just before saving the zip file

zip.ParallelDeflateThreshold = -1



REF: http://forums.codeguru.com/showthread.php?534177-Issue-with-DotNetZip-ionic.zip-class-hanging-on-save

Nitin Sawant
  • 7,278
  • 9
  • 52
  • 98
  • Both Nitin Sawant and Wes Cumberland answers work for C#. Don't forget to put the ParallelDeflateThreshold and/or BufferSize and CodecBufferSize BEFORE the Save method. – Jonathan Robbins Sep 22 '15 at 08:41
9

It's been almost 2 years since your question, so I doubt this will help but I just encountered the same problem in v1.9.1.8.

I worked around it by increasing the BufferSize and CodecBufferSize ZipFile properties to 1MB each.

I can't download the DotNetZip source because of filters at work but here is a very-likely-related comment from http://dotnetzip.codeplex.com/releases/view/68268

There is a pretty major bug in the code. I am working to figure it out. Another chap logged it before me: Deadlock in ParallelDeflateOutputStream.EmitPendingBuffers The zip hangs. End-of-day I will have to rip this code out and start over with a new library. I need to call my last job and give them a head's up b/c I used this library at my last job. They will likely have to rip the code out too. by jnarkiewicz on May 30 at 6:31 PM

So if this is indeed the problem, increasing the size of those buffers just lowers the likelihood of the deadlock occurring and is not an ideal solution.

Wes Cumberland
  • 1,318
  • 8
  • 12