From e3b3823c5fd5181cec8a53a1befa16ccb02d359b Mon Sep 17 00:00:00 2001 From: Mohammed ElSayed Date: Sun, 29 Mar 2015 18:23:06 +0200 Subject: [PATCH] Fix Gzip decompresstion error: removed decompresstion logic because the stream is automatically decompressed as a result of using 'AutomaticDecompression' on the request object. --- .../C#/StreamingConnection_Async.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Premium Stream Connection/C#/StreamingConnection_Async.cs b/Premium Stream Connection/C#/StreamingConnection_Async.cs index 8869ebc..2a6766f 100644 --- a/Premium Stream Connection/C#/StreamingConnection_Async.cs +++ b/Premium Stream Connection/C#/StreamingConnection_Async.cs @@ -105,7 +105,6 @@ static void handleResult(IAsyncResult result) using (HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(result)) using (Stream stream = response.GetResponseStream()) using (MemoryStream memory = new MemoryStream()) - using (GZipStream gzip = new GZipStream(memory, CompressionMode.Decompress)) { byte[] compressedBuffer = new byte[8192]; byte[] uncompressedBuffer = new byte[8192]; @@ -127,9 +126,11 @@ static void handleResult(IAsyncResult result) memory.Write(compressedBuffer.Take(readCount).ToArray(), 0, readCount); memory.Position = 0; - int uncompressedLength = gzip.Read(uncompressedBuffer, 0, uncompressedBuffer.Length); - - output.AddRange(uncompressedBuffer.Take(uncompressedLength)); + // No need to decompress the stream again because request.AutomaticDecompression is enabled so the stream will be automatically decompressed + //(see line 80) + //int uncompressedLength = gzip.Read(uncompressedBuffer, 0, uncompressedBuffer.Length); + uncompressedBuffer = memory.ToArray(); + output.AddRange(uncompressedBuffer.Take(uncompressedBuffer.Length)); if (!output.Contains(0x0A)) continue; //Heartbeat