title: FileStream.Read() - bytes read
body: <p><code>FileStream.Read()</code> returns the amount of bytes read, but... is there any situation other than having reached the end of file, that it will read less bytes than the number of bytes requested <strong>and not throw an exception</strong>?</p>
  
  <p>the documentation says: </p>
  
  <blockquote>
    <p>The Read method returns zero only after reaching the end of the stream. Otherwise, Read always reads at least one byte from the stream before returning. If no data is available from the stream upon a call to Read, the method will block until at least one byte of data can be returned. An implementation is free to return fewer bytes than requested even if the end of the stream has not been reached.</p>
  </blockquote>
  
  <p>But this doesn't quite explain in what situations data would be unavailable and cause the method to block until it can read again. I mean, shouldn't most situations where data is unavailable force an exception?</p>
  
  <p>What are real situations where comparing the number of bytes read against the number of expected bytes could differ (assuming that we're already checking for end of file when we mention number of bytes expected)?</p>
  
  <p><strong>EDIT:</strong> A bit more information, reason why I'm asking this is because I've come across a bit of code where the developer pretty much did something like this:</p>
  
  <pre><code>bytesExpected = (remainingBytesInFile &gt; 94208 ? 94208 : remainingBytesInFile
  while (bytesRead &lt; bytesExpected)
  {
        bytesRead += fileStream.Read(buffer, bytesRead, bytesExpected - bytesRead)
  }
  </code></pre>
  
  <p>Now, I can't see any advantage to having this while at all, I'd expect it to throw an exception if it can't read the number of bytes expected (bearing in mind it's already taking into account that there are those many bytes left to read)</p>
  
  <p>What would the reason one could possibly have for something like this? I'm sure I'm missing something</p>