Method OpenAsync
OpenAsync(string, FileMode, FileAccess, CancellationToken)
Opens a remote file as a seekable Stream (asynchronous reads and writes only). mode works as
for FileStream: Create creates or truncates, CreateNew fails if the
file exists, Append starts at the end. Disposing the stream closes the remote file.
public Task<Stream> OpenAsync(string path, FileMode mode, FileAccess access, CancellationToken cancellationToken = default)
Parameters
pathstringmodeFileModeaccessFileAccesscancellationTokenCancellationToken
Returns
Remarks
A stream opened only for reading reads ahead (up to 16 reads in flight) while it is read in order, one read at a time: a read while another is in progress throws InvalidOperationException. Writes are written behind: WriteAsync(ReadOnlyMemory<byte>, CancellationToken) returns once its requests are sent, keeping up to 16 in flight, so a write the server refuses is thrown by a later call: the next write that finds it, or at the latest FlushAsync(CancellationToken) or DisposeAsync(), which wait for every write in flight (as do reads and SetLength(long)). The stream is then faulted: every later call throws the same exception, and disposing still closes the remote file. Cancelling a write also faults the stream.