int64_t GcsUtil::GetObjectSize()

in e2e-examples/gcs/dummy_server/gcs_util.cc [52:70]


int64_t GcsUtil::GetObjectSize(absl::string_view bucket,
                               absl::string_view object) {
  std::string name = std::string(GetBasenameWithoutExt(object));

  // Parse the object name into num and unit (e.g. 100KB => 100 and KB)
  std::smatch match;
  if (!std::regex_match(name, match, kSizeRegex)) {
    return -1;
  }

  // Calculate the byte size with num and unit
  std::string num_part = match.str(1);
  std::string unit_part = match.str(2);
  int64_t num;
  if (!absl::SimpleAtoi(num_part, &num)) return -1;
  int64_t multiplier = GetUnitMultiplier(unit_part);
  if (multiplier == 0) return -1;
  return num * multiplier;
}