Mercurial > hg > orthanc-object-storage
changeset 41:d99afdf6d872
ReadRange for AWS
author | Alain Mazy <am@osimis.io> |
---|---|
date | Fri, 19 Mar 2021 10:13:49 +0100 |
parents | 516b6e731bb5 |
children | 822e29256ffb 4c71c5e2edce |
files | Aws/AwsS3StoragePlugin.cpp |
diffstat | 1 files changed, 21 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/Aws/AwsS3StoragePlugin.cpp Fri Mar 19 09:34:29 2021 +0100 +++ b/Aws/AwsS3StoragePlugin.cpp Fri Mar 19 10:13:49 2021 +0100 @@ -141,12 +141,30 @@ throw StoragePluginException(std::string("error while reading file ") + path_ + ": " + result.GetError().GetExceptionName().c_str() + " " + result.GetError().GetMessage().c_str()); } } - virtual void Read(char* data, size_t size) + + virtual void ReadWhole(char* data, size_t size) + { + _Read(data, size, 0, false); + } + + virtual void ReadRange(char* data, size_t size, size_t fromOffset) + { + _Read(data, size, fromOffset, true); + } + + void _Read(char* data, size_t size, size_t fromOffset, bool useRange) { Aws::S3::Model::GetObjectRequest getObjectRequest; getObjectRequest.SetBucket(bucketName_.c_str()); getObjectRequest.SetKey(path_.c_str()); + if (useRange) + { + // https://developer.mozilla.org/en-US/docs/Web/HTTP/Range_requests + std::string range = std::string("bytes=") + boost::lexical_cast<std::string>(fromOffset) + "-" + boost::lexical_cast<std::string>(fromOffset + size -1); + getObjectRequest.SetRange(range.c_str()); + } + getObjectRequest.SetResponseStreamFactory( [data, size]() { @@ -174,6 +192,8 @@ + + const char* AwsS3StoragePluginFactory::GetStoragePluginName() { return "AWS S3 Storage";