SharpZipLib Basics What am I missing?

There is the following method in my code:

private bool GenerateZipFile(List<FileInfo> filesToArchive, DateTime archiveDate) { try { using (ZipOutputStream zipStream = new ZipOutputStream(File.Create(GetZipFileName(archiveDate)))) { zipStream.SetLevel(9); // maximum compression. byte[] buffer = new byte[4096]; foreach (FileInfo fi in filesToArchive) { string fileName = ZipEntry.CleanName(fi.Name); ZipEntry entry = new ZipEntry(fileName); entry.DateTime = fi.LastWriteTime; zipStream.PutNextEntry(entry); using (FileStream fs = File.OpenRead(fi.FullName)) { StreamUtils.Copy(fs, zipStream, buffer); } zipStream.CloseEntry(); } zipStream.Finish(); zipStream.Close(); } return true; } catch (Exception ex) { OutputMessage(ex.ToString()); return false; } } 

This code generates a ZIP file with all the correct entries, but each file is listed as 4 TB (both unpacked and packed) and creates the following error when trying to open it:

 Extracting to "C:\winnt\profiles\jbladt\LOCALS~1\Temp\" Use Path: no Overlay Files: yes skipping: QPS_Inbound-20081113.txt: this file is not in the standard Zip 2.0 format Please see www.winzip.com/zip20.htm for more information error: no files were found - nothing to do 

The code is practically taken from the samples, but it seems to me that something is missing. Does anyone have pointers?

+4
source share
4 answers

I used SharpZipLib until I switched to DotNetZip . You can check this out as an alternative.

Example:

 try { using (ZipFile zip = new ZipFile("MyZipFile.zip") { zip.AddFile("c:\\photos\\personal\\7440-N49th.png"); zip.AddFile("c:\\Desktop\\2005_Annual_Report.pdf"); zip.AddFile("ReadMe.txt"); zip.Save(); } } catch (System.Exception ex1) { System.Console.Error.WriteLine("exception: " + ex1); } 
+7
source

See post Tyler Holmes

The problem with Winzip 8.0 and others with Zip64. Set the original file size when adding ZipEntry, and the error will disappear.

eg.

 string fileName = ZipEntry.CleanName(fi.Name); ZipEntry entry = new ZipEntry(fileName); entry.DateTime = fi.LastWriteTime; entry.Size = fi.Length; zipStream.PutNextEntry(entry); 

The zip utilities for the current version have no problems.

+3
source

I had a similar problem that I solved by specifying the CompressionMethod and CompressedSize properties of the ZipEntry object. However, in my use, zip was created to group several very small files in one download, and not to compress files, so I managed to avoid compression (level 0) and use the actual file size for the CompressedSize property. Not sure how this will work if compression is needed.

+2
source

In the interest of anyone who has the same problem in the future: My problem turned out to be that I used a truly ancient version of WinZip (I think 8.0) to view files. Using a modern viewer (12.0) solved the problem.

0
source

All Articles