3

Do you know good C/C++ library for Google Cloud Storage?

I can find Python library for it, but I can't find with C/C++ (or Objective-C).

Takashi Matsuo
  • 3,406
  • 16
  • 25
Wonil
  • 6,364
  • 2
  • 37
  • 55

3 Answers3

3

GCS has a supported C++ client library. The source is here: https://github.com/googleapis/google-cloud-cpp

The full documentation is here: https://cloud.google.com/storage/docs/reference/libraries#client-libraries-install-cpp

Here's an example of downloading an object and counting the number of lines:

#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;
}
Brandon Yarbrough
  • 37,021
  • 23
  • 116
  • 145
1

There is a list of Google's libraries (including Objective C) here.

Cebjyre
  • 6,552
  • 3
  • 32
  • 57
0

In the Gnome tree there is an OAuth2 library written in C:

http://git.gnome.org/browse/librest/tree/

This is part of Gnome's librest package, a library that facilitates REST transactions. I have not used it myself, but here are a few observations:

It looks like you will need to use automake to build a .configure. The docs say to just run the configure script but the docs are pretty old. It is still being developed (the most recent check in was December 2012).

If you do try it please report your experiences. (Thank you in advance!)

David V
  • 486
  • 4
  • 17
  • Thanks for your information. In fact, I finished my task by using Amazon S3 instead of Google Cloud Storage. There is open source C library for S3 - http://aws.amazon.com/developertools/1648. – Wonil Dec 06 '12 at 08:04