nodestream-gcs

0.7.0 • Public • Published

Google Cloud Storage nodestream-gcs

NPM Version Build Status Coverage Status Documentation Status Built with GNU Make

Google Cloud Storage adapter for Nodestream

Identity:: gcs

API docs

Description

This adapter provides interface for Nodestream to transfer bytes between your app and Google Cloud Storage.

Usage

Installation

npm install --save nodestream-gcs

Configuration

When configuring Nodestream instance, you must specify at minimum the bucket on which you want to operate, and, as per GCS documentation, at least projectId, but preferably also keyFilename to have fully authenticated client functionality. All configuration options are passed along unmodified to the gcloud() function. No default values are provided.

const Nodestream = require('nodestream')
const nodestream = new Nodestream({
  adapter: 'gcs',
  config: {
    bucket: 'my-gcs-bucket',
    projectId: 'project-id-123',
    keyFilename: '/path/to/keyfile.json'
  }
})

Uploading

When uploading files, you may specify a directory and name for the upload. Both are optional - if no name is given, a random GUID will be generated.

You can also specify options for the createWriteStream() method via gcs object (this adapter's identity).

const file = fs.createReadStream('/users/me/profile-pic.png')
nodestream.upload(file, {
  directory: 'avatars',
  name: 'user-123.png',
  gcs: {
    gzip: true
  }
})

Downloading

You can also specify options for the createReadStream() method via gcs object (this adapter's identity) in the third argument.

const dest = fs.createWriteStream('/users/me/profile-pic.png')
nodestream.download('avatars/user-123.png', dest, {
  gcs: {
    start: 1000
  }
})
 
// Perhaps in an Express controller, you would pipe the file to the client
res.setHeader('content-type', 'image/png')
res.setHeader('content-disposition', 'attachment')
nodestream.download('avatars/user-123.png', res)
.then(results => {
  // Client received the file
})

License

This software is licensed under the BSD-3-Clause License. See the LICENSE file for more information.

Package Sidebar

Install

npm i nodestream-gcs

Weekly Downloads

0

Version

0.7.0

License

BSD-3-Clause

Last publish

Collaborators

  • dreamscapes