开发者

Odd Error in SharpZipLib -- Size was x, but I expected y

开发者 https://www.devze.com 2022-12-09 01:39 出处:网络
I\'m getting an error when I use the SharpZipLib开发者_运维知识库.I have code that looks like

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?


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.


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


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;
         }
0

精彩评论

暂无评论...
验证码 换一张
取 消