@@ -63,6 +63,13 @@ std::string ExtractUploadId(std::string v) {
6363 return v.substr (pos + std::strlen (kRestField ));
6464}
6565
66+ gcs::ChecksumAlgorithm GetChecksumAlgorithm (bool enable_crc32c,
67+ bool enable_md5) {
68+ if (enable_crc32c) return gcs::ChecksumAlgorithm::kCrc32c ;
69+ if (enable_md5) return gcs::ChecksumAlgorithm::kMD5 ;
70+ return gcs::ChecksumAlgorithm::kNone ;
71+ }
72+
6673class ResumableUpload : public ThroughputExperiment {
6774 public:
6875 explicit ResumableUpload (google::cloud::storage::Client client,
@@ -80,14 +87,10 @@ class ResumableUpload : public ThroughputExperiment {
8087
8188 auto const start = std::chrono::system_clock::now ();
8289 auto timer = Timer::PerThread ();
83- auto writer =
84- client_.WriteObject (
90+ auto writer = client_.WriteObject (
8591 bucket_name, object_name,
8692 google::cloud::Options{}.set <gcs::UploadChecksumValidationOption>(
87- config.enable_crc32c
88- ? gcs::ChecksumAlgorithm::kCrc32c
89- : (config.enable_md5 ? gcs::ChecksumAlgorithm::kMD5
90- : gcs::ChecksumAlgorithm::kNone )));
93+ GetChecksumAlgorithm (config.enable_crc32c , config.enable_md5 )));
9194 auto upload_id = ExtractUploadId (writer.resumable_session_id ());
9295 for (std::int64_t offset = 0 ; offset < config.object_size ;
9396 offset += config.app_buffer_size ) {
@@ -159,10 +162,7 @@ class SimpleUpload : public ThroughputExperiment {
159162 client_.InsertObject (
160163 bucket_name, object_name, data,
161164 google::cloud::Options{}.set <gcs::UploadChecksumValidationOption>(
162- config.enable_crc32c
163- ? gcs::ChecksumAlgorithm::kCrc32c
164- : (config.enable_md5 ? gcs::ChecksumAlgorithm::kMD5
165- : gcs::ChecksumAlgorithm::kNone )));
165+ GetChecksumAlgorithm (config.enable_crc32c , config.enable_md5 )));
166166 auto const usage = timer.Sample ();
167167 auto generation = object_metadata
168168 ? std::to_string (object_metadata->generation ())
@@ -221,10 +221,7 @@ class DownloadObject : public ThroughputExperiment {
221221 client_.ReadObject (
222222 bucket_name, object_name, read_range,
223223 google::cloud::Options{}.set <gcs::DownloadChecksumValidationOption>(
224- config.enable_crc32c
225- ? gcs::ChecksumAlgorithm::kCrc32c
226- : (config.enable_md5 ? gcs::ChecksumAlgorithm::kMD5
227- : gcs::ChecksumAlgorithm::kNone )));
224+ GetChecksumAlgorithm (config.enable_crc32c , config.enable_md5 )));
228225 std::int64_t transfer_size = 0 ;
229226 while (!reader.eof () && !reader.bad ()) {
230227 reader.read (buffer.data (), buffer.size ());
0 commit comments