Stop doing this :
using (var memory = new MemoryStream())
{
using (StreamWriter writer = new StreamWriter(memory, Encoding.ASCII))
{
foreach (var lineData in dataLines)
{
writer.WriteLine(lineData);
}
writer.Flush();
return memory.GetBuffer();
}
}
Just… do this instead.
return Encoding.ASCII.GetBytes(lineData.Join("\n\r"));
Trust me, it’s not worth using streams unless you explicitly need to.