0

I have a problem with a zip-file created with the old PKZIP® Command Line for Windows version 4 from the year 2000. I am using ICSharpCode.SharpZipLib to extract the file. Windows has no problem to open the file in the Explorer. Here is the code:

private void Extract(string zipFile, string outputfolder)
{
  try
  {
    _logger.InfoFormat("Extracting {0}", zipFile);
    System.IO.Stream stream = new System.IO.FileStream(zipFile, System.IO.FileMode.Open);
    ZipInputStream zipInputStream = new ZipInputStream(stream);
    ZipEntry zipEntry = zipInputStream.GetNextEntry(); //Throws Compression error exception
    while (zipEntry != null)
    {
      String entryFileName = zipEntry.Name;
      _logger.InfoFormat("Entry-Filename: {0}", entryFileName);

      byte[] buffer = new byte[4096];
      String fullZipToPath = Path.Combine(outputfolder, entryFileName);
      string directoryName = Path.GetDirectoryName(fullZipToPath);
      if (directoryName.Length > 0)
      {
        Directory.CreateDirectory(directoryName);
      }

      using (FileStream streamWriter = File.Create(fullZipToPath))
      {
        StreamUtils.Copy(zipInputStream, streamWriter, buffer);
      }
      zipEntry = zipInputStream.GetNextEntry();
    }
  }
  catch (Exception ex)
  {
    _logger.Error("Error during extraction",ex);
    throw;
  }
}

Any idea how to fix this problem?

Sardoan
  • 767
  • 1
  • 10
  • 25
  • Can you elaborate on the exception? What is the exception message? Does it say that the format is unsupported? – Ron Beyer Dec 17 '15 at 18:47
  • The stacktrace is: ICSharpCode.SharpZipLib.Zip.ZipEntry.set_CompressionMethod(CompressionMethod value) bei ICSharpCode.SharpZipLib.Zip.ZipInputStream.GetNextEntry() bei CSVImport.Decompressor.Extract(String zipFile, String outputfolder) in c:\Users\dev-cotreba\Desktop\Neuerer_csv\CSVImport\Decompressor.cs:Zeile 84. And the message: Compression method not supported. Not that informative – Sardoan Dec 17 '15 at 19:00
  • The decompressor that Windows uses is not related to the decompressor that SharpZipLib uses, so you can't really draw a line between one working and one not working. It seems pretty clear from the message, that the compression scheme used is not supported by SharpZipLib. – Ron Beyer Dec 17 '15 at 19:07
  • The strange thing is that I can add some files to the zip with the Explorer and they can be extracted with SharpZipLib. It extracts the files and throws the exception when it tries to extract the file added via PKZIP. It is a bit strange, since I used pkzip over 25 years ago and it worked on DOS. Thought the liburary should support such an old compression method. – Sardoan Dec 17 '15 at 19:11
  • 1
    There's a point at which keeping backwards compatibility is more of a pain than a benefit. I'm guessing the authors didn't choose to support that one just because its so old. Personally if I were writing a Zip library from scratch, a 25 year old ZIP format would not be high on the list of supported formats. – Ron Beyer Dec 17 '15 at 19:13
  • True. I hoped PKZIP would use a standard algorithm to compress the stuff. Seems I still need to use System.Diagnaostics to call the exe. Thanks for your help anyway. I tried to convince the side sending the zips to me to use a zipper I wrote with the lib. But it is hard to change old processes at the german car industry... – Sardoan Dec 17 '15 at 19:20

1 Answers1

1

I had this same issue when decompressing a zip-file made with 7-zip.

I changed it from Deflate64 to Deflate, and then it worked.

7-zip screenshot showing compression method

frankhommers
  • 1,169
  • 12
  • 26