StreamReader.ReadToEnd() returning an empty string

Posted by axk on Stack Overflow See other posts from Stack Overflow or by axk
Published on 2010-04-03T22:59:46Z Indexed on 2010/04/03 23:33 UTC
Read the original article Hit count: 576

Filed under:
|

I have a method

private static String DecompressAndDecode(byte[] data)
{
   GZipStream decompressor = new GZipStream(new MemoryStream(data), CompressionMode.Decompress);
   StreamReader decompressed = new StreamReader(decompressor, Encoding.UTF8);
   String result = decompressed.ReadToEnd();
   return result;
}

I have some GZipped text as input and the result is supposed to be a String representation of this text. The problem is that the method returns an empty string. What is puzzling me is that when I step trough the method in debug mode and reach the return statement the result variable is an empty string but if I create a watch for the decompressed.ReadToEnd() expression it returns me the text. What I would expect at this point is the result variable to contain the text and the decompressed.ReadToEnd() expression evaluating to an empty string. (Reevaluating the decompressed.ReadToEnd() expression returns an empty string as expected).

There must be something obvious I'm missing here.

© Stack Overflow or respective owner

Related posts about .NET

Related posts about streams