nodestream-gcs
v0.7.0
Published
Google Cloud Storage adapter for Nodestream
Downloads
15
Maintainers
Readme
nodestream-gcs
Google Cloud Storage adapter for Nodestream
Identity:: gcs
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.