如何将物理zip文件转换为System.IO.Stream对象? 我试过了 -
System.IO.Stream stream = File.ReadAllBytes(Path + "\\" + "ZipFile.zip");
StreamReader stream = new StreamReader(Path + "\\" + "ZipFile.zip");
System.IO.Stream stream = new FileStream(Path + "\\" + "ZipFile.zip", FileMode.Open); stream.Close();
他们似乎都没有工作。
当尝试读取流时,它或者说流不可读
或者文件在目的地似乎已损坏且无法解压缩
答案 0 :(得分:1)
byte[]
强制转换为Stream
)...所以不确定如何在此处获得运行时错误。StreamReader
不是广告信息流 - 不确定您希望转化的内容。答案 1 :(得分:1)
试试此代码。要使用此代码,您必须下载dotnetzip-ionic.dll
using Ionic.Zip;
using Ionic.Crc;
using System.IO;
protected void Page_Load(object sender, EventArgs e)
{
using (ZipFile zip = ZipFile.Read(ZipPath))
{
foreach (ZipEntry entry in zip)
{
CrcCalculatorStream reader = entry.OpenReader();
MemoryStream memstream = new MemoryStream();
reader.CopyTo(memstream);
byte[] bytes = memstream.ToArray();
System.IO.Stream stream = new System.IO.MemoryStream(bytes);
}
}
}
答案 2 :(得分:0)
查看SharpZipLib的ZipInputStream
:https://github.com/icsharpcode/SharpZipLib