1
如何構造下面的代碼,以便我可以讀取塊中的所有流。 目前它一直返回相同的數據。不能前進。從流中異步反覆讀取?
public static IObservable<byte[]> AsyncRead(this Stream stream, int bufferSize)
{
var asyncRead = Observable.FromAsyncPattern<byte[], int, int, int>(stream.BeginRead, stream.EndRead);
var buffer = new byte[bufferSize];
return asyncRead(buffer, 0, bufferSize)
.Select(cbRead =>
{
var dataChunk = new byte[cbRead];
Buffer.BlockCopy(buffer, 0, dataChunk, 0, cbRead);
return dataChunk;
})
.Repeat()
.TakeWhile(dataChunk => dataChunk.Length > 0);
}