-1

I have a zipped up file within a resource and am attempting to decompress this zip file. However I keep getting this exception...?

The magic number in GZip header is not correct. Make sure you are passing in a GZip stream.

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

Any ideas anyone? Currently using .Net 4.0 and don't really want to use external libraries?

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
  • Do you understand that gzip and zip are different things? – Jon Skeet Jun 30 '14 at 08:55
  • I had an idea, just can't figure out how to decompress the zip file within the resource? – user3529183 Jun 30 '14 at 08:56
  • In .NET 4.5 you can use `ZipFile`, but I don't know of anything in .NET 4. It's possible there are bits of WPF that are capable of handling zip files, but I suspect the cleanest way would either be to require .NET 4.5 instead, or to use an external library. Certainly `GZipStream` is *not* going to help you. – Jon Skeet Jun 30 '14 at 09:02

1 Answers1

0

I suspect the problem with 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();
Shashi
  • 2,860
  • 2
  • 34
  • 45