in awsio/csrc/io/s3/s3_io.cpp [177:207]
size_t readS3Client(uint64_t offset, size_t n, char *buffer) {
Aws::S3::Model::GetObjectRequest getObjectRequest;
getObjectRequest.WithBucket(this->bucket_name_.c_str())
.WithKey(this->object_name_.c_str());
std::string bytes = "bytes=";
bytes += std::to_string(offset) + "-" + std::to_string(offset + n - 1);
getObjectRequest.SetRange(bytes.c_str());
// When you don’t want to load the entire file into memory,
// you can use IOStreamFactory in AmazonWebServiceRequest to pass a
// lambda to create a string stream.
getObjectRequest.SetResponseStreamFactory(
[]() { return Aws::New<Aws::StringStream>("S3IOAllocationTag"); });
// get the object
auto getObjectOutcome = this->s3_client_->GetObject(getObjectRequest);
if (!getObjectOutcome.IsSuccess()) {
auto error = getObjectOutcome.GetError();
std::cout << "ERROR: " << error.GetExceptionName() << ": "
<< error.GetMessage() << std::endl;
return 0;
} else {
n = getObjectOutcome.GetResult().GetContentLength();
// read data as a block:
getObjectOutcome.GetResult().GetBody().read(buffer, n);
return n;
}
}