Posted By

dactivo on 05/18/11


Tagged


Versions (?)

read bytes


 / Published in: C#
 

  1. public static byte[] ReadFully(this Stream stream)
  2. {
  3. using (MemoryStream memoryStream = new MemoryStream())
  4. {
  5. byte[] buffer = new byte[8192];
  6. int bytesRead;
  7. while ((bytesRead = stream.Read(buffer, 0, buffer.Length)) > 0)
  8. {
  9. memoryStream.Write(buffer, 0, bytesRead);
  10. }
  11. return memoryStream.ToArray();
  12. }
  13. }

Report this snippet  

You need to login to post a comment.