views:

466

answers:

4

I've got a C# program that uses SharpZIPlib to decompress some zip files? It works fine but on one file, I keep getting "Unexpected EOF" error? Is there actually an EOF marker, or did the Zip file just get truncated?

+5  A: 

Your file got truncated (or possibly extended or otherwise corrupted).

You could run the regular unzip program on it (say 'unzip -l file.zip') to prove this.

Incidentally, if you used FTP to download the file, did you remember to use a binary transfer? If you (accidentally) used ASCII mode, that will ruin any binary file such as a ZIP archive.

Jonathan Leffler
+2  A: 

Unexpected EOF means exactly that: when reading the file, the function encountered the end of the file and the library was expecting something else (data). It is not a marker.

Otávio Décio
+4  A: 

A simple ZIP file looks like this:

LocalHeader1
CompressedData1
LocalHeader2
CompressedData2
[...]
LocalHeaderN
CompressedDataN
CentralHeader1
CentralHeader2
[...]
CentralHeaderN
EndHeader

The EndHeader contains (amongst other things) the offset to the first CentralHeader, then each CentralHeader contains an offset to their matching LocalHeader.

Some libraries can read the zip file from the start to process LocalHeaders sequentially, thus recover what can be recovered of a damaged zip file.

Martin Plante
Interesting information - thanks.
Jonathan Leffler
DotNetZip (http://dotnetzip.codeplex.com) can optionally do a full scan of the zip file, ignoring the directory. This allows you to reconstruct the zip directory from the existing zip entries, for a corrupted or truncated file.
Cheeso
+1  A: 

Have you tried DotNetZip ? http://www.codeplex.com/DotNetZip

Cheeso