Skip to content

Instantly share code, notes, and snippets.

@adityadeshpande
Created January 2, 2020 08:24
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 adityadeshpande/40f2af6eed849bed2f4fedbc6997fe04 to your computer and use it in GitHub Desktop.
Save adityadeshpande/40f2af6eed849bed2f4fedbc6997fe04 to your computer and use it in GitHub Desktop.
var file_url = 'https://downloadurl.com/files/my_zip_file.zip';
var AdmZip = require('adm-zip'); //Reference: https://www.npmjs.com/package/adm-zip
var https = require('https');
var fs = require('fs')
https.get(file_url, function (res) {
var data = [], dataLen = 0;
res.on('data', function (chunk) {
data.push(chunk);
dataLen += chunk.length;
}).on('end', function () {
var buf = Buffer.alloc(dataLen);
for (var i = 0, len = data.length, pos = 0; i < len; i++) {
data[i].copy(buf, pos);
pos += data[i].length;
}
var zip = new AdmZip(buf);
var dir = './relative_path/zip_test/';
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir);
}
zip.extractAllTo(/*target path*/dir, /*overwrite*/true);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment