Mercurial > hg > orthanc-object-storage
comparison Aws/AwsS3StoragePlugin.cpp @ 41:d99afdf6d872
ReadRange for AWS
author | Alain Mazy <am@osimis.io> |
---|---|
date | Fri, 19 Mar 2021 10:13:49 +0100 |
parents | f55b2afdf53d |
children | 1c3e34f5c5c6 |
comparison
equal
deleted
inserted
replaced
40:516b6e731bb5 | 41:d99afdf6d872 |
---|---|
139 else | 139 else |
140 { | 140 { |
141 throw StoragePluginException(std::string("error while reading file ") + path_ + ": " + result.GetError().GetExceptionName().c_str() + " " + result.GetError().GetMessage().c_str()); | 141 throw StoragePluginException(std::string("error while reading file ") + path_ + ": " + result.GetError().GetExceptionName().c_str() + " " + result.GetError().GetMessage().c_str()); |
142 } | 142 } |
143 } | 143 } |
144 virtual void Read(char* data, size_t size) | 144 |
145 virtual void ReadWhole(char* data, size_t size) | |
146 { | |
147 _Read(data, size, 0, false); | |
148 } | |
149 | |
150 virtual void ReadRange(char* data, size_t size, size_t fromOffset) | |
151 { | |
152 _Read(data, size, fromOffset, true); | |
153 } | |
154 | |
155 void _Read(char* data, size_t size, size_t fromOffset, bool useRange) | |
145 { | 156 { |
146 Aws::S3::Model::GetObjectRequest getObjectRequest; | 157 Aws::S3::Model::GetObjectRequest getObjectRequest; |
147 getObjectRequest.SetBucket(bucketName_.c_str()); | 158 getObjectRequest.SetBucket(bucketName_.c_str()); |
148 getObjectRequest.SetKey(path_.c_str()); | 159 getObjectRequest.SetKey(path_.c_str()); |
149 | 160 |
161 if (useRange) | |
162 { | |
163 // https://developer.mozilla.org/en-US/docs/Web/HTTP/Range_requests | |
164 std::string range = std::string("bytes=") + boost::lexical_cast<std::string>(fromOffset) + "-" + boost::lexical_cast<std::string>(fromOffset + size -1); | |
165 getObjectRequest.SetRange(range.c_str()); | |
166 } | |
167 | |
150 getObjectRequest.SetResponseStreamFactory( | 168 getObjectRequest.SetResponseStreamFactory( |
151 [data, size]() | 169 [data, size]() |
152 { | 170 { |
153 std::unique_ptr<Aws::StringStream> | 171 std::unique_ptr<Aws::StringStream> |
154 istream(Aws::New<Aws::StringStream>(ALLOCATION_TAG)); | 172 istream(Aws::New<Aws::StringStream>(ALLOCATION_TAG)); |
169 throw StoragePluginException(std::string("error while reading file ") + path_ + ": " + result.GetError().GetExceptionName().c_str() + " " + result.GetError().GetMessage().c_str()); | 187 throw StoragePluginException(std::string("error while reading file ") + path_ + ": " + result.GetError().GetExceptionName().c_str() + " " + result.GetError().GetMessage().c_str()); |
170 } | 188 } |
171 } | 189 } |
172 | 190 |
173 }; | 191 }; |
192 | |
193 | |
174 | 194 |
175 | 195 |
176 | 196 |
177 const char* AwsS3StoragePluginFactory::GetStoragePluginName() | 197 const char* AwsS3StoragePluginFactory::GetStoragePluginName() |
178 { | 198 { |