SharpZipLib检查,然后选择一个ZIP文件的内容 [英] SharpZipLib Examine and select contents of a ZIP file

查看:174
本文介绍了SharpZipLib检查,然后选择一个ZIP文件的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个项目中使用SharpZipLib,我想知道是否可以用它来寻找一个zip文件中,如果内的文件之一,具有范围修改的数据我正在寻找,然后选择那些文件出并将其复制到一个新的目录?有谁知道ID这是可能的吗?

I am using SharpZipLib in a project and am wondering if it is possible to use it to look inside a zip file, and if one of the files within has a data modified in a range I am searching for then to pick that file out and copy it to a new directory? Does anybody know id this is possible?

推荐答案

是的,这是可能的枚举使用SharpZipLib zip文件的文件。你也可以挑选出文件的zip文件,并把这些文件复制到磁盘上的目录

Yes, it is possible to enumerate the files of a zip file using SharpZipLib. You can also pick files out of the zip file and copy those files to a directory on your disk.

下面是一个小例子:

using (var fs = new FileStream(@"c:\temp\test.zip", FileMode.Open, FileAccess.Read))
{
  using (var zf = new ZipFile(fs))
  {
    foreach (ZipEntry ze in zf)
    {
      if (ze.IsDirectory)
        continue;

      Console.Out.WriteLine(ze.Name);            

      using (Stream s = zf.GetInputStream(ze))
      {
        byte[] buf = new byte[4096];
        // Analyze file in memory using MemoryStream.
        using (MemoryStream ms = new MemoryStream())
        {
          StreamUtils.Copy(s, ms, buf);
        }
        // Uncomment the following lines to store the file
        // on disk.
        /*using (FileStream fs = File.Create(@"c:\temp\uncompress_" + ze.Name))
        {
          StreamUtils.Copy(s, fs, buf);
        }*/
      }            
    }
  }
}

在上面的例子中我使用了一个的MemoryStream 存储的ZipEntry 在存储器(进一步的分析)。您也可以存储的ZipEntry (如果符合一定的标准)在磁盘上。

In the example above I use a MemoryStream to store the ZipEntry in memory (for further analysis). You could also store the ZipEntry (if it meets certain criteria) on disk.

希望,这有助于。

这篇关于SharpZipLib检查,然后选择一个ZIP文件的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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