title: Decode base64 filestream with FromBase64Transform
body: <p>The <a href="https://msdn.microsoft.com/en-us/library/system.security.cryptography.frombase64transform%28v=vs.110%29.aspx" rel="nofollow">example</a> from MSDN seems to read the whole file into memory. I don't want that. The file should be processed block by block. Therefore I tried to rewrite the example:</p>
  
  <pre><code>using (FromBase64Transform myTransform = new FromBase64Transform (FromBase64TransformMode.IgnoreWhiteSpaces)) {
      byte[] transformBuffer = new byte[myTransform.OutputBlockSize];
  
      using (FileStream inputFile = File.OpenRead("/path/to/file/47311.b64")) {
          using(FileStream outputFile = File.OpenWrite("/path/to/file/47311.jpg")){
              int bytesRead;
              byte[] inputBuffer = new byte[4096];
              while ((bytesRead = inputFile.Read (inputBuffer, 0, 4096)) &gt; 0) {
                  int bytesWritten = myTransform.TransformBlock (inputBuffer, 0, 4, transformBuffer, 0);
                  outputFile.Write (transformBuffer, 0, bytesWritten);
              }
  
              myTransform.Clear ();
          }
      }
  }
  </code></pre>
  
  <p>But the image can't be opened. What I'm doing wrong?</p>