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.

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

Parameters

Name Type Description
stream Stream
length Int32 The number of bytes to read.
cancellationToken CancellationToken A cancellation token.

Returns

ValueTask<Byte[]>

A byte array containing the bytes read from the stream.