private List <RemainingBytes> GenerateByteRangesOfBlobToDownload(List <BlockSignature> sigsToReuseList, SizeBasedCompleteSignature cloudBlobSig, string containerName, string blobName) { var blobSize = AzureHelper.GetBlobSize(containerName, blobName); var remainingBytesList = new List <RemainingBytes>(); var allBlobSigs = cloudBlobSig.Signatures.Values.SelectMany(x => x.SignatureList).OrderBy(a => a.Offset).ToList(); var sortedSigs = (from sig in sigsToReuseList orderby sig.Offset ascending select sig).ToList(); long startOffsetToCopy = 0; // loop through all cloudBlobSigs. // If have a match in sigsToReuse, skip it. // otherwise, take note of offset and size to download. foreach (var sig in allBlobSigs) { var haveMatchingSig = sigsToReuseList.Any(s => s.MD5Signature.SequenceEqual(sig.MD5Signature)); if (!haveMatchingSig) { // if no match then we need to copy everything from startOffsetToCopy to sig.Offset + sig.Size remainingBytesList.Add(new RemainingBytes() { BeginOffset = startOffsetToCopy, EndOffset = sig.Offset + sig.Size - 1 }); startOffsetToCopy = sig.Offset + sig.Size; } else { // we have a match therefore dont need to copy the data. // change startOffsetToCopy to just after current sig. startOffsetToCopy = sig.Offset + sig.Size; } } return(remainingBytesList); }