title: Converting file into Base64String and back again
body: <p>The title says it all:</p>
  
  <ol>
  <li>I read in a tar.gz archive like so </li>
  <li>break the file into an array of bytes</li>
  <li>Convert those bytes into a Base64 string</li>
  <li>Convert that Base64 string back into an array of bytes</li>
  <li>Write those bytes back into a new tar.gz file</li>
  </ol>
  
  <p>I can confirm that both files are the same size (the below method returns true) but I can no longer extract the copy version.</p>
  
  <p>Am I missing something?</p>
  
  <pre><code>Boolean MyMethod(){
      using (StreamReader sr = new StreamReader("C:\...\file.tar.gz")) {
          String AsString = sr.ReadToEnd();
          byte[] AsBytes = new byte[AsString.Length];
          Buffer.BlockCopy(AsString.ToCharArray(), 0, AsBytes, 0, AsBytes.Length);
          String AsBase64String = Convert.ToBase64String(AsBytes);
  
          byte[] tempBytes = Convert.FromBase64String(AsBase64String);
          File.WriteAllBytes(@"C:\...\file_copy.tar.gz", tempBytes);
      }
      FileInfo orig = new FileInfo("C:\...\file.tar.gz");
      FileInfo copy = new FileInfo("C:\...\file_copy.tar.gz");
      // Confirm that both original and copy file have the same number of bytes
      return (orig.Length) == (copy.Length);
  }
  </code></pre>
  
  <p>EDIT: The working example is much simpler (Thanks to @T.S.):</p>
  
  <pre><code>Boolean MyMethod(){
      byte[] AsBytes = File.ReadAllBytes(@"C:\...\file.tar.gz");
      String AsBase64String = Convert.ToBase64String(AsBytes);
  
      byte[] tempBytes = Convert.FromBase64String(AsBase64String);
      File.WriteAllBytes(@"C:\...\file_copy.tar.gz", tempBytes);
  
      FileInfo orig = new FileInfo(@"C:\...\file.tar.gz");
      FileInfo copy = new FileInfo(@"C:\...\file_copy.tar.gz");
      // Confirm that both original and copy file have the same number of bytes
      return (orig.Length) == (copy.Length);
  }
  </code></pre>
  
  <p>Thanks!</p>