GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — add download() method · Issue #367 · googleapis/google-cloud-node

add download() method #367

New issue
Copy link
New issue
Copy link
Closed
#381
Closed
add download() method#367
#381
Copy link
Assignees
ryanseys
Labels
api: storageIssues related to the Cloud Storage API.type: questionRequest for information or clarification. Not an issue.
Milestone
Storage Stable

Description

@nicolabortignon
nicolabortignon
opened on Jan 31, 2015
Issue body actions

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

var streamPointer = cloudstorage.createReadStream(myTextFile)
    streamPointer.on('complete', function(res) {
            myVar = res
        })

Activity

Next
  1. jgeewax
    added
    api: storageIssues related to the Cloud Storage API.
    type: questionRequest for information or clarification. Not an issue.
    on Feb 2, 2015
  2. jgeewax
    added this to the Storage Stable milestone on Feb 2, 2015
  3. stephenplusplus commented on Feb 2, 2015

    @stephenplusplus
    stephenplusplus
    on Feb 2, 2015
    Contributor
    More actions

    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#download to make this easier?

  4. ryanseys commented on Feb 2, 2015

    @ryanseys
    ryanseys
    on Feb 2, 2015
    Contributor
    More actions

    @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?

  5. stephenplusplus commented on Feb 2, 2015

    @stephenplusplus
    stephenplusplus
    on Feb 2, 2015
    Contributor
    More actions

    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"), //...

    ?

  6. nicolabortignon commented on Feb 2, 2015

    @nicolabortignon
    nicolabortignon
    on Feb 2, 2015
    Author
    More actions

    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!

  7. stephenplusplus
    changed the title [-]buffer of a createReadStream into a variable[/-] [+]add download() method[/+] on Feb 4, 2015
  8. ryanseys commented on Feb 4, 2015

    @ryanseys
    ryanseys
    on Feb 4, 2015
    Contributor
    More actions

    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
    });
  9. stephenplusplus commented on Feb 4, 2015

    @stephenplusplus
    stephenplusplus
    on Feb 4, 2015
    Contributor
    More actions

    PR sent: #381

  10. ryanseys
    closed this as completedin #381on Feb 9, 2015
  11. JustinBeckwith
    assigned
    ryanseys
    on Feb 1, 2021
  12. sofisl
    added a commit that references this issue on Sep 16, 2022

    fix: move gitattributes files to node templates (#367)

    ae954c6
  13. sofisl
    added 2 commits that reference this issue on Sep 27, 2022

    Add video quickstart (#367)

    2da3e4e

    chore: release 2.7.0

    5c98823
  14. 21 remaining items

  15. sofisl
    added a commit that references this issue on Feb 5, 2026

    chore: publish to npm using wombat (#367)

    be68789
  16. GautamSharda
    added a commit that references this issue on Feb 5, 2026

    build: remove verbose logging from test scripts (#367)

    94b65f1
  17. sofisl
    added a commit that references this issue on Feb 17, 2026

    chore: publish to npm using wombat (#367)

    7b7d237
  18. GautamSharda
    added a commit that references this issue on Feb 23, 2026

    build: remove verbose logging from test scripts (#367)

    85eaf47
  19. sofisl
    added 2 commits that reference this issue on Feb 24, 2026

    Convert test/collection.ts (#367)

    f4187cf

    fix(deps): update dependency @google-cloud/common to ^0.24.0 (#367)

    22c00a3
  20. GautamSharda
    added 2 commits that reference this issue on Feb 25, 2026

    build: update typescript generator version to publish in dual format …

    0e2cc90

    build: remove verbose logging from test scripts (#367)

    8067dcb
  21. sofisl
    added a commit that references this issue on Feb 26, 2026

    fix(tests): use unique label for tests (#367)

    f8e3f4b
  22. GautamSharda
    added a commit that references this issue on Mar 5, 2026

    chore(deps): update dependency @google-cloud/pubsub to ^0.23.0 (#367)

    8d18e61
  23. thiyaguk09
    added a commit that references this issue on Mar 18, 2026

    fix(deps): update dependency @google-cloud/common to ^0.24.0 (googlea…

    4664454
  24. GautamSharda
    added 2 commits that reference this issue on Mar 23, 2026

    Release v1.0.0 (#367)

    9975ab4

    Release v1.0.0 (#367)

    1704f82
  25. shivanee-p
    added a commit that references this issue on Mar 27, 2026

    Release v1.0.0 (#367)

    e383e31
  26. thiyaguk09
    added a commit that references this issue on May 5, 2026

    Release v1.0.0 (googleapis#367)

    c5c6100
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @ryanseys
    ryanseys

Labels

api: storageIssues related to the Cloud Storage API.type: questionRequest for information or clarification. Not an issue.

Type

No type

Projects

No projects

    Milestone

    • Storage Stable

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.