by
84k 18
0
6
1,140
0
Top 1% !
Popular
Famous
Tagged
Specified
Tuned
Popularity: 34392nd place

Published on:

Architecturex86_64
InputName0stream
InputName1buffer
InputName2offset
InputName3count
InputType0Stream
InputType1byte[]
InputType2int
InputType3int
LanguageC#
MethodNameReadStream
OutputTypeint
Windows VersionWindows7

ReadStream: Read specified amount of bytes from the specified stream.

Read specified amount of bytes from the specified stream.

 
<param name="stream">Source sream to read data from.</param>
<param name="buffer">Buffer to read data into.</param>
<param name="offset">Offset in buffer to put data into.</param>
<param name="count">Number of bytes to read.</param>
 
<returns>Returns total number of bytes read. It may be smaller than requested amount only
in the case if end of stream was reached.</returns>
 
<remarks><para>This tool function guarantees that requested number of bytes
was read from the source stream (.NET streams don't guarantee this and may return less bytes
than it was requested). Only in the case if end of stream was reached, the function
may return with less bytes read.</para>
</remarks>
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/1383598/ReadStream--Read-specified-amount-of-byt?startLine=0"></iframe>
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
/// <summary> /// Read specified amount of bytes from the specified stream. /// </summary> /// /// <param name="stream">Source sream to read data from.</param> /// <param name="buffer">Buffer to read data into.</param> /// <param name="offset">Offset in buffer to put data into.</param> /// <param name="count">Number of bytes to read.</param> /// /// <returns>Returns total number of bytes read. It may be smaller than requested amount only /// in the case if end of stream was reached.</returns> /// /// <remarks><para>This tool function guarantees that requested number of bytes /// was read from the source stream (.NET streams don't guarantee this and may return less bytes /// than it was requested). Only in the case if end of stream was reached, the function /// may return with less bytes read.</para> /// </remarks> /// public static int ReadStream( Stream stream, byte[] buffer, int offset, int count ) { int totalBytesRead = 0, bytesRead = 0; while ( totalBytesRead != count ) { bytesRead = stream.Read( buffer, offset + totalBytesRead, count - totalBytesRead ); if ( bytesRead == 0 ) { break; } totalBytesRead += bytesRead; } return totalBytesRead; }
If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus