using EnumerableToStream; var enumerable = new [] {"Hello, ", "world!"}; Stream s = enumerable.ToStream();
$ dotnet add package EnumerableToStreamConverts an IEnumerable<string> to a Stream:
using EnumerableToStream;
IEnumerable<string> enumerable = new [] {"Hello, ", "world!"};
Stream stream = enumerable.ToStream();
enumerable.ToStream(Encoding.UTF8);IEnumerable and IAsyncEnumerable.
If you use the async version, you will need to call stream.ReadAsync() rather than Read().Streaming query results to the client in a memory efficient manner:
public IActionResult Get()
{
IEnumerable<string> lines = GetLines();
Stream stream = lines.AddLineEndings().ToStream();
return File(stream, "text/csv");
}