MCPcopy Create free account
hub / github.com/GoogleCloudPlatform/cpp-samples / task

Function task

gcs-fast-transfers/download.cc:57–76  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

55}
56
57std::string task(std::int64_t offset, std::int64_t length,
58 std::string const& bucket, std::string const& object, int fd) {
59 auto client = gcs::Client::CreateDefaultClient().value();
60 auto is = client.ReadObject(bucket, object,
61 gcs::ReadRange(offset, offset + length));
62
63 std::vector<char> buffer(1024 * 1024L);
64 std::int64_t count = 0;
65 std::int64_t write_offset = offset;
66 do {
67 is.read(buffer.data(), buffer.size());
68 if (is.bad()) break;
69 count += is.gcount();
70 check_system_call("pwrite()",
71 ::pwrite(fd, buffer.data(), is.gcount(), write_offset));
72 write_offset += is.gcount();
73 } while (not is.eof());
74 return fmt::format("Download range [{}, {}] got {}/{} bytes", offset,
75 offset + length, count, length);
76}
77
78using ::gcs_fast_transfers::file_info;
79using ::gcs_fast_transfers::format_size;

Callers

nothing calls this directly

Calls 1

check_system_callFunction · 0.85

Tested by

no test coverage detected