title: Writing to the compression stream is not supported. Using System.IO.GZipStream
body: <p>I get an exception when trying to decompress a (.gz) file using the GZipStream class that is included in the .NET framework. I am using the MSDN documentation. This is the exception: </p>
  
  <blockquote>
    <p>Writing to the compression stream is not supported.</p>
  </blockquote>
  
  <p>Here is the application source:</p>
  
  <pre><code> try
   {
       var infile = new FileStream(@"C:\TarDecomp\TarDecomp\TarDecomp\bin\Debug\nick_blah-2008.tar.gz", FileMode.Open, FileAccess.Read, FileShare.Read);
       byte[] buffer = new byte[infile.Length];
       // Read the file to ensure it is readable.
       int count = infile.Read(buffer, 0, buffer.Length);
       if (count != buffer.Length)
       {
           infile.Close();
           Console.WriteLine("Test Failed: Unable to read data from file");
           return;
       }
       infile.Close();
       MemoryStream ms = new MemoryStream();
       // Use the newly created memory stream for the compressed data.
       GZipStream compressedzipStream = new GZipStream(ms, CompressionMode.Decompress, true);
       Console.WriteLine("Decompression");
       compressedzipStream.Write(buffer, 0, buffer.Length); //&lt;&lt;Throws error here
       // Close the stream.
       compressedzipStream.Close();
       Console.WriteLine("Original size: {0}, Compressed size: {1}", buffer.Length, ms.Length);
  } catch {...}
  </code></pre>
  
  <p>The exception is thrown at the compressedZipStream.write().</p>
  
  <p>Any ideas? What is this exception telling me?</p>