export BUCKET_NAME=my-bucket-name
npm test
Last active
July 8, 2019 16:12
-
-
Save stephenplusplus/a79fe4032c014124cf4a97e00d8e6ab7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
test text |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment