scratch-parser/lib/unzip.js
Andrew Sliwinski 0fe264a05b refactor: Merge changes from upstream and resolve issues with interface and test coverage
Merges in changes from upstream and resolves issues with both the removal of the analysis library as
well as issues with lint rules and integration tests.
2018-03-24 11:36:17 -04:00

21 lines
702 B
JavaScript

var JSZip = require('jszip');
/**
* Unpacks a zip file.
* @param {string} input Zip file provided as a string
* @param {array} callback Array including both the project and zip archive
* @return {void}
*/
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));
});
};