简体   繁体   English

c#寻找API读取7z标头

[英]c# looking for API to read 7z headers

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? 是否有用于7zip(7z)的基于c#的API,该API支持读取其标头以检索压缩档案中每个文件的CRC信息的功能? 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. 我正在编写一个将压缩文件夹中文件的CRC与单独列表进行比较的应用程序。

I currently am using DotNetZip for zip files and it works great. 我目前正在使用DotNetZip压缩文件,效果很好。 Unfortunately it has no .7z support. 不幸的是,它没有.7z支持。

EDIT: Exception generated when calling ZipFile.Read() 编辑:调用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)

... ...

This sounds like a duplicate post.. here look at some of the answers on this StackOverFlow Link Reading 7z files 这听起来像是重复的帖子。.在此查看此StackOverFlow链接中的一些答案阅读7z文件

This should work for you if you are using DotNetZip try this example below 如果您正在使用DotNetZip,这应该对您有用,请尝试以下示例

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");

  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM