StreamExtensionMethod.cs 521 B

1234567891011121314151617181920
  1. using System.IO;
  2. namespace VCommon.IO
  3. {
  4. public static class StreamExtensionMethod
  5. {
  6. public static byte[] ReadFully(this Stream input)
  7. {
  8. //REF stackoverflow.com/a/221941/2430943
  9. var buffer = new byte[16 * 1024];
  10. using (var ms = new MemoryStream())
  11. {
  12. int read;
  13. while ((read = input.Read(buffer, 0, buffer.Length)) > 0) ms.Write(buffer, 0, read);
  14. return ms.ToArray();
  15. }
  16. }
  17. }
  18. }