将Ionic Zip读取为Memory Stream C#

编程入门 行业动态 更新时间:2024-10-27 06:23:59
本文介绍了将Ionic Zip读取为Memory Stream C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用Ionic.Zip通过以下方法将ZipFile提取到内存流中:

I am using Ionic.Zip to extract ZipFile to memory stream with this method:

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?

我尝试使用下面的代码进行调用,但是在ZipFile.Read(ms)上显示错误:

I tried by calling with the code below, but I get error on the ZipFile.Read(ms) which said:

无法将其读取为ZipFile

Cannot read that as a 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; } }

预先感谢您的帮助!

推荐答案

这可能是个有点老的问题和较晚的答案,但我已经做了一些事情来将文件作为字节集合及其文件名

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; }

更多推荐

将Ionic Zip读取为Memory Stream C#

本文发布于:2023-11-06 13:18:37,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1563796.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Zip   Ionic   Stream   Memory

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!