0.3.5 • Published 3 years ago

gcp-object-storage v0.3.5

Weekly downloads
5
License
MIT
Repository
github
Last release
3 years ago

GCP Object Storage

npm Build Status 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
0.3.5

3 years ago

0.3.4

4 years ago

0.3.3

4 years ago

0.3.2

4 years ago

0.3.1

4 years ago

0.3.0

4 years ago

0.2.0

4 years ago

0.2.0-1

4 years ago

0.2.0-0

4 years ago

0.1.0

4 years ago