I need to download and unzip zip archive in my nodejs application. I have this code:
utils.apiRequest(teamcityOptions)
.then(function (loadedData) {
var tempDir = tmp.dirSync();
var tmpZipFileName = tempDir.name + "\\" + 'bob.zip';
fs.appendFileSync(tmpZipFileName, loadedData);
var zip;
try {
zip = new AdmZip(tmpZipFileName);
} catch (e) {
log('Can not create zip, bad data', e);
}
});
This code gives me error:
Can not create zip, bad data Invalid CEN header (bad signature)
I am using Windows 7. I can't even open this ZIP file with 7-zip or WinRAR (simple error like corrupted data).
Also, utils.apiRequest
function body is:
utils.apiRequest: function (options) {
var deferred = defer();
https.get(options, function (request) {
var loadedData = '';
request.on('data', function (dataBlock) {
loadedData += dataBlock.toString('utf8');
});
request.on('end', function () {
deferred.resolve(loadedData);
})
});
return deferred.promise;
}
How can I solve my problem?
PS: I don't have problems using curl
:)