title: MemoryStream CopyTo only partially writing
body: <p>I'm about to lose my freaking mind. I've been trying to get GzipStream to compress a string for the past hour, but for whatever reason, it refuses to write the entire byte array to the memory stream. At first I thought it had something to do with the using statements, but even after removing them it didn't seem to make a difference. </p>
  
  <p><strong>Initial config:</strong></p>
  
  <pre><code>var str = "Here is a relatively simple string to compress";
  byte[] compressedBytes;
  string returnedData;
  
  var bytes = Encoding.UTF8.GetBytes(str);
  </code></pre>
  
  <p><strong>Works correctly (writes 64 length byte array):</strong></p>
  
  <pre><code>using (var msi = new MemoryStream(bytes))
  using (var mso = new MemoryStream()) {
     using (var gs = new GZipStream(mso, CompressionMode.Compress)) {
         msi.CopyTo(gs);
     }
  
     compressedBytes = mso.ToArray();
  }
  </code></pre>
  
  <p><strong>Fails (writes 10 length byte array):</strong></p>
  
  <pre><code>using(var mso = new MemoryStream())
  using(var msi = new MemoryStream(bytes))
  using(var zip = new GZipStream(mso, CompressionMode.Compress))
  {
      msi.CopyTo(zip);
      compressedBytes = mso.ToArray();
  }
  </code></pre>
  
  <p><strong>Also fails (writes 10 length byte array):</strong></p>
  
  <pre><code>var mso = new MemoryStream();
  var msi = new MemoryStream(bytes);
  var zip = new GZipStream(mso, CompressionMode.Compress);
  
  msi.CopyTo(zip);
  compressedBytes = mso.ToArray();
  </code></pre>
  
  <p>Can somebody explain why the first one works but in the other two I'm getting these incomplete arrays? Is something getting disposed out from under me? For that matter, is there a way for me to avoid using two memorystreams?</p>
  
  <p>Thanks,
  Zoombini</p>