Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function skinType(skinPath) {
if (skinPath.endsWith(".wsz")) {
return FILE_TYPES.CLASSIC;
} else if (skinPath.endsWith(".wal")) {
return FILE_TYPES.MODERN;
}
const buffer = await fsPromises.readFile(skinPath);
try {
const zip = await JSZip.loadAsync(buffer);
if (zip.file(/.*\.(wsz|wal|zip)$/i).length) {
// This is a collection of skins
return FILE_TYPES.PACK;
}
const mains = zip.file(/^(.+\/)main\.bmp$/i);
return mains.length === 1 ? FILE_TYPES.CLASSIC : FILE_TYPES.MODERN;
} catch (e) {
return FILE_TYPES.INVALID;
}
}
module.exports = function (input, isSprite, callback) {
var msg = 'Failed to unzip and extract project.json, with error: ';
return JSZip.loadAsync(input)
.then(function (zip) {
// look for json in the list of files, or in a subdirectory
// assumes there is only one sprite or project json in the zipfile
const file = isSprite ?
zip.file(/^([^/]*\/)?sprite\.json$/)[0] :
zip.file(/^([^/]*\/)?project\.json$/)[0];
if (file) {
return file.async('string')
.then(function (project) {
return callback(null, [project, zip]);
});
}
return callback(msg + 'missing project or sprite json');
})
.catch(function (err) {
return callback(msg + JSON.stringify(err));
function localSaveAs(blob, filename) {
assert.strictEqual(filename, '20015 - Alligator_instruction_books.zip');
JSZip.loadAsync(blob)
.then(zip => {
const folderName = filename.split('.')[0] + '/';
const fileBaseName = folderName + '20015 - Alligator_book_';
assert.strictEqual(folderName, '20015 - Alligator_instruction_books/');
assert.property(zip.files, folderName);
assert.property(zip.files, fileBaseName + '1.lic');
assert.property(zip.files, fileBaseName + '2.lic');
zip.files[fileBaseName + '1.lic'].async('string')
.then(content => {
const file = JSON.parse(content);
assert.equal(file.state.books.length, 1);
assert.deepEqual(
file.state.books[0].pages,
file.state.pages.map(p => p.id).slice(1)
);
request(core.latestVersionZip, function () {
const jsZip = require('jszip')
jsZip.loadAsync(fs.readFileSync(localZipFile)).then(function (zip) {
let countDone = 0
let countFiles = Object.keys(zip.files).length
const fileDoneCb = function () {
countDone++
if (countDone >= countFiles) {
fs.unlinkSync(localZipFile)
process.stdout.write('Application successfully updated\n')
process.exit(0)
}
}
Object.keys(zip.files).forEach(function (index) {
const zipFile = zip.files[index]
const filepath = path.join(dir, zipFile.name.replace(/\\/g, path.sep))
if (zipFile.dir === true) {
if (!fs.existsSync(filepath)) fs.mkdirSync(filepath, {'mode': fstools.defaultMask})
process.stdout.write('Directory ' + filepath + '\n')
async makePath() {
const tempDir = electronRemote.app.getPath('temp');
const { userId, apiKey } = assets.getCredentials();
const request = await util.fetchApi(
apiKey,
`api/user/${userId}/bot/0`,
{
headers: {
'Accept': 'application/zip',
},
});
const rawZip = await request.arrayBuffer();
const zip = await JSZip.loadAsync(rawZip);
let botPath = null;
for (const [ zipFilePath, file ] of Object.entries(zip.files)) {
if (!file.dir && path.basename(zipFilePath).startsWith('MyBot')) {
botPath = zipFilePath;
}
}
await util.extractZip(zip, tempDir);
const result = path.join(tempDir, botPath);
console.info('Remote bot temp path:', result);
const tempBot = new InterpretedBot(this.name, guessInterpreter(result), result);
return await (tempBot.makePath());
}
}
const query: { [key: string]: string | undefined } = {};
window.location.search
.slice(1)
.split("&")
.reduce((result, item) => {
const index = item.indexOf("=");
result[item.slice(0, index)] = item.slice(index + 1);
return result;
}, query);
if (query[this.m_restoreUrlParamName] === undefined) {
return;
}
window.history.pushState({}, "", window.location.origin + window.location.pathname);
const zip = await jszip.loadAsync(query[this.m_restoreUrlParamName] as string, {
base64: true
});
if (!zip.files["settings.json"]) {
return;
}
const jsonData = await zip.files["settings.json"].async("text");
this.load(jsonData);
}
lib.load = function(source) {
return JSZip.loadAsync(source)
.then(zip => {
return Promise.all([
zip.file('document.json').async('string'),
zip.file('meta.json').async('string'),
zip.file('user.json').async('string')
]).then(result => {
return {
repo: zip,
document: JSON.parse(result[0]),
meta: JSON.parse(result[1]),
user: JSON.parse(result[2])
};
});
})
.then(data => {
return Promise.all(
JSZipUtils.getBinaryContent(filePath, (err, data) => {
if (err) {
resolve(err);
} else {
resolve(JSZip.loadAsync(data));
}
});
});
static fromArchive(Buffer) {
const method = 'fromArchive';
LOG.entry(method, Buffer.length);
return JSZip.loadAsync(Buffer).then(function(zip) {
const allPromises = [];
let ctoModelFiles = [];
let ctoModelFileNames = [];
let jsScriptFiles = [];
let permissionsFiles = [];
let businessNetworkDefinition;
let readmeContents = null;
let packageJsonContents = null;
LOG.debug(method, 'Loading README.md');
let readme = zip.file('README.md');
if(readme) {
const readmePromise = readme.async('string');
allPromises.push(readmePromise);
readmePromise.then(contents => {
LOG.debug(method, 'Loaded README.md');