title: How to read last block of Stream.Read
body: <p>I wrote an extension method as following</p>
  <pre class="lang-cs prettyprint-override"><code>public static void ReadBlock(this Stream stream, Action&lt;string&gt; action, int bufferSize = 8192)
  {
      var buffer = new byte[bufferSize];
      while (true)
      {
          var count = stream.Read(buffer, 0, bufferSize);
          if (count == 0) break;
          var text = Encoding.ASCII.GetString(buffer);
          action(text);
      }
  }
  </code></pre>
  <p>The problem I have is the last block which is often less than the size of the buffer is not read.
  and the code returns the n-1 block again (the last buffer).</p>
  <p>Can anyone help me to read a stream block by block in the correct way based on buffer size?</p>