2

I'm getting an error when I use the SharpZipLib. I have code that looks like

FastZip compressor = new FastZip();
compressor.CreateZip(outputFileName, currentWorkingDirectory, true, "");

Which seems to be correct. However, I get a ZipException claiming that

size was 0, but I expected 54

I have no idea what that means. Anyone have any insight, or a link to an API document of some sort?

GWLlosa
  • 23,995
  • 17
  • 79
  • 116

3 Answers3

3

It turns out the issue was as follows. I was trying to make a .zip file of all the items in a given directory, and place that .zip file IN the directory. Apparently the way this library works, the .zip file is created, and then the directory is read in file-by-file, writing into the .zip file. The error occured when it tried to add the .zip file itself to the zip! It was probably denied access to the file or something at that point, resulting in the error above. Simple fix was to create the .ZIP file in a different directory.

GWLlosa
  • 23,995
  • 17
  • 79
  • 116
  • Had a similar issue just now - turns out it was a file locking issue, but this sent me in the right direction :) – Zhaph - Ben Duguid Sep 06 '12 at 15:29
  • I Had fixed similar issue in side ProgressHandler evnent handler and pass the ZIPEntry as Sender
    private void ProcessFileHandler(object sender, ProgressEventArgs e) { ZipEntry newEntry = sender as ZipEntry; if (newEntry != null) { newEntry.Size = e.Processed; } e.ContinueRunning = keepRunning; return; }
    – Murari Kumar Apr 16 '19 at 09:52
1

Here are links to their source code and a help file with API documentation.

Justin Ethier
  • 131,333
  • 52
  • 229
  • 284
0

I Had fixed similar issue by handling it inside ProgressHandler event handler and pass the ZIPEntry as Sender. As this is error condition so we should stop further processing of zip file e.ContinueRunning should be set as false

private void ProcessFileHandler(object sender, ProgressEventArgs e)
        {                    
                ZipEntry newEntry = sender as ZipEntry;
                if (newEntry != null)
                {
                    newEntry.Size = e.Processed;
                }
                e.ContinueRunning = keepRunning;
                return;
         }
Murari Kumar
  • 359
  • 2
  • 9