Skip to content

Use the Google Cloud Storage as a JSON object storage.

License

Notifications You must be signed in to change notification settings

Achneoder/clobs

Repository files navigation

GCP Object Storage

npm Build Coverage Status

This package is intended for use in GCP Cloud Functions and to write and read JavaScript objects as JSON files to/from Cloud Storage.

Installation

npm install gcp-object-storage

Usage

JavaScript

const gcpObjectStorage = new require('gcp-object-storage');
const objectReader = new gcpObjectStorage.ObjectReader();
const objectWriter = new gcpObjectStorage.ObjectWriter();

const options = {
  contentType: 'application/x-font-ttf',
  metadata: {
    my: 'custom',
    properties: 'go here'
  },
  public: true
};

// providing optional metadata
objectWriter.writeObject({ any: 'data' }, 'my-gcp-bucket', 'folder/to/my/file.json', options);

// without metadata
objectWriter.writeObject({ any: 'data' }, 'my-gcp-bucket', 'folder/to/my/file.json');

objectReader.readObject('my-gcp-bucket', 'folder/to/my/file.json');
// Object { any: "data" }

TypeScript

import { ObjectWriter, ObjectReader, IWriteOptions } from 'gcp-object-storage';

const options: IWriteOptions = {
  contentType: 'application/x-font-ttf',
  metadata: {
    my: 'custom',
    properties: 'go here'
  },
  public: true
};
new ObjectWriter()
  .writeObject({ any: 'data' }, 'my-gcp-bucket', 'folder/to/my/file.json', options)
  .then(() => new ObjectReader().readObject('my-gcp-bucket', 'folder/to/my/file.json'))
  .then((data: any) => console.log(data));
// Object { any: "data" }

Test

npm run test

About

Use the Google Cloud Storage as a JSON object storage.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •