2

Is there c# based API for 7zip (7z) that supports the ability to read its header to retrieve the CRC information for each file in the compressed archive? Everything I have looked at requires you to decompress the file. I am writing an application that compares the CRCs of the files in a compressed folder with a separate list.

I currently am using DotNetZip for zip files and it works great. Unfortunately it has no .7z support.

EDIT: Exception generated when calling ZipFile.Read()

{Ionic.Zip.ZipException: Cannot read that as a ZipFile ---> Ionic.Zip.BadReadException:   Bad signature (0xAFBC7A37) at position  0x00000000
   at Ionic.Zip.ZipEntry.ReadHeader(ZipEntry ze, Encoding defaultEncoding)
   at Ionic.Zip.ZipEntry.ReadEntry(ZipContainer zc, Boolean first)
   at Ionic.Zip.ZipFile.ReadIntoInstance_Orig(ZipFile zf)
   at Ionic.Zip.ZipFile.ReadIntoInstance(ZipFile zf)
   --- End of inner exception stack trace ---
   at Ionic.Zip.ZipFile.ReadIntoInstance(ZipFile zf)
   at Ionic.Zip.ZipFile.Read(String fileName, TextWriter statusMessageWriter, Encoding encoding, EventHandler`1 readProgress)
   at Ionic.Zip.ZipFile.Read(String fileName)

...

Don H
  • 41
  • 2
  • 5
  • possible duplicate of [Free compression library for C# which supports 7zip (LZMA)](http://stackoverflow.com/questions/449998/free-compression-library-for-c-sharp-which-supports-7zip-lzma) – stakx - no longer contributing Jul 23 '12 at 18:15
  • Not really. Unfortunately there is no easy way to read the CRC information from the headers with that API. – Don H Jul 24 '12 at 01:53

1 Answers1

1

This sounds like a duplicate post.. here look at some of the answers on this StackOverFlow Link Reading 7z files

This should work for you if you are using DotNetZip try this example below

using (ZipFile zip = ZipFile.Read(ExistingZipFile))
{
  foreach (ZipEntry ze in zip)
  {
    if (header)
    {
      System.Console.WriteLine("Zipfile: {0}", zip.Name);
      if ((zip.Comment != null) && (zip.Comment != "")) 
        System.Console.WriteLine("Comment: {0}", zip.Comment);
      System.Console.WriteLine("\n{1,-22} {2,8}  {3,5}   {4,8}  {5,3} {0}",
                               "Filename", "Modified", "Size", "Ratio", "Packed", "pw?");
      System.Console.WriteLine(new System.String('-', 72));
      header = false;
    }
    System.Console.WriteLine("{1,-22} {2,8} {3,5:F0}%   {4,8}  {5,3} {0}",
                             ze.FileName,
                             ze.LastModified.ToString("yyyy-MM-dd HH:mm:ss"),
                             ze.UncompressedSize,
                             ze.CompressionRatio,
                             ze.CompressedSize,
                             (ze.UsesEncryption) ? "Y" : "N");

  }
}
Community
  • 1
  • 1
MethodMan
  • 18,625
  • 6
  • 34
  • 52
  • I have seen that post already. Unfortunately none of those APIs *seem* to have calls to read the CRCs for each file in the compressed archive. – Don H Jul 23 '12 at 18:22
  • I was looking more into 7ZipStream http://code.google.com/p/7zipstream/source/browse/trunk/_Documentation/7zC.txt?r=3 In step 5 of "Steps for using 7z decoder" I came the list items example. I wonder if there is something in CFileItem. – Don H Jul 23 '12 at 18:28
  • if you are using DotNetZip I am going to post something that may work for you.. let me know if this is something that could possibly work – MethodMan Jul 23 '12 at 18:30
  • I thought DotNetZip does not support 7z files? I am using the ZipEntry API already for the .zip files though. – Don H Jul 23 '12 at 18:44
  • I found an example that looks like DotnetZip would work..I don't have it installed on my local but at work machine I do.. so can't test it just give it a try.. step thru the code and see if it's what you are looking for or if the code snippet helps – MethodMan Jul 23 '12 at 18:53
  • I end up getting an exception "Cannot read that as a ZipFile". This is what lead me to believe DotNetZip did not support 7z. – Don H Jul 23 '12 at 21:04
  • I should mention that that exception is generated during ZipFile.Read() call – Don H Jul 23 '12 at 21:20
  • Pasted my detailed exception above in my first post – Don H Jul 23 '12 at 22:29
  • Hi, I'm facing the same problem , did you find a solution to extract this files? – Mouadh Oct 02 '12 at 07:46