Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 4.0 使用GZipStream解压_C# 4.0_Zip_Gzipstream - Fatal编程技术网

C# 4.0 使用GZipStream解压

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

我在一个资源中有一个压缩文件,正在尝试解压缩这个压缩文件。然而,我一直得到这个例外

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,并且不想使用外部库?

我怀疑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();