Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

System.IO.Compression End of Central Directory record could not be found

On executing the following code.. I get an exception on the OpenRead statement:

End of Central Directory record could not be found.

I am however able to open the zip file with no issues through windows explorer.

Any thoughts?

string zipPath = @"c:\testfiles\MMM_C13000_2016M08.zip";
   using (ZipArchive archive = ZipFile.OpenRead(zipPath))
   {
       foreach (ZipArchiveEntry entry in archive.Entries)
       {
       }
   }
like image 683
Fiona Avatar asked Sep 08 '16 12:09

Fiona


1 Answers

It is possible to process a zip file in two different ways. You can simply read sequentially from the beginning, processing local headers and compressed data as you go. Or you can use the central directory at the end of the zip file to find the entries and process them by seeking in the file.

It appears that the zip file is damaged or has junk at the end that is preventing one method from working, but not the other.

like image 117
Mark Adler Avatar answered Sep 20 '22 23:09

Mark Adler