StreamExtensions.cs 566 B

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