The example 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:
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)) > 0) {
int bytesWritten = myTransform.TransformBlock (inputBuffer, 0, 4, transformBuffer, 0);
outputFile.Write (transformBuffer, 0, bytesWritten);
}
myTransform.Clear ();
}
}
}
But the image can't be opened. What I'm doing wrong?