5using System.Threading.Tasks;
57 Task<CachedResponseStream>? localDownloadTask;
72 if (localDownloadTask !=
null)
77 result = await localDownloadTask;
85 await result.DisposeAsync();
93 public async ValueTask<Stream>
GetResult(CancellationToken cancellationToken)
98 Task<CachedResponseStream> localTask;
99 using (cancellationToken.Register(() =>
downloadCts.Cancel()))
107 return await localTask;
118 var response = await
httpClient.SendAsync(
requestMessage, HttpCompletionOption.ResponseHeadersRead, cancellationToken);
121 response.EnsureSuccessStatusCode();
Caches the Stream from a HttpResponseMessage for later use.
override void Dispose(bool disposing)
static async ValueTask< CachedResponseStream > Create(HttpResponseMessage response)
Asyncronously creates a new CachedResponseStream.
A IFileStreamProvider that represents the response of HttpRequestMessages.
volatile bool disposed
If DisposeAsync has been called.
Task< CachedResponseStream >? downloadTask
The Task<TResult> resulting in the downloaded MemoryStream.
RequestFileStreamProvider(HttpClient httpClient, HttpRequestMessage requestMessage)
Initializes a new instance of the RequestFileStreamProvider class.
readonly CancellationTokenSource downloadCts
The CancellationTokenSource used to abort the download.
async Task< CachedResponseStream > InitiateDownload(CancellationToken cancellationToken)
Initiate the download.
readonly HttpRequestMessage requestMessage
The IFileDownloader for the RequestFileStreamProvider.
readonly HttpClient httpClient
The HttpClient for the RequestFileStreamProvider.
async ValueTask DisposeAsync()
async ValueTask< Stream > GetResult(CancellationToken cancellationToken)
Gets the provided Stream. May be called multiple times, though cancelling any may cause all calls to ...
Interface for asynchronously consuming Streams of files.