Skip to content

An example on Multi-Shard Upload from a memory buffer #6718

Answered by coryan
wkyu2kg asked this question in Q&A
Discussion options

You must be logged in to vote

You would need to do something like this:

namespace gcs = ::google::cloud::storage;

google::cloud::StatusOr<gcs::ObjectMetadata> MultiShardUpload(
    gcs::Client client, std::string const& bucket, std::string const& object,
    std::string const& scratch_area_prefix,
    int shard_count, std::string const& buffer) {
  auto const shard_size = buffer.size() / shard_count; // maybe adjust shard_count and shard_size if too small
  std::vector<std::size_t> offset(shard_count);
  std::iota(offset.begin(), offset.end(), 0);
  std::transform(offset.begin(), offset.end(), offset.begin(), [&](auto v) { return v * shard_size; });

  std::vector<std::future<StatusOr<gcs::ObjectMetadata>> tasks(shar…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by coryan
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants