public async virtual Task DownloadToAsync(Stream fileStream, CancellationToken? cancellationToken = null, Dictionary<string, object> transferMetadata = null) { var downloadQuery = CreateDownloadQuery(); var totalBytesToDownload = Item.FileSizeBytes.GetValueOrDefault(); var progress = new TransferProgress(totalBytesToDownload, transferMetadata); using (var stream = await downloadQuery.ExecuteAsync(cancellationToken)) { if (stream != null) { int bytesRead; var buffer = new byte[Config.BufferSize]; do { bytesRead = await stream.ReadAsync(buffer, 0, buffer.Length, cancellationToken ?? CancellationToken.None); if (bytesRead > 0) { fileStream.Write(buffer, 0, bytesRead); NotifyProgress(progress.UpdateBytesTransferred(bytesRead)); await TryPauseAsync(cancellationToken); } } while (bytesRead > 0); } } NotifyProgress(progress.MarkComplete()); }
public async Task DownloadToAsync(Stream fileStream, CancellationToken?cancellationToken = null, Dictionary <string, object> transferMetadata = null) { var downloadQuery = CreateDownloadQuery(); var totalBytesToDownload = Item.FileSizeBytes.GetValueOrDefault(); var progress = new TransferProgress(totalBytesToDownload, transferMetadata); using (var stream = await downloadQuery.ExecuteAsync(cancellationToken)) { if (stream != null) { int bytesRead; var buffer = new byte[Config.BufferSize]; do { bytesRead = await stream.ReadAsync(buffer, 0, buffer.Length, cancellationToken ?? CancellationToken.None); if (bytesRead > 0) { fileStream.Write(buffer, 0, bytesRead); NotifyProgress(progress.UpdateBytesTransferred(bytesRead)); await TryPauseAsync(cancellationToken); } } while (bytesRead > 0); } } NotifyProgress(progress.MarkComplete()); }
public override void DownloadTo(Stream fileStream, Dictionary <string, object> transferMetadata = null) { var downloadQuery = CreateDownloadQuery(); var totalBytesToDownload = Item.FileSizeBytes.GetValueOrDefault(); var progress = new TransferProgress(totalBytesToDownload, transferMetadata); using (var stream = downloadQuery.Execute()) { if (stream != null) { int bytesRead; var buffer = new byte[Config.BufferSize]; do { TryPause(); bytesRead = stream.Read(buffer, 0, buffer.Length); if (bytesRead > 0) { fileStream.Write(buffer, 0, bytesRead); NotifyProgress(progress.UpdateBytesTransferred(bytesRead)); } } while (bytesRead > 0); } } NotifyProgress(progress.MarkComplete()); }
public override void DownloadTo(Stream fileStream, Dictionary<string, object> transferMetadata = null) { var downloadQuery = CreateDownloadQuery(); var totalBytesToDownload = Item.FileSizeBytes.GetValueOrDefault(); var progress = new TransferProgress(totalBytesToDownload, transferMetadata); using (var stream = downloadQuery.Execute()) { if (stream != null) { int bytesRead; var buffer = new byte[Config.BufferSize]; do { TryPause(); bytesRead = stream.Read(buffer, 0, buffer.Length); if (bytesRead > 0) { fileStream.Write(buffer, 0, bytesRead); NotifyProgress(progress.UpdateBytesTransferred(bytesRead)); } } while (bytesRead > 0); } } NotifyProgress(progress.MarkComplete()); }