2
0

StreamExtensions.cs 520 B

12345678910111213141516171819
  1. using System;
  2. using System.IO;
  3. using System.Reactive.Linq;
  4. namespace MediaBrowser.Net
  5. {
  6. public static class StreamExtensions
  7. {
  8. public static IObservable<byte[]> ReadBytes(this Stream stream, int count)
  9. {
  10. var buffer = new byte[count];
  11. return Observable.FromAsyncPattern((cb, state) => stream.BeginRead(buffer, 0, count, cb, state), ar =>
  12. {
  13. stream.EndRead(ar);
  14. return buffer;
  15. })();
  16. }
  17. }
  18. }