private void DownloadByteRange(string bucketName, string objectName,
long firstByte, long lastByte, string localPath = null)
{
var storageClient = StorageClient.Create();
localPath = localPath ??
$"{Path.GetFileName(objectName)}_{firstByte}-{lastByte}";
// Create an HTTP request for the media, for a limited byte range.
StorageService storage = storageClient.Service;
var uri = new Uri(
$"{storage.BaseUri}b/{bucketName}/o/{objectName}?alt=media");
var request = new HttpRequestMessage() { RequestUri = uri };
request.Headers.Range =
new System.Net.Http.Headers.RangeHeaderValue(firstByte,
lastByte);
using (var outputFile = File.OpenWrite(localPath))
{
// Use the HttpClient in the storage object because it supplies
// all the authentication headers we need.
var response = storage.HttpClient.SendAsync(request).Result;
response.Content.CopyToAsync(outputFile, null).Wait();
Console.WriteLine($"downloaded {objectName} to {localPath}.");
}
}