title: Compressing with GZipStream
body: <p>I am trying to understand why my code doesn't execute as desired. It creates a GZipStream,  and then saves the object as compressed file on my hard drive, but the saved file is always 0 bytes.</p>
  
  <p>Now I know how to <a href="http://www.dotnetperls.com/gzipstream" rel="noreferrer">save a file using GZipStream</a>, but, my question is not how to do it. My question is purely why does this code save 0 bytes (or why FileStream works and memory doesn't).</p>
  
  <pre><code>private void BegingCompression()
  {
      var bytes = File.ReadAllBytes(this.fileName);
      using (MemoryStream ms = new MemoryStream(bytes))
      {
          ms.ReadByte();
          using (FileStream fs =new FileStream(this.newFileName, FileMode.CreateNew))
          using (GZipStream zipStream = new GZipStream(ms, CompressionMode.Compress, false))
          {
              zipStream.Write(bytes, 0, bytes.Length);
          }
      }
  }
  </code></pre>
  
  <p>In regards to the source code, <code>this.fileName = c:\Audio.wav</code> and the <code>newFileName</code> is <code>c:\Audio.wav.gz</code> (but have also tried <code>c:\audio.gz</code>)</p>