title: GZipStream is cutting off last part of XML
body: <p>I have created an extension method called AddGZip which looks like the following:</p>
  
  <pre><code>public static void AddGZip(this HttpResponse response)
  {
      response.Filter = new GZipStream(response.Filter, CompressionMode.Compress);
      response.AppendHeader("Content-Encoding", "gzip");
  }
  </code></pre>
  
  <p>This is a very cut down version of the code:</p>
  
  <pre><code>var response = HttpContext.Current.Response;
  var request = HttpContext.Current.Request;
  var result = File.ReadAllText(path);
  if (request.SupportsGZip)
  {
    response.AddGZip();
  }
  response.Write(result);
  response.Flush();
  </code></pre>
  
  <p>When you view the response in a web browser with GZip support you get an error like this:</p>
  
  <blockquote>
    <p>"XML Parsing Error: unclosed token
    Location: <a href="http://webserver1/1234.xml" rel="nofollow noreferrer">http://webserver1/1234.xml</a>
    Line Number 78, Column 1:"</p>
  </blockquote>
  
  <p>When i view the source it's basically missed out the last <code>&gt;</code> from the end of the XML file. So 1 or 2 bytes.</p>
  
  <p>If I comment out the AddGZip Line it works fine. However I really want to support GZip as the XML can be quite large.</p>
  
  <p>Does anyone have a suggestion for me? I've tried checking lots of blogs but no solution seems to be out there for this type of error.</p>
  
  <p>Dave</p>