I'm downloading a daily export gzip file from The Movie Database and decompressing it with zlib. When the end
event is hit, I log the length of the string of data I decompressed. The length is different every time.
It appears that the data isn't fully getting decompressed. I noticed this when I started parsing the JSON that the file actually contains. It would get half-way through converting each line of JSON (each line represents a stand-alone json object) and blow up because the json was malformed.
var http = require('http');
var zlib = require('zlib');
var downloadUrl = "http://files.tmdb.org/p/exports/movie_ids_03_01_2018.json.gz";
http.get(downloadUrl, function(response) {
var fileContents = "";
var gunzip = zlib.createGunzip();
gunzip.on('data', function(data) {
fileContents += data.toString();
});
gunzip.on('end', function() {
console.log(fileContents.length);
});
response.pipe(gunzip);
});
Am I using the gunzip events incorrectly?
I have a reproducible example you can execute to see it running.