I want to download files from github. I use this question and it's answer as example
I write this code:
var downloadPath = './downloads/picasso.zip';
var file = fs.createWriteStream(downloadPath);
https.get('https://github.com/square/picasso/archive/master.zip', function (response) {
response.pipe(file);
file.on('finish', function() {
file.close();
console.log("DONE LOADING");
})
}).on('error', function (err) {
console.log("ERROR " + err.message);
fs.unlink(downloadPath);
});
When I launch this code, it says to me DONE LOADING
, which, in theory, means that zip file is downloaded. However, when I try to open this zip file, my archiver says that this file is corrupted and it is only 1KB.
Why this is happening? Does github restrict somehow downloading according to header of my request? Then why error is not throwing?