gpt4 book ai didi

google-cloud-storage - 谷歌云存储的 C/C++ 库

转载 作者:行者123 更新时间:2023-12-05 04:18:47 24 4
gpt4 key购买 nike

您知道 Google Cloud Storage 的优秀 C/C++ 库吗? ?

我可以找到 Python library为此,但我找不到 C/C++(或 Objective-C)。

最佳答案

GCS 有一个受支持的 C++ 客户端库。来源在这里:https://github.com/googleapis/google-cloud-cpp

完整文档在这里:https://cloud.google.com/storage/docs/reference/libraries#client-libraries-install-cpp

下面是一个下载对象并计算行数的例子:

#include "google/cloud/storage/client.h"
#include <iostream>
namespace gcs = google::cloud::storage;

int countLines(std::string bucket_name, std::string object_name) {
// Create aliases to make the code easier to read.
namespace gcs = google::cloud::storage;

// Create a client to communicate with Google Cloud Storage. This client
// uses the default configuration for authentication and project id.
google::cloud::StatusOr<gcs::Client> client =
gcs::Client::CreateDefaultClient();
if (!client) {
std::cerr << "Failed to create Storage Client, status=" << client.status()
<< "\n";
return 1;
}

gcs::ObjectReadStream stream = client.ReadObject(bucket_name, object_name);
int count = 0;
std::string line;
while (std::getline(stream, line, '\n')) {
++count;
}
return count;
}

关于google-cloud-storage - 谷歌云存储的 C/C++ 库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8632584/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com