Is there a way to convert IAsyncEnumerable to Stream?

Viewed 568

I'd like to send out a PUT request that has a Stream InputStream property, however, I only have an IAsyncStreamReader from a gRPC service which I can convert at most to an IAsyncEnumerable if I call ReadAllAsync() on it.

The only thing I can think of is:

await foreach (var item in requestStream.ReadAllAsync())
{
    await request.InputStream.WriteAsync(item.Data.ToByteArray());
}
// Send PUT request

In this case, however, I can only send the PUT request after the entire enumerable has been read which cannot be done for large amounts of data.

0 Answers
Related