HttpResult reading stream into memory

In the code of HttpResult here, there must be a better way than having to read an entire stream into memory?

Is there not a more efficient way of writing a stream out without having it in memory? There is also a .ToArray() on line 286 - would Spans or something not be better?

What are your thoughts?

Where is the entire stream read in memory? This is writing from the FileStream directly to the Response Stream:

If you check the latest version of HttpResult it’s no longer calling .ToArray():

It calls an efficient WriteToAsync() which tries to access the internal buffer before falling back to ToArray():

That’s as efficient as it can be made, Span doesn’t help here.