in sdk/Common/ResumableDownloadManager.cs [80:144]
private void DoResumableDownloadSingleThread(DownloadObjectRequest request, ResumableDownloadContext resumableContext,
EventHandler<StreamTransferProgressArgs> downloadProgressCallback)
{
_downloadedBytes = resumableContext.GetDownloadedBytes();
if (!request.MatchingETagConstraints.Contains(resumableContext.ETag))
{
request.MatchingETagConstraints.Add(resumableContext.ETag);
}
long totalBytes = resumableContext.GetTotalBytes();
foreach (var part in resumableContext.PartContextList)
{
if (part.IsCompleted)
{
// is CRC is enabled and part.Crc64 is 0, then redownload the data
if (!_conf.EnableCrcCheck || part.Crc64 != 0)
{
continue;
}
}
using (Stream fs = File.Open(GetTempDownloadFile(request), FileMode.OpenOrCreate))
{
fs.Seek(part.Position, SeekOrigin.Begin);
var originalStream = fs;
if (downloadProgressCallback != null)
{
originalStream = _ossClient.SetupDownloadProgressListeners(fs,
totalBytes,
_downloadedBytes,
_conf.ProgressUpdateInterval,
downloadProgressCallback);
}
if (_conf.EnableCrcCheck)
{
originalStream = new Crc64Stream(originalStream, null, part.Length);
}
var getPartRequest = request.ToGetObjectRequest();
getPartRequest.SetRange(part.Position, part.Length + part.Position - 1);
var partResult = _ossClient.GetObject(getPartRequest);
WriteTo(partResult.Content, originalStream);
if (originalStream is Crc64Stream)
{
Crc64Stream crcStream = originalStream as Crc64Stream;
if (crcStream.CalculatedHash == null)
{
crcStream.CalculateHash();
}
part.Crc64 = BitConverter.ToUInt64(crcStream.CalculatedHash, 0);
}
}
part.IsCompleted = true;
resumableContext.Dump();
_downloadedBytes += part.Length;
}
Validate(request, resumableContext);
}