title: Gzip uncompress from string error, The magic number in GZip header is not correct
body: <p>I am trying to replicate the php function gzuncompress in C#
  So far I got part of following code working. see comment and code below.</p>
  
  <p>I thing the tricky bit is happening during byte[] and string convertion.
  How can I fix this? and where did I missed?? </p>
  
  <p>I am using .Net 3.5 environment</p>
  
  <pre><code>        var plaintext = Console.ReadLine();
          Console.WriteLine("string to byte[] then to string");
          byte[] buff = Encoding.UTF8.GetBytes(plaintext);
  
          var compress = GZip.GZipCompress(buff);
          //Uncompress working below
          try
          {
              var unpressFromByte = GZip.GZipUncompress(compress);
              Console.WriteLine("uncompress successful by uncompress byte[]");
          }catch
          {
              Console.WriteLine("uncompress failed by uncompress byte[]");
          }
  
          var compressString = Encoding.UTF8.GetString(compress);
          Console.WriteLine(compressString);
          var compressBuff = Encoding.UTF8.GetBytes(compressString);
          Console.WriteLine(Encoding.UTF8.GetString(compressBuff));
          //Uncompress not working below by using string
          //The magic number in GZip header is not correct
          try
          {
              var uncompressFromString = GZip.GZipUncompress(compressBuff);
              Console.WriteLine("uncompress successful by uncompress string");
          }
          catch
          {
              Console.WriteLine("uncompress failed by uncompress string");
          }
  </code></pre>
  
  <p>code for class Gzip</p>
  
  <pre><code>public static class GZip
        {
          public static byte[] GZipUncompress(byte[] data)
          {
              using (var input = new MemoryStream(data))
              using (var gzip = new GZipStream(input, CompressionMode.Decompress))
              using (var output = new MemoryStream())
              {
                  gzip.CopyTo(output);
                  return output.ToArray();
              }
          }
          public static byte[] GZipCompress(byte[] data)
          {
              using (var input = new MemoryStream(data))
              using (var output = new MemoryStream())
              {
                  using (var gzip = new GZipStream(output, CompressionMode.Compress, true))
                  {
                      input.CopyTo(gzip);
                  }
                  return output.ToArray();
              }
          }
  
          public static long CopyTo(this Stream source, Stream destination)
          {
              var buffer = new byte[2048];
              int bytesRead;
              long totalBytes = 0;
              while ((bytesRead = source.Read(buffer, 0, buffer.Length)) &gt; 0)
              {
                  destination.Write(buffer, 0, bytesRead);
                  totalBytes += bytesRead;
              }
              return totalBytes;
          }
  }
  </code></pre>