1 #pragma once 2 /* 3 * Copyright 2009-2017 Alibaba Cloud All rights reserved. 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 #pragma once 19 #include "ResumableBaseWorker.h" 20 21 namespace AlibabaCloud 22 { 23 namespace OSS 24 { 25 struct PartRecord { 26 int32_t partNumber; 27 int64_t offset; 28 int64_t size; 29 uint64_t crc64; 30 }; 31 typedef std::vector<PartRecord> PartRecordList; 32 struct DownloadRecord { 33 std::string opType; 34 std::string bucket; 35 std::string key; 36 std::string filePath; 37 std::string mtime; 38 uint64_t size; 39 uint64_t partSize; 40 PartRecordList parts; 41 std::string md5Sum; 42 int64_t rangeStart; 43 int64_t rangeEnd; 44 //crc64 45 }; 46 47 48 class ResumableDownloader : public ResumableBaseWorker 49 { 50 public: ResumableDownloader(const DownloadObjectRequest & request,const OssClientImpl * client,uint64_t objectSize)51 ResumableDownloader(const DownloadObjectRequest& request, const OssClientImpl *client, uint64_t objectSize) 52 : ResumableBaseWorker(objectSize, request.PartSize()), request_(request),client_(client), contentLength_(objectSize) 53 {} 54 55 GetObjectOutcome Download(); 56 57 protected: 58 void genRecordPath(); 59 int loadRecord(); 60 int validateRecord(); 61 int prepare(OssError& err); 62 void initRecord(); 63 int getPartsToDownload(OssError &err, PartRecordList &partsToDownload); 64 bool renameTempFile(); 65 static void DownloadPartProcessCallback(size_t increment, int64_t transfered, int64_t total, void *userData); 66 67 virtual GetObjectOutcome GetObjectWrap(const GetObjectRequest &request) const; 68 69 const DownloadObjectRequest request_; 70 DownloadRecord record_; 71 const OssClientImpl *client_; 72 uint64_t contentLength_; 73 }; 74 } 75 } 76