Reputation: 35
var url = "https://www.parsehub.com/api/v2/projects/{PROJECT_TOKEN}/last_ready_run/data";
var api_key = 'te79WidrkOmN_Fxs2e_kNnX5';
url = url.replace('{PROJECT_TOKEN}', 'tbNBvhG208xhGUpecAk62V80');
console.log('start fetching remote results from ' + url);
this.unblock();
HTTP.get(url, {params: {api_key: api_key}}, function(error, result) {
if(error) {
console.log('http get FAILED!');
} else {
console.log('http get SUCCESS');
if (result.statusCode === 200) {
console.log('Status code = 200!');
console.log(result.content);
}
}
});
The result.content here is gzipped, how to unzip it? I tried gb96:zlib but could not make it work. Also is there a hidden flag while using HTTP.get to automatically unzip the gzipped response?
I also put this issue on meteorpad at http://meteorpad.com/pad/8LnKNnzusSNhzbQ5s/Leaderboard
To reproduce, just select a player and click "Add 5 points".
Any help will be appreciated.
Thanks,
Upvotes: 0
Views: 510
Reputation: 17826
Sorry I know this is a really late response and the question has been open forever, but I have a solution.
In your Http.get
options you can pass npmRequestOptions
as an object. In this object use gzip : true
and your response should be decompressed for you.
Something like this...
HTTP.get("http://something", {
"npmRequestOptions" : {"gzip" : true}
},
function(err, res) {
//response is decompressed!
});
Upvotes: 4
Reputation: 5244
Run Command:
npm install unzip
fs.createReadStream('path/to/archive.zip').pipe(unzip.Extract({ path: 'output/path' }));
Or pipe the output of unzip.Parse() to fstream
var readStream = fs.createReadStream('path/to/archive.zip');
var writeStream = fstream.Writer('output/path');
readStream
.pipe(unzip.Parse())
.pipe(writeStream)
Upvotes: 1