Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to decompress GZip in Stream (C#)?

This code receives the GZip-encoded string. How can I decode it?

Stream stream = ret.GetResponseStream();

System.IO.StreamReader reader = new System.IO.StreamReader(stream, Encoding.Default);

string answer = reader.ReadToEnd();//answer is GZip encoded string !

byte[] bytes = Encoding.Default.GetBytes(answer);

//???

GZipStream compStream = new GZipStream(stream, CompressionMode.Decompress);

// ... what's next?
like image 871
xieergai Avatar asked Jul 04 '11 08:07

xieergai


1 Answers

One other way is to use Automatic decompression property of the request/response:

request.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;

Set this property before you get the response.

like image 175
TheBoyan Avatar answered Sep 20 '22 08:09

TheBoyan