# HG changeset patch # User Alain Mazy # Date 1616145229 -3600 # Node ID d99afdf6d872acec302b07f2f6f956c214739085 # Parent 516b6e731bb56c67be16f53db0305f3d99fd85a7 ReadRange for AWS diff -r 516b6e731bb5 -r d99afdf6d872 Aws/AwsS3StoragePlugin.cpp --- 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(fromOffset) + "-" + boost::lexical_cast(fromOffset + size -1); + getObjectRequest.SetRange(range.c_str()); + } + getObjectRequest.SetResponseStreamFactory( [data, size]() { @@ -174,6 +192,8 @@ + + const char* AwsS3StoragePluginFactory::GetStoragePluginName() { return "AWS S3 Storage";