Skip to content

Is gzip uploading possible through the API #751

Description

@MKHenson

Hi guys

I have been reading the documentation and from what I understand there is functionality to gzip uploaded files to storage - or at least the functionality exists through the gsutil.

"Note also that gsutil provides an easy way to cause content to be compressed and stored with Content-Encoding: gzip: see the -z option"

Is this currently possible through the node API? I have not seen it mentioned in the docs or code comments. If not, does this mean we have to gzip the files ourselves and then upload it with gzip meta data?

Activity

  1. stephenplusplus commented on Jul 28, 2015

    @stephenplusplus
    Contributor

    we have to gzip the files ourselves and then upload it with gzip meta data?

    Yes. It would look something like:

    var fs = require('fs');
    var zlib = require('zlib');
    
    var file = bucket.file('file.gz');
    var writeStream = file.createWriteStream({
      metadata: {
        contentEncoding: 'gzip'
      }
    });
    
    fs.createReadStream('./file')
      .pipe(zlib.createGzip())
      .pipe(writeStream);

    Using the stream implementation, it's easy to attach a GCS writable stream to any data manipulation pipeline. However, it wouldn't be a big task to support this more easily in our library. I'll let others chime in.

    Thanks for the question!

  2. MKHenson commented on Jul 28, 2015

    @MKHenson
    Author

    Thanks stephenplusplus, that makes sense to me. I'll go ahead and close the issue. Might not be worthwhile as a feature, but perhaps a mention in the docs? Just an afterthought though :)

  3. jgeewax commented on Jul 28, 2015

    @jgeewax
    Contributor

    How common is gzipping ? If it's something people often want to do, is there a way we could simplify this ? So that it's much less code?

    Ideally, uploading a .gz version of a file would be the same number of lines (with an extra config or different method call) as uploading the uncompressed version.

  4. stephenplusplus commented on Jul 28, 2015

    @stephenplusplus
    Contributor

    It's probably common enough to make it easier. I'll send a PR.

  5. added a commit that references this issue on Dec 16, 2022
  6. 6 remaining items

  7. added a commit that references this issue on Feb 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

api: storageIssues related to the Cloud Storage API.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions