1 /*
2  * Copyright 2009-2017 Alibaba Cloud All rights reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 #include <alibabacloud/oss/Export.h>
19 #include <alibabacloud/oss/OssRequest.h>
20 #include <alibabacloud/oss/model/ObjectMetaData.h>
21 
22 namespace AlibabaCloud
23 {
24 namespace OSS
25 {
26     class ALIBABACLOUD_OSS_EXPORT DownloadObjectRequest : public OssResumableBaseRequest
27     {
28     public:
29         DownloadObjectRequest(const std::string& bucket, const std::string& key,
30             const std::string& filePath);
31         DownloadObjectRequest(const std::string& bucket, const std::string& key,
32             const std::string& filePath, const std::string& checkpointDir,
33             const uint64_t partSize, const uint32_t threadNum);
34         DownloadObjectRequest(const std::string& bucket, const std::string& key,
35             const std::string& filePath, const std::string& checkpointDir);
36 
FilePath()37         const std::string& FilePath() const { return filePath_; }
TempFilePath()38         const std::string& TempFilePath() const { return tempFilePath_; }
39 
40         DownloadObjectRequest(const std::string& bucket, const std::string& key,
41             const std::wstring& filePath);
42         DownloadObjectRequest(const std::string& bucket, const std::string& key,
43             const std::wstring& filePath, const std::wstring& checkpointDir,
44             const uint64_t partSize, const uint32_t threadNum);
45         DownloadObjectRequest(const std::string& bucket, const std::string& key,
46             const std::wstring& filePath, const std::wstring& checkpointDir);
47 
FilePathW()48         const std::wstring& FilePathW() const { return filePathW_; }
TempFilePathW()49         const std::wstring& TempFilePathW() const { return tempFilePathW_; }
50 
Content()51         std::shared_ptr<std::iostream> Content() { return content_; }
RangeIsSet()52         bool RangeIsSet() const{ return rangeIsSet_; }
RangeStart()53         int64_t RangeStart() const { return range_[0]; }
RangeEnd()54         int64_t RangeEnd() const { return range_[1]; }
ModifiedSinceConstraint()55         const std::string& ModifiedSinceConstraint() const { return modifiedSince_; }
UnmodifiedSinceConstraint()56         const std::string& UnmodifiedSinceConstraint() const { return unmodifiedSince_; }
MatchingETagsConstraint()57         const std::vector<std::string>& MatchingETagsConstraint() const { return matchingETags_; }
NonmatchingETagsConstraint()58         const std::vector<std::string>& NonmatchingETagsConstraint() const { return nonmatchingETags_;}
ResponseHeaderParameters()59         const std::map<std::string, std::string>& ResponseHeaderParameters() const { return responseHeaderParameters_; }
60 
61         void setRange(int64_t start, int64_t end);
62         void setModifiedSinceConstraint(const std::string& gmt);
63         void setUnmodifiedSinceConstraint(const std::string& gmt);
64         void setMatchingETagConstraints(const std::vector<std::string>& match);
65         void setNonmatchingETagConstraints(const std::vector<std::string>& match);
66         void addResponseHeaders(RequestResponseHeader header, const std::string& value);
67 
68     protected:
69         virtual int validate() const;
70 
71     private:
72         bool rangeIsSet_;
73         int64_t range_[2];
74         std::string modifiedSince_;
75         std::string unmodifiedSince_;
76         std::vector<std::string> matchingETags_;
77         std::vector<std::string> nonmatchingETags_;
78 
79         std::string filePath_;
80         std::string tempFilePath_;
81         std::shared_ptr<std::iostream> content_;
82 
83         std::map<std::string, std::string> responseHeaderParameters_;
84 
85         std::wstring filePathW_;
86         std::wstring tempFilePathW_;
87     };
88 }
89 }