I'm trying to decompress a GZipStream. The problem is that the "Length" property on the stream throws a "NotSupported" exception. How do I know what size to make my buffer when I'm reading the bytes from the stream? Since it's compressed I don't know how large the uncompressed version will be. Any suggestions?
1
votes
2 Answers
4
votes
Why do you need that?
public static byte[] Decompress(this byte[] data)
{
var ms = new MemoryStream(data);
var s = new GZipStream(ms, CompressionMode.Decompress);
var output = new MemoryStream();
byte[] buffer = new byte[8192];
int read = 0;
while ((read = s.Read(buffer, 0, buffer.Length)) > 0)
{
output.Write(buffer, 0, read);
}
return output.ToArray();
}