Skip to content

Instantly share code, notes, and snippets.

@rosshinkley
Last active November 10, 2015 20:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rosshinkley/478f3711f4337e5beb8f to your computer and use it in GitHub Desktop.
Save rosshinkley/478f3711f4337e5beb8f to your computer and use it in GitHub Desktop.
request gzip: write to compressed file
var request = require('request'),
path = require('path'),
fs = require('fs');
var writezip = fs.createWriteStream(path.resolve(__dirname, 'temp.gz'));
var writefile = fs.createWriteStream(path.resolve(__dirname, 'temp.html'));
request({
method: 'GET',
uri: 'http://www.google.com',
gzip: true
}, function(error, response, body) {
writezip.close();
writefile.close();
})
.on('data', function(data) {
writefile.write(data);
})
.on('response', function(response) {
// unmodified http.IncomingMessage object
response.on('data', function(data) {
// compressed data as it is received
console.log('received ' + data.length + ' bytes of compressed data')
writezip.write(data);
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment