如何阅读从一个zip文件中的数据,而无需解压整个文件 [英] How to read data from a zip file without having to unzip the entire file

查看:166
本文介绍了如何阅读从一个zip文件中的数据,而无需解压整个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

反正在.net(C#)来提取一个zip文件中的数据,而不DECOM pressing完整的文件?

Is there anyway in .Net (C#) to extract data from a zip file without decompressing the complete file?

只要我可能要提取一个zip文件的起始数据(文件),显然这取决于如果COM pression算法融为一体preSS以确定的顺序文件。

Simply I possibly want to extract data (file) from the start of a zip file, obviously this depends if the compression algorithm compress the file in a deterministic order.

推荐答案

DotNetZip 是你的朋友在这里。

一样简单:

using (ZipFile zip = ZipFile.Read(ExistingZipFile))
{
  ZipEntry e = zip["MyReport.doc"];
  e.Extract(OutputStream);
}

(你也可以提取到一个文件或其他目的地)。

(you can also extract to a file or other destinations).

读取压缩文件的目录也是很简单的:

Reading the zip file's table of contents is as easy as:

using (ZipFile zip = ZipFile.Read(ExistingZipFile))
{
  foreach (ZipEntry e 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}",
                             e.FileName,
                             e.LastModified.ToString("yyyy-MM-dd HH:mm:ss"),
                             e.UncompressedSize,
                             e.CompressionRatio,
                             e.CompressedSize,
                             (e.UsesEncryption) ? "Y" : "N");

  }
}

这篇关于如何阅读从一个zip文件中的数据,而无需解压整个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆