Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to unzip gzip response #747

Closed
youxiachai opened this issue Dec 27, 2013 · 7 comments
Closed

how to unzip gzip response #747

youxiachai opened this issue Dec 27, 2013 · 7 comments

Comments

@youxiachai
Copy link

Example:

function response (err, response, body) {

// current how to unzip body ?

}
request.get({
    url : path,
    headers: {
        'Accept-Encoding' : 'gzip'
    }
}, response);
@youxiachai
Copy link
Author

I resolve it.

@VRMink
Copy link
Contributor

VRMink commented Jan 13, 2014

How did you resolve it?

@youxiachai
Copy link
Author

@VRMink here it is example

  zlib = require('zlib');

function response (err, res, body) {
//check res header it is gzip
 console.log(res.headers['content-encoding'])
//now body it is gzip stream buffer
      zlib.unzip(body, function(err, buffer) {
             console.log(buffer.toString())
       }

}
    request.get({
        url : apiUrl,
        headers: {
            'Accept-Encoding' : 'gzip',
          },
        encoding : null  // it is very import!!
    }, response);

@VRMink
Copy link
Contributor

VRMink commented Jan 13, 2014

Thanks - that was not very obvious :)

@codyi96
Copy link

codyi96 commented Jan 20, 2018

@youxiachai Thanks!

@skygxk
Copy link

skygxk commented Mar 20, 2020

Thanks for your solution!

@xiaoshiziha
Copy link

request.get({ url : path, encoding: null, //it is vert important! }, response)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants