4using System.Threading.Tasks;
44 this.input =
input ??
throw new ArgumentNullException(nameof(
input));
49 buffer =
new MemoryStream();
61 MemoryStream localBuffer;
65 if (localBuffer ==
null)
74 var bufferDispose = localBuffer.DisposeAsync();
80 public async Task<Stream>
GetResult(CancellationToken cancellationToken)
87 public async Task<MemoryStream>
GetOwnedResult(CancellationToken cancellationToken)
90 return new MemoryStream(sharedStream.GetBuffer(), 0, (
int)length,
false,
true);
111 MemoryStream localBuffer;
115 await
input.CopyToAsync(localBuffer, cancellationToken);
116 localBuffer.Seek(0, SeekOrigin.Begin);
118 return (localBuffer, localBuffer.Length);
IFileStreamProvider that provides a ISeekableFileStreamProvider from an input Stream.
volatile bool buffered
If buffer has been populated.
bool Disposed
If the ISeekableFileStreamProvider has had global::System.IAsyncDisposable.DisposeAsync called on it.
readonly SemaphoreSlim semaphore
The SemaphoreSlim used to synchronize writes to buffer.
async Task<(MemoryStream, long)> GetResultInternal(CancellationToken cancellationToken)
Gets the shared MemoryStream and its Stream.Length.
readonly Stream input
The original input Stream must remain valid for the lifetime of the BufferedFileStreamProvider or unt...
BufferedFileStreamProvider(Stream input)
Initializes a new instance of the BufferedFileStreamProvider class.
volatile MemoryStream buffer
The backing Stream.
async Task< Stream > GetResult(CancellationToken cancellationToken)
Gets the provided Stream. May be called multiple times, though cancelling any may cause all calls to ...
Task EnsureBuffered(CancellationToken cancellationToken)
Ensures the input Stream has been copied to the buffer.
async ValueTask DisposeAsync()
async Task< MemoryStream > GetOwnedResult(CancellationToken cancellationToken)
Gets the provided MemoryStream. May be called multiple times, though cancelling any may cause all cal...
Async lock context helper.
static async ValueTask< SemaphoreSlimContext > Lock(SemaphoreSlim semaphore, CancellationToken cancellationToken)
Asyncronously locks a semaphore .
IFileStreamProvider that provides MemoryStreams.