void CopyFileWithChecksum (Stream input, string to, string from, ICodePragmaGenerator pragmaGenerator)
{
if (pragmaGenerator == null) {
// This is BAD, BAD, BAD! CodeDOM API is really no good in this
// instance.
string filedata;
using (StreamReader sr = new StreamReader (input, WebEncoding.FileEncoding)) {
filedata = sr.ReadToEnd ();
}
var snippet = new CodeSnippetCompileUnit (filedata);
snippet.LinePragma = new CodeLinePragma (from, 1);
filedata = null;
AddCodeCompileUnit (snippet);
snippet = null;
return;
}
MD5 checksum = MD5.Create ();
using (FileStream fs = new FileStream (to, FileMode.Create, FileAccess.Write)) {
using (StreamWriter sw = new StreamWriter (fs, Encoding.UTF8)) {
using (StreamReader sr = new StreamReader (input, WebEncoding.FileEncoding)) {
int count = pragmaGenerator.ReserveSpace (from);
char[] src;
if (count > COPY_BUFFER_SIZE)
src = new char [count];
else
src = new char [COPY_BUFFER_SIZE];
sw.Write (src, 0, count);
do {
count = sr.Read (src, 0, COPY_BUFFER_SIZE);
if (count == 0) {
UpdateChecksum (src, 0, checksum, true);
break;
}
sw.Write (src, 0, count);
UpdateChecksum (src, count, checksum, false);
} while (true);
src = null;
}
}
}
pragmaGenerator.DecorateFile (to, from, checksum, Encoding.UTF8);
}