Created
January 2, 2020 08:24
-
-
Save adityadeshpande/40f2af6eed849bed2f4fedbc6997fe04 to your computer and use it in GitHub Desktop.
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 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