scratch-parser/lib/unzip.js
Karishma Chadha 663d6ee8e6 test($test): Rename zip to unzip for clarity. Add descriptive error message to
Added unit tests for unzip and added a user-friendly error message for unzip being unable to perform
its duties of extracting a project.json from the given input (zip).
2018-03-23 09:38:14 -04:00

22 lines
593 B
JavaScript

var JSZip = require('jszip');
/**
* Unpacks a zip
*
* @param {String} Input
*
* @return {Object}
*/
module.exports = function (input, callback) {
return JSZip.loadAsync(input)
.then(function (zip) {
return zip.file('project.json').async('string')
.then(function (project) {
return callback(null, [project, zip]);
});
})
.catch(function(err) {
var msg = 'Failed to unzip and extract project.json, with error: ';
return callback(msg + JSON.stringify(err));
});
};