Last active
November 10, 2015 20:03
-
-
Save rosshinkley/478f3711f4337e5beb8f to your computer and use it in GitHub Desktop.
request gzip: write to compressed file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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