private async Task DownloadToStreamHelperAsync(FileInfo fileinfo, Stream destination, DownloadOptions options, CancellationToken cancelToken) { Ensure.IsNotNull(options, nameof(options)); using (var source = new DownloadStreamForwardOnly(this, fileinfo, options)) { var count = source.Length; var buffer = new byte[fileinfo.ChunkSizeBytes]; while (count > 0) { var partialCount = (int)Math.Min(buffer.Length, count); await source.ReadAsync(buffer, 0, partialCount, cancelToken).ConfigureAwait(false); await destination.WriteAsync(buffer, 0, partialCount, cancelToken).ConfigureAwait(false); count -= partialCount; } await source.CloseAsync(cancelToken).ConfigureAwait(false); } }
private async Task DownloadToStreamHelperAsync(FileInfo fileinfo, Stream destination, DownloadOptions options, CancellationToken cancelToken) { Ensure.IsNotNull(options, nameof(options)); using( var source = new DownloadStreamForwardOnly(this, fileinfo, options) ) { var count = source.Length; var buffer = new byte[fileinfo.ChunkSizeBytes]; while( count > 0 ) { var partialCount = (int)Math.Min(buffer.Length, count); await source.ReadAsync(buffer, 0, partialCount, cancelToken).ConfigureAwait(false); await destination.WriteAsync(buffer, 0, partialCount, cancelToken).ConfigureAwait(false); count -= partialCount; } await source.CloseAsync(cancelToken).ConfigureAwait(false); } }