title: Decompressing GZIP stream
body: <p>I am trying to decompress a GZipped string which is part of response from a webservice. The string that I have is:</p>
  
  <p><code>"[31,-117,8,0,0,0,0,0,0,0,109,-114,65,11,-62,48,12,-123,-1,75,-50,-61,-42,-127,30,122,21,111,-126,94,60,-119,-108,-72,102,44,-48,-75,-93,-21,100,56,-6,-33,-19,20,20,101,57,37,95,-14,94,-34,4,-63,-5,-72,-73,-44,-110,-117,-96,38,-88,26,-74,38,-112,3,117,-7,25,-82,5,24,-116,56,-97,-44,108,-23,28,24,-44,-85,83,34,-41,97,-88,24,-99,23,36,124,-120,94,99,-120,15,-42,-91,-108,91,45,-11,70,119,60,-110,21,-20,12,-115,-94,111,-80,-93,89,-41,-65,-127,-82,76,41,51,-19,52,90,-5,69,-85,76,-96,-128,64,22,35,-33,-23,-124,-79,-55,-1,-2,-10,-87,0,55,-76,55,10,-57,122,-9,73,42,-45,98,-44,5,-77,101,-3,58,-91,39,38,51,-15,121,21,1,0,0]"</code></p>
  
  <p>I'm trying to decompress that string using the following method:</p>
  
  <pre><code>public static string UnZip(string value)
          {
              // Removing brackets from string
              value = value.TrimStart('[');
              value = value.TrimEnd(']');
  
              //Transform string into byte[]
              string[] strArray = value.Split(',');
              byte[] byteArray = new byte[strArray.Length];
              for (int i = 0; i &lt; strArray.Length; i++)
              {
                  if (strArray[i][0] != '-')
                      byteArray[i] = Convert.ToByte(strArray[i]);
                  else
                  {
                      int val = Convert.ToInt16(strArray[i]);
                      byteArray[i] = (byte)(val + 256);
                  }
              }
  
              //Prepare for decompress
              System.IO.MemoryStream ms = new System.IO.MemoryStream(byteArray);
              System.IO.Compression.GZipStream sr = new System.IO.Compression.GZipStream(ms,
                  System.IO.Compression.CompressionMode.Decompress);
  
              //Reset variable to collect uncompressed result
              byteArray = new byte[byteArray.Length];
  
              //Decompress
              int rByte = sr.Read(byteArray, 0, byteArray.Length);
  
              //Transform byte[] unzip data to string
              System.Text.StringBuilder sB = new System.Text.StringBuilder(rByte);
              //Read the number of bytes GZipStream red and do not a for each bytes in
              //resultByteArray;
              for (int i = 0; i &lt; rByte; i++)
              {
                  sB.Append((char)byteArray[i]);
              }
              sr.Close();
              ms.Close();
              sr.Dispose();
              ms.Dispose();
              return sB.ToString();
          }
  </code></pre>
  
  <p>The method is a modified version of the one in the following link:
  <a href="http://www.codeproject.com/Articles/27203/GZipStream-Compress-Decompress-a-string/" rel="nofollow" title="codeproject - GZipStream-Compress-Decompress-a-string">http://www.codeproject.com/Articles/27203/GZipStream-Compress-Decompress-a-string</a></p>
  
  <p>Sadly, the result of that method is a corrupted string. More specifically, I know that the input string contains a compressed JSON object and the output string has only some of the expected string:</p>
  
  <pre><code>"{\"rootElement\":{\"children\":[{\"children\":[],\"data\":{\"fileUri\":\"file:////Luciano/e/orto_artzi_2006_0_5_pixel/index/shapefiles/index_cd20/shp_all/index_cd2.shp\",\"relativePath\":\"/i"
  </code></pre>
  
  <p>Any idea what could be the problem and how to solve it?</p>