aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Controller/Net/StreamExtensions.cs
blob: 451a43acba277c538148e64f2ec23677b24fc8ce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
using System;
using System.Collections.Generic;
using System.IO;
using System.Reactive.Linq;

namespace MediaBrowser.Controller.Net
{
    public static class StreamExtensions
    {
        public static IObservable<byte[]> ReadBytes(this Stream stream, int count)
        {
            var buffer = new byte[count];
            return Observable.FromAsyncPattern((cb, state) => stream.BeginRead(buffer, 0, count, cb, state), ar =>
            {
                stream.EndRead(ar);
                return buffer;
            })();
        }
    }
}