Repository navigation
add download() method #367
Description
Activity
- addedapi: storageIssues related to the Cloud Storage API.Issues related to the Cloud Storage API.type: questionRequest for information or clarification. Not an issue.Request for information or clarification. Not an issue.
on Feb 2, 2015 Sorry, it appears our docs are lacking on showing how to simply download a file. Here's the current way to get a file's contents:
var gcloud = require("gcloud")({ /* credentials. */ }); var cloudstorage = gcloud.storage(); var myTextFile = cloudstorage.file('your-file.txt'); var fileContents = new Buffer(''); myTextFile.createReadStream() .on('data', function(chunk) { fileContents = Buffer.concat([fileContents, chunk]); }) .on('complete', function() { // `fileContents` is ready });
@ryanseys thoughts on adding
Bucket#downloadto make this easier?@stephenplusplus That sounds like a good idea. I had an idea for a similar thing that would immediately write to a given filename as well for those wanting to just download a bunch of files. Perhaps we could support both of these options either as separate methods or as an option?
Something like:
myBucket.download("my-file.txt", function (err, contents, file) { // contents === file's contents // file === myBucket.file("my-file.txt") }) // and... myBucket.download("my-file.txt", { destination: "/Users/stephen/Desktop/local-copy.txt" }, function (err, contents, file) { // contents === file's contents // file === myBucket.file("my-file.txt") }) // and we can support a File object as a source: myBucket.download(myBucket.file("my-file.txt"), //...
?
I would say both the .read and .download as wraps for the asynchronous readStream and Pipe, would add a really appreciated level of simplification.
Also, just as overall idea, would be nice to align the interface of the CreateReadStream to the standard (fs) one.
Thanks for the answer!- changed the title
[-]buffer of a createReadStream into a variable[/-][+]add download() method[/+]on Feb 4, 2015 If we are downloading, wouldn't we just download from a Bucket#file instance? And if we just want to immediately write to a file without storing in memory, that'd be cool... I don't know if we should use two separate methods for that or if we can get away with just one like below:
myFile.download('./local/path/image.jpg', function(err, contents) { // don't consume memory // contents = null }); myFile.download(function(err, contents) { // consume memory // contents = contents of file });
PR sent: #381
- added a commit that references this issue
on Sep 16, 2022 - added 2 commits that reference this issue
on Sep 27, 2022 21 remaining items
- added a commit that references this issue
on Feb 5, 2026 - added a commit that references this issue
on Feb 5, 2026 - added a commit that references this issue
on Feb 17, 2026 - added a commit that references this issue
on Feb 23, 2026 - added a commit that references this issue
on Feb 26, 2026 - added a commit that references this issue
on Mar 5, 2026 - added a commit that references this issue
on Mar 18, 2026 - added 2 commits that reference this issue
on Mar 23, 2026 - added a commit that references this issue
on May 5, 2026
Hi,
I spent few hours looking into the code, but didn't find the solution.
What am i suppose to do in order to load the content of a file from a createReadStream into a variable ?
In the example there is only a read-to-pipe-to-write example.
I just want to do something like