public void TransformAsync(Stream source, Stream detination, Func <Chunk, Chunk> clientCall) { if (source == null) { throw new System.ArgumentNullException(nameof(source)); } if (detination == null) { throw new System.ArgumentNullException(nameof(detination)); } if (clientCall == null) { throw new System.ArgumentNullException(nameof(clientCall)); } LazyRead lazyRead = new LazyRead(source, this._wordLength); var transformedBytes = this.LazzyTransform(lazyRead, clientCall); var buffered = new BufferedEnumerable <Chunk>(transformedBytes, 10); var orederedBytes = buffered.Values(); foreach (var chunk in orederedBytes) { detination.Write(chunk.Data, 0, chunk.Length); } }
private IEnumerable <Task <Chunk> > LazzyTransform(LazyRead read, Func <Chunk, Chunk> clientCall) { foreach (var chunk in read.Read()) { var task = new Task <Chunk>(() => { return(clientCall.Invoke(chunk)); }); task.Start(); yield return(task); } }