我在资源中有一个压缩文件,并试图解压缩此zip文件。但是我一直得到这个例外......?
GZip标头中的幻数不正确。确保传入GZip流。
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并不是真的想使用外部库吗?
答案 0 :(得分:0)
我怀疑bigStream.CopyTo(bigStreamOut);
的问题 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();