Stream.ReadAtLeast(Span<Byte>, Int32, Boolean) Method
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
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
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
.
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.
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.
When minimumBytes
is 0 (zero), this read operation will be completed without waiting for available data in the stream.
Product | Versions |
---|---|
.NET | 7, 8, 9, 10 |
.NET feedback
.NET is an open source project. Select a link to provide feedback: