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 ValueTask<Stream>
GetResult(CancellationToken cancellationToken)
87 public async ValueTask<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 (
Stream: localBuffer, StreamLength: localBuffer.Length);
126 StreamLength: localBuffer.Length);
IFileStreamProvider that provides a ISeekableFileStreamProvider from an input Stream.
volatile? MemoryStream buffer
The backing Stream.
volatile bool buffered
If buffer has been populated.
async ValueTask< MemoryStream > GetOwnedResult(CancellationToken cancellationToken)
Gets the provided MemoryStream. May be called multiple times, though cancelling any may cause all cal...
async ValueTask<(MemoryStream Stream, long StreamLength)> GetResultInternal(CancellationToken cancellationToken)
Gets the shared MemoryStream and its Stream.Length.
bool Disposed
If the ISeekableFileStreamProvider has had global::System.IAsyncDisposable.DisposeAsync called on it.
async ValueTask< Stream > GetResult(CancellationToken cancellationToken)
Gets the provided Stream. May be called multiple times, though cancelling any may cause all calls to ...
readonly SemaphoreSlim semaphore
The SemaphoreSlim used to synchronize writes to buffer.
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.
Task EnsureBuffered(CancellationToken cancellationToken)
Ensures the input Stream has been copied to the buffer.
async ValueTask DisposeAsync()
Async lock context helper.
static async ValueTask< SemaphoreSlimContext > Lock(SemaphoreSlim semaphore, CancellationToken cancellationToken)
Asyncronously locks a semaphore .
IFileStreamProvider that provides MemoryStreams.