An object-oriented programming language developed by Microsoft that can be used in .NET.
You can just use StreamReader and specify the encoding you of the data (ASCII here as per your example):
await PrintStream(new MemoryStream(Encoding.ASCII.GetBytes("Hello world!")));
await PrintStream(new FileStream("./test.txt", FileMode.Open));
await Console.Out.WriteLineAsync();
async Task PrintStream(Stream stream) {
var reader = new StreamReader(stream, Encoding.ASCII);
Console.WriteLine(await reader.ReadToEndAsync());
}
Disclaimer: If the data isn't too big this method is fine, but if you're dealing with huge files (like a binary image file) then you should prefer the Read option so you can read the data in chunks to avoid dragging too much into memory at one time.