The zip process is hanging when compressing multiple large files

Jan 31, 2012 at 7:59 PM

I have the following repro situation.

First, I used this code to create a bunch of dummy 300MB files:

#include <cstdio>
#include <cstdlib>

int main(int argc, char* argv[])
{
    srand(1234);

    size_t sz = 75*1024*1024;
    int *data = new int[sz];

    for (size_t ff=0; ff<18; ++ff)
    {
        printf("Making random data for File%03d\n",ff+1);
        for (size_t dd=0; dd<sz; ++dd)
        {
            data[dd] = rand();
        }
        char fname[50];
        sprintf_s(fname,50,"File%03d.dat",ff+1);
        printf("Saving out the file: %s\n",fname);
        FILE *fptr = 0;
        fopen_s(&fptr,fname,"wb");
        fwrite(data,sizeof(int),sz,fptr);
        fclose(fptr);
    }

    delete [] data;

    return 0;
}

Then I used the following code to zip up the created files:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using Ionic.Zip;
                               
namespace TestZipUp
{
    class Program
    {
        static int Main(string[] args)
        {
            if (args.Length != 2)
            {
                Console.WriteLine("Syntax: ");
                Console.WriteLine("    TestZipUp <output zip name> <input folder>");
                return -1;
            }

            string outputZipFname = args[0];
            string inputFolder = args[1];

            using (ZipFile zip = new ZipFile(outputZipFname))
            {
                zip.CompressionLevel = Ionic.Zlib.CompressionLevel.Default;
                zip.UseZip64WhenSaving = Zip64Option.AsNecessary;
                zip.AlternateEncoding = System.Text.Encoding.UTF8;
                zip.AlternateEncodingUsage = ZipOption.Always;

                // Zipping up the entire folder.
                zip.AddDirectory(inputFolder);
                Console.WriteLine("Zipping up folder ...");

                // Update some static variables being used by the SaveProgress event handler first.
                try
                {
                    // If we're not running from Shell, using Console.WindowWidth will give an exception.
                    sConsoleWindowWidth = Console.WindowWidth;
                    sExecutingFromShell = true;
                }
                catch
                {
                    sExecutingFromShell = false;
                }
                sLastZipEntry = null;
                zip.SaveProgress += new EventHandler<SaveProgressEventArgs>(ZipSaveProgress);
                zip.Save();
                Console.WriteLine("\nDone.");

                return 0;
            }           
        }

        private static string sLastZipEntry = null;
        private static bool sExecutingFromShell = false;
        private static int sConsoleWindowWidth = 80;

        static void ZipSaveProgress(object sender, SaveProgressEventArgs e)
        {
            if (e.TotalBytesToTransfer > 0)
            {
                if (sExecutingFromShell)
                {
                    string s = string.Format("{0}: {1}%", e.CurrentEntry, (e.BytesTransferred * 100) / e.TotalBytesToTransfer);
                    Console.Write("\r{0}", s.PadRight(sConsoleWindowWidth - 1));
                }
                else
                {
                    // If the program is not being run on a Shell, just print out the file only once on screen.
                    if (sLastZipEntry != e.CurrentEntry.ToString())
                    {
                        Console.WriteLine("{0}", e.CurrentEntry.ToString());
                        sLastZipEntry = e.CurrentEntry.ToString();
                    }
                }
            }
        }

    }
}

When I ran the test, the program was able to zip up the first file "File001.dat" fine.  But it start to hang at File002.dat at 0%. 

I'm using DotNetZip version 1.9.1.8.  Is this a know issue?  Anyone seen DotNetZip hanging before when compressing large files?  I notice that if I don't compress the files (ie set zip.CompressionLevel to Ionic.Zlib.CompressLevel.None), the process won't hang. 

 

Mar 2, 2012 at 7:22 PM

Looks like I found another thread that shows me exactly what was happening and the work around.

http://dotnetzip.codeplex.com/workitem/14252