Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>As others have pointed out, you should read the first few bytes into an array.</p> <p>What should also be noted that you don't want to make a direct call to <a href="http://msdn.microsoft.com/en-us/library/system.io.stream.read.aspx" rel="nofollow noreferrer">Read</a> and <a href="https://stackoverflow.com/questions/3441338/how-do-i-hash-first-n-bytes-of-a-file/3441408#3441408"><em>assume</em> that the bytes have been read</a>.</p> <p><a href="http://www.yoda.arachsys.com/csharp/readbinary.html" rel="nofollow noreferrer">Rather, you want to make sure that the number of bytes that are returned are the number of bytes that you requested, and make another call to Read in the event that the number of bytes returned doesn't equal the initial number requested.</a></p> <p>Also, if you have rather large streams, you will want to create a <a href="http://en.wikipedia.org/wiki/Proxy_pattern" rel="nofollow noreferrer">proxy</a> for the <a href="http://msdn.microsoft.com/en-us/library/system.io.stream.aspx" rel="nofollow noreferrer">Stream class</a> where you pass it the underlying stream (the <a href="http://msdn.microsoft.com/en-us/library/system.io.filestream.aspx" rel="nofollow noreferrer">FileStream</a> in this case) and override the Read method to forward the call to the underlying stream <em>until</em> you read the number of bytes that you need to read. Then, when that number of bytes is returned, you would return -1 to indicate that there are no more bytes to be read.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload