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 — Propagate 'response' event through file.createReadStream() · Issue #606 · googleapis/google-cloud-node

Propagate 'response' event through file.createReadStream() #606

New issue
Copy link
New issue
Copy link
Closed
Closed
Propagate 'response' event through file.createReadStream()#606
Copy link
Assignees
stephenplusplus

Description

@robertdimarco
robertdimarco
opened on May 19, 2015
Issue body actions

_Background_:
We run a proxy service that serves a large number of files of varying size to downstream clients. In cases where we encounter an error serving the requested file (such as 404s) we intercept the error to the downstream client and pass through a custom error and template. See #522 for an oversimplified version.

_Request_:
The previous request to remove the required call to file.getMetadata() before invoking file.createReadStream() has been a big help in reducing mean latency since it removed a roundtrip for each download request. Our next challenge has been intercepting errors (namely those 404s) in a way that continues to let us simply pipe the result to the downstream client (and not buffer the download file until completion), and send the appropriate status code + headers.

Currently, in the case of a 404, the stream returned from file.createReadStream() will first emit a data event (an XML response containing an error) and then emits an error event (the formatted error object). Ideally, we could inspect the response headers before deciding whether or not to stream the result from GCS down to the client, and currently we have to buffer some number of data event payloads until we're sure we haven't encountered a GCS error.

_Details_:
The Node http.ClientRequest class specifies a response event that fires once and exposes (amongst other things) the HTTP response headers. If we could subscribe to that event, it would allow us to inspect the response from GCS, send the appropriate status code and headers to our downstream client, prior to piping any data.

diff --git a/lib/storage/file.js b/lib/storage/file.js
index d64aa09..137baba 100644
--- a/lib/storage/file.js
+++ b/lib/storage/file.js
@@ -464,6 +464,8 @@ File.prototype.createReadStream = function(options) {
         request(authorizedReqOpts)
           .on('error', done)

+          .on('response', throughStream.emit.bind(throughStream, 'response'))
+
           .on('data', function(chunk) {
             if (crc32c) {
               localCrcHash = crc.calculate(chunk, localCrcHash);

Don't hesitate to let me know if you have any thoughts or questions, and thanks for all of your hard work on this library!

Activity

Next
  1. ryanseys commented on May 19, 2015

    @ryanseys
    ryanseys
    on May 19, 2015
    Contributor
    More actions

    Interesting use case. I don't see why we couldn't support this. I'm all for exposing this functionality if it helps our users :) @stephenplusplus what do you say?

  2. ryanseys commented on May 19, 2015

    @ryanseys
    ryanseys
    on May 19, 2015
    Contributor
    More actions

    @robertdimarco I'm going to make an executive decision here and say "why not!". Could you create a PR for this change with a unit test or two and assign me to review when you're ready? Thanks!

  3. robertdimarco commented on May 19, 2015

    @robertdimarco
    robertdimarco
    on May 19, 2015
    ContributorAuthor
    More actions

    @ryanseys Sure thing, I'll follow-up with that shortly.

  4. stephenplusplus commented on May 19, 2015

    @stephenplusplus
    stephenplusplus
    on May 19, 2015
    Contributor
    More actions

    👍

  5. stephenplusplus commented on May 20, 2015

    @stephenplusplus
    stephenplusplus
    on May 20, 2015
    Contributor
    More actions

    Thanks, @robertdimarco!

  6. stephenplusplus
    closed this as completedon May 20, 2015
  7. JustinBeckwith
    assigned
    stephenplusplus
    on Feb 1, 2021
  8. sofisl
    added 2 commits that reference this issue on Oct 11, 2022

    chore(nodejs): update client ref docs link in metadata (#606)

    4e6e85f

    chore(nodejs): update client ref docs link in metadata (#606)

    e9d93ee
  9. sofisl
    added 2 commits that reference this issue on Nov 10, 2022

    chore(main): release 4.0.0 (#606)

    8e0387f

    feat: check status of long running operation by its name (#606)

    c91a640
  10. sofisl
    added a commit that references this issue on Jan 10, 2023

    fix(deps): require google-gax v2.12.0 (#606)

    6d9e17f
  11. sofisl
    added 2 commits that reference this issue on Jan 24, 2023

    chore(deps): update dependency mocha to v8 (#606)

    05626c5

    chore(deps): update dependency mocha to v8 (#606)

    9ec517c
  12. sofisl
    added a commit that references this issue on Sep 13, 2023

    build(node): update client library version in samples metadata (#1356) (

    767b131
  13. 12 remaining items

  14. GautamSharda
    added a commit that references this issue on Feb 3, 2026

    build: remove errant comma (#1113) (#606)

    662ea0b
  15. sofisl
    added 3 commits that reference this issue on Feb 4, 2026

    migrate code from googleapis/cloud-profiler-nodejs (#7087)

    288deb4

    chore(main): release 3.3.0 (#606)

    ac50a3a

    build: update linkinator config (#606)

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

    chore(deps): update dependency @types/node to v16 (#606)

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

    build: update linkinator config (#606)

    6dfab0d
  18. GautamSharda
    added a commit that references this issue on Feb 23, 2026

    chore(deps): update dependency @types/node to v16 (#606)

    2e58368
  19. sofisl
    added a commit that references this issue on Feb 24, 2026

    fix(deps): update dependency google-gax to ^0.26.0 (#606)

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

    chore(deps): update dependency pack-n-play to v4 (#606)

    6220309

    chore(deps): update dependency @types/node to v16 (#606)

    4b75588
  21. GautamSharda
    added 3 commits that reference this issue on Mar 5, 2026

    refactor: drop dependency on common-grpc (#606)

    95a9296

    chore(deps): update dependency jsdoc to v3.6.2 (#606)

    9c40008

    chore: add dev dependencies for cloud-rad ref docs (#606)

    1c21a3e
  22. sofisl
    added a commit that references this issue on Mar 17, 2026

    chore: fix type error in test (#606)

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

    fix(deps): update dependency yargs to v13 (googleapis#606)

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

Metadata

Metadata

Assignees

  • @stephenplusplus
    stephenplusplus

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    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.