There is such code:
void DeadSecCoding(string strfile) { using (FileStream fs = new FileStream(strfile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite,1024*1024,true)) using (BinaryReader sr = new BinaryReader(fs)) { byte byte1; long nBytesRead = fs.Length; while (nBytesRead >0) { byte1 = sr.ReadByte(); int i = Convert.ToInt32(byte1); i *= 1234567; using (StreamWriter writer = new StreamWriter(strfile+".mql",true)) { writer.WriteAsync(i.ToString()+"@"); } nBytesRead--; } } }
Its meaning is: we read a byte from a stream, convert it to int, multiply int by a number, write to a text file, convert int to string with adding a label. The output file has the contents (plain text):
5372635@5272736@2437362@827463637@262627@
And so on. Everything is written in one line. The code is very slow, since StreamWriter is constantly opening. How to make writing to a file beyond the limits of the while construct so that when converting a large input file does not catch MemoryException?
I think to organize some intermediate buffer, write 8 * 1024 int (or byte) there and make a record in the foreach loop through the StreamWriter.
Can anyone have ideas on how to implement something like this, or ideas on how to do better?
Ps I have some thoughts, but I want to hear someone else's opinion. Thank!
writer.WriteAsync
withoutawait
simply wrong. - VladD