Bewerken

Share via


Stream.ReadAtLeast(Span<Byte>, Int32, Boolean) Method

Definition

Reads at least a minimum number of bytes from the current stream and advances the position within the stream by the number of bytes read.

public int ReadAtLeast (Span<byte> buffer, int minimumBytes, bool throwOnEndOfStream = true);
member this.ReadAtLeast : Span<byte> * int * bool -> int
Public Function ReadAtLeast (buffer As Span(Of Byte), minimumBytes As Integer, Optional throwOnEndOfStream As Boolean = true) As Integer

Parameters

buffer
Span<Byte>

A region of memory. When this method returns, the contents of this region are replaced by the bytes read from the current stream.

minimumBytes
Int32

The minimum number of bytes to read into the buffer.

throwOnEndOfStream
Boolean

true to throw an exception if the end of the stream is reached before reading minimumBytes of bytes; false to return less than minimumBytes when the end of the stream is reached. The default is true.

Returns

The total number of bytes read into the buffer. This is guaranteed to be greater than or equal to minimumBytes when throwOnEndOfStream is true. This will be less than minimumBytes when the end of the stream is reached and throwOnEndOfStream is false. This can be less than the number of bytes allocated in the buffer if that many bytes are not currently available.

Exceptions

minimumBytes is negative, or is greater than the length of buffer.

throwOnEndOfStream is true and the end of the stream is reached before reading minimumBytes bytes of data.

Remarks

When minimumBytes is 0 (zero), this read operation will be completed without waiting for available data in the stream.

Applies to