2012-07-12 06:55:27 +00:00
|
|
|
using System;
|
|
|
|
using System.IO;
|
|
|
|
using System.Reactive.Linq;
|
|
|
|
|
2012-07-13 03:50:50 +00:00
|
|
|
namespace MediaBrowser.Common.Net
|
2012-07-12 06:55:27 +00:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
})();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|