[英]Read ionic Zip as Memory Stream C#
I am using Ionic.Zip to extract ZipFile to memory stream with this method: 我正在使用Ionic.Zip使用此方法将ZipFile提取到内存流:
private MemoryStream GetReplayZipMemoryStream()
{
MemoryStream zipMs = new MemoryStream();
using (ZipFile zip = ZipFile.Read(myFile.zip))
{
foreach (ZipEntry zipEntry in zip)
{
if (zipEntry.FileName.StartsWith("Aligning") || zipEntry.FileName.StartsWith("Sensing"))
{
zipEntry.Extract(zipMs);
}
}
}
zipMs.Seek(0, SeekOrigin.Begin);
return zipMs;
}
Once I am done extracting, I want to read the streams and get some of the entries based on the entry filename. 一旦我完成提取,我想读取流并根据条目文件名获取一些条目。 How can I do that? 我怎样才能做到这一点?
I tried by calling with the code below, but I get error on the ZipFile.Read(ms)
which said: 我尝试使用下面的代码调用,但我在ZipFile.Read(ms)
上得到错误,其中说:
Cannot read that as a ZipFile 无法将其视为ZipFile
Stream ms = GetReplayZipMemoryStream();
using (ZipFile zip = ZipFile.Read(ms))
{
ZipEntry imageEntry = zip.Entries.First(x => x.FileName.EndsWith(".png"));
using (Stream s = imageEntry.OpenReader())
{
var image = Image.FromStream(s);
pictureBox1.Image = image;
}
}
Thank you in advance for the help! 提前感谢您的帮助!
This may be little bit old question and late answer but I have did something to get the files as bytes collections and its file names like this 这可能是一个有点老问题和迟到的答案,但我已经做了一些事情来获取文件作为字节集合和它的文件名这样
public static Dictionary<string, byte[]> Decompress(Stream targFileStream)
{
Dictionary<string, byte[]> files = new Dictionary<string, byte[]>();
using(ZipFile z = ZipFile.Read(targFileStream))
{
foreach (ZipEntry zEntry in z)
{
MemoryStream tempS = new MemoryStream();
zEntry.Extract(tempS);
files.Add(zEntry.FileName, tempS.ToArray());
}
}
return files;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.