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?
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.
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.
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.