scratch-vm/test/fixtures/readProjectFile.js
Karishma Chadha fd31a777e2
Code clean up from code review
Co-authored-by: Christopher Willis-Ford <7019101+cwillisf@users.noreply.github.com>
2022-05-16 16:07:08 -04:00

21 lines
738 B
JavaScript

const AdmZip = require('adm-zip');
const fs = require('fs');
module.exports = {
readFileToBuffer: function (path) {
return Buffer.from(fs.readFileSync(path));
},
extractProjectJson: function (path) {
const zip = new AdmZip(path);
const projectEntry = zip.getEntries().filter(item => item.entryName.match(/project\.json/))[0];
if (projectEntry) {
return JSON.parse(zip.readAsText(projectEntry.entryName, 'utf8'));
}
return null;
},
extractAsset: function (path, assetFileName) {
const zip = new AdmZip(path);
const assetEntry = zip.getEntries().find(item => item.entryName.match(assetFileName));
return assetEntry.getData();
}
};