gcp-object-storage
v0.3.5
Published
Use Google Cloud Storage as a JSON object storage. For use with Cloud Functions.
Downloads
42
Readme
GCP Object Storage
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