title: Using GZipStream to compress empty input results in an invalid gz file in C#
body: <p>I am using the C# GZipStream class to compress some input data. The problem is when that input is empty. In that scenario, it ends up creating a 0 byte file. When I try to use 7zip to unzip the resulting .gz file, it gives an error saying the format is invalid. If I have a non-empty input, it works fine. Please tell me how I can create a valid .gz file that will uncompress into a 0 byte file?</p>
  
  <pre><code>var file = new FileStream("foo.txt.gz", FileMode.Create, FileAccess.ReadWrite);
  var gzip = new GZipStream(file, CompressionMode.Compress);
  var writer = new StreamWriter(gzip);
  
  for (string line in input) {
      writer.Write(line);
  }
  
  writer.Close();
  gzip.Close();
  file.Close();
  </code></pre>
  
  <p>In the code above, if my 'input' array is empty, I end up writing a file called foo.txt.gz with 0 bytes, and 7zip says the file is invalid. But if I have a non-empty array, I get a valid file. Please tell me how I can modify my code to resolve the issue such that I get a valid .gz file even when the input is empty. Thanks!</p>
  
  <hr>
  
  <p>EDIT: This may be a bug in .NET. If you notice the same issue and agree that it is a bug, please vote on: <a href="https://connect.microsoft.com/VisualStudio/feedback/details/888912/gzipstream-creates-invalid-gz-files-when-input-is-empty" rel="noreferrer">https://connect.microsoft.com/VisualStudio/feedback/details/888912/gzipstream-creates-invalid-gz-files-when-input-is-empty</a></p>