C# 4.0 使用GZipStream解压
我在一个资源中有一个压缩文件,正在尝试解压缩这个压缩文件。然而,我一直得到这个例外 GZip头中的幻数不正确。确保您正在传递GZip流C# 4.0 使用GZipStream解压,c#-4.0,zip,gzipstream,C# 4.0,Zip,Gzipstream,我在一个资源中有一个压缩文件,正在尝试解压缩这个压缩文件。然而,我一直得到这个例外 GZip头中的幻数不正确。确保您正在传递GZip流 byte[] zipFile = HTMLEditor.ZipTest.HTMLEditor; string output = AppDomain.CurrentDomain.BaseDirectory; var bigStreamOut = new System.IO.MemoryStream(); //Decompress
byte[] zipFile = HTMLEditor.ZipTest.HTMLEditor;
string output = AppDomain.CurrentDomain.BaseDirectory;
var bigStreamOut = new System.IO.MemoryStream();
//Decompress
using (var bigStream = new GZipStream(new MemoryStream(zipFile), CompressionMode.Decompress))
{
bigStream.CopyTo(bigStreamOut);
}
有什么想法吗?目前正在使用.Net 4.0,并且不想使用外部库?我怀疑bigStream.CopyTo(bigstreeamout)有问题
你知道gzip和zip是不同的东西吗?我有个主意,就是不知道如何在资源中解压缩zip文件?在.NET4.5中,你可以使用
ZipFile
,但在.NET4中我什么都不知道。可能有一些WPF能够处理zip文件,但我怀疑最干净的方法可能是要求使用.NET4.5,或者使用外部库。当然,GZipStream
对您没有帮助。
byte[] step = new byte[16]; //Instead of 16 can put any 2^x
int readCount;
do
{
readCount = bigStream.Read(step, 0, step.Length);
bigStreamOut.Write(step, 0, readCount);
} while (readCount > 0);
bigStream.Close();