private void Validate()

in sdk/Common/ResumableDownloadManager.cs [319:355]


        private void Validate(DownloadObjectRequest request, ResumableDownloadContext resumableContext)
        {
            if (_conf.EnalbeMD5Check && !string.IsNullOrEmpty(resumableContext.ContentMd5))
            {
                using (var fs = File.Open(GetTempDownloadFile(request), FileMode.Open))
                {
                    string calcuatedMd5 = OssUtils.ComputeContentMd5(fs, fs.Length);
                    if (calcuatedMd5 != resumableContext.ContentMd5)
                    {
                        throw new OssException(string.Format("The Md5 of the downloaded file {0} does not match the expected. Expected:{1}, actual:{2}",
                                                             GetTempDownloadFile(request),
                                                             resumableContext.ContentMd5,
                                                             calcuatedMd5
                                                            ));
                    }
                }
            }
            else if (_conf.EnableCrcCheck && !string.IsNullOrEmpty(resumableContext.Crc64))
            {
                ulong calculatedCrc = 0;
                foreach (var part in resumableContext.PartContextList)
                {
                    calculatedCrc = Crc64.Combine(calculatedCrc, part.Crc64, part.Length);
                }

                if (calculatedCrc.ToString() != resumableContext.Crc64)
                {
                    throw new OssException(string.Format("The Crc64 of the downloaded file {0} does not match the expected. Expected:{1}, actual:{2}",
                                                           GetTempDownloadFile(request),
                                                           resumableContext.Crc64,
                                                           calculatedCrc
                                                          ));
                }
            }

            File.Move(GetTempDownloadFile(request), request.DownloadFile);
        }