2018-03-25 19:08:52 -04:00
|
|
|
const AdmZip = require('adm-zip');
|
|
|
|
const fs = require('fs');
|
|
|
|
|
|
|
|
module.exports = {
|
2018-04-05 13:46:07 -04:00
|
|
|
readFileToBuffer: function (path) {
|
2021-03-07 16:21:06 -05:00
|
|
|
return Buffer.from(fs.readFileSync(path));
|
2018-03-25 19:08:52 -04:00
|
|
|
},
|
2018-04-05 13:46:07 -04:00
|
|
|
extractProjectJson: function (path) {
|
2018-03-25 19:08:52 -04:00
|
|
|
const zip = new AdmZip(path);
|
2022-05-16 17:11:55 -04:00
|
|
|
const projectEntry = zip.getEntries().find(item => item.entryName.match(/project\.json/));
|
2019-02-12 05:24:26 -05:00
|
|
|
if (projectEntry) {
|
|
|
|
return JSON.parse(zip.readAsText(projectEntry.entryName, 'utf8'));
|
|
|
|
}
|
|
|
|
return null;
|
2022-05-13 18:34:34 -04:00
|
|
|
},
|
|
|
|
extractAsset: function (path, assetFileName) {
|
|
|
|
const zip = new AdmZip(path);
|
2022-05-16 16:07:08 -04:00
|
|
|
const assetEntry = zip.getEntries().find(item => item.entryName.match(assetFileName));
|
2022-05-13 18:34:34 -04:00
|
|
|
return assetEntry.getData();
|
2018-03-25 19:08:52 -04:00
|
|
|
}
|
|
|
|
};
|