解决方法
是的,可以使用SharpZipLib枚举zip文件的文件.您还可以从zip文件中选择文件,并将这些文件复制到磁盘上的目录中.
这是一个小例子:
- 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(如果它符合某些条件).
希望这可以帮助.