Skip to content

StreamExtensions.ReadExactlyAsync Method ​

Definition ​

Reads exactly length bytes from the stream asynchronously, throwing EndOfStreamException if the end of the stream has been reached.

c#
public static ValueTask<Byte[]> ReadExactlyAsync(this Stream stream, int length, CancellationToken cancellationToken = null);

Parameters ​

NameTypeDescription
streamStream
lengthInt32The number of bytes to read.
cancellationTokenCancellationTokenA cancellation token.

Returns ​

ValueTask<Byte[]>

A byte array containing the bytes read from the stream.