Skip to content

PeekableStream.ReadAsync Method

Overloads

Name Description
ReadAsync(Byte[], Int32, Int32, CancellationToken) Asynchronously reads a sequence of bytes from the current stream, advances the position within the stream by the number of bytes read, and monitors cancellation requests.
ReadAsync(Memory<Byte>, CancellationToken) Asynchronously reads a sequence of bytes from the current stream, advances the position within the stream by the number of bytes read, and monitors cancellation requests.

ReadAsync(Byte[], Int32, Int32, CancellationToken)

Asynchronously reads a sequence of bytes from the current stream, advances the position within the stream by the number of bytes read, and monitors cancellation requests.

public override Task<int> ReadAsync(Byte[] buffer, int offset, int count, CancellationToken cancellationToken);

View source

Parameters

Name Type Description
buffer Byte[] The buffer to write the data into.
offset Int32 The byte offset in buffer at which to begin writing data from the stream.
count Int32 The maximum number of bytes to read.
cancellationToken CancellationToken The token to monitor for cancellation requests. The default value is None.

Returns

Task<Int32>

A task that represents the asynchronous read operation. The value of the TResult parameter contains the total number of bytes read into the buffer. The result value can be less than the number of bytes requested if the number of bytes currently available is less than the requested number, or it can be 0 (zero) if count is 0 or if the end of the stream has been reached.

ReadAsync(Memory<Byte>, CancellationToken)

Asynchronously reads a sequence of bytes from the current stream, advances the position within the stream by the number of bytes read, and monitors cancellation requests.

public override ValueTask<int> ReadAsync(Memory<Byte> buffer, CancellationToken cancellationToken = null);

Parameters

Name Type Description
buffer Memory<Byte> The region of memory to write the data into.
cancellationToken CancellationToken The token to monitor for cancellation requests. The default value is None.

Returns

ValueTask<Int32>

A task that represents the asynchronous read operation. The value of its Result property contains the total number of bytes read into the buffer. The result value can be less than the length of the buffer if that many bytes are not currently available, or it can be 0 (zero) if the length of the buffer is 0 or if the end of the stream has been reached.