GZipStream not reading the whole file

Posted by Ed on Stack Overflow See other posts from Stack Overflow or by Ed
Published on 2010-06-18T09:06:18Z Indexed on 2010/06/18 9:43 UTC
Read the original article Hit count: 438

Filed under:
|

I have some code that downloads gzipped files, and decompresses them. The problem is, I can't get it to decompress the whole file, it only reads the first 4096 bytes and then about 500 more.

Byte[] buffer = new Byte[4096];
int count = 0;
FileStream fileInput = new FileStream("input.gzip", FileMode.Open, FileAccess.Read, FileShare.Read);
FileStream fileOutput = new FileStream("output.dat", FileMode.Create, FileAccess.Write, FileShare.None);
GZipStream gzipStream = new GZipStream(fileInput, CompressionMode.Decompress, true);

// Read from gzip steam
while ((count = gzipStream.Read(buffer, 0, buffer.Length)) > 0)
{
    // Write to output file
    fileOutput.Write(buffer, 0, count);
}

// Close the streams
...

I've checked the downloaded file; it's 13MB when compressed, and contains one XML file. I've manually decompressed the XML file, and the content is all there. But when I do it with this code, it only outputs the very beginning of the XML file.

Anyone have any ideas why this might be happening?

© Stack Overflow or respective owner

Related posts about c#

Related posts about gzipstream