title: Write file from assembly resource stream to disk
body: <p>I can't seem to find a more efficient way to "copy" an embedded resource to disk, than the following:</p>
  
  <pre><code>using (BinaryReader reader = new BinaryReader(
      assembly.GetManifestResourceStream(@"Namespace.Resources.File.ext")))
  {
      using (BinaryWriter writer
          = new BinaryWriter(new FileStream(path, FileMode.Create)))
      {
          long bytesLeft = reader.BaseStream.Length;
          while (bytesLeft &gt; 0)
          {
              // 65535L is &lt; Int32.MaxValue, so no need to test for overflow
              byte[] chunk = reader.ReadBytes((int)Math.Min(bytesLeft, 65536L));
              writer.Write(chunk);
  
              bytesLeft -= chunk.Length;
          }
      }
  }
  </code></pre>
  
  <p>There appears to be no more direct way to do the copy, unless I'm missing something...</p>