Skip to content

Instantly share code, notes, and snippets.

@stephenplusplus
Last active July 8, 2019 16:12
Show Gist options
  • Save stephenplusplus/a79fe4032c014124cf4a97e00d8e6ab7 to your computer and use it in GitHub Desktop.
Save stephenplusplus/a79fe4032c014124cf4a97e00d8e6ab7 to your computer and use it in GitHub Desktop.
{
"name": "gissue-763",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "node ./test.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@google-cloud/storage": "^3.0.2"
}
}
'use strict'
const fs = require('fs')
const {Storage} = require('@google-cloud/storage')
const storage = new Storage()
const bucket = storage.bucket(process.env.BUCKET_NAME)
const file = bucket.file('test.zip')
fs.createReadStream('test.txt.zip')
.on('error', console.log)
.pipe(file.createWriteStream())
.on('error', console.log)
.on('finish', download)
async function download() {
const [contents] = await file.download()
fs.writeFileSync('test.txt-downloaded.zip', contents)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment