gcp-object-storage
    TypeScript icon, indicating that this package has built-in type declarations

    0.3.5 • Public • Published

    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

    Install

    npm i gcp-object-storage

    DownloadsWeekly Downloads

    259

    Version

    0.3.5

    License

    MIT

    Unpacked Size

    12 kB

    Total Files

    14

    Last publish

    Collaborators

    • achneoder