StreamUtils.cs 462 B

123456789101112131415161718192021222324
  1. using System;
  2. using System.IO;
  3. namespace TriLib
  4. {
  5. public static class StreamUtils
  6. {
  7. public static byte[] ReadFullStream(Stream stream)
  8. {
  9. byte[] array = new byte[4096];
  10. byte[] result;
  11. using (MemoryStream memoryStream = new MemoryStream())
  12. {
  13. int count;
  14. while ((count = stream.Read(array, 0, array.Length)) > 0)
  15. {
  16. memoryStream.Write(array, 0, count);
  17. }
  18. result = memoryStream.ToArray();
  19. }
  20. return result;
  21. }
  22. }
  23. }