Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return new Promise((resolve, reject) => {
yauzl.fromBuffer(zippedData, { lazyEntries: true }, (err, zipfile) => {
if (err) {
reject(err)
} else if (zipfile == null) {
reject(new Error('zipFile is null or undefined'))
} else {
zipfile.readEntry()
zipfile.on('end', () => resolve())
zipfile.on('entry', entry => {
if (/\$/.test(entry.fileName)) {
// Current entry is an empty directory
shell.mkdir('-p', path.join(destPath, entry.fileName))
zipfile.readEntry()
} else {
// Current entry is a file
shell.mkdir('-p', path.join(destPath, path.dirname(entry.fileName)))
const ws = fs.createWriteStream(path.join(destPath, entry.fileName))
function unzip (buffer, callback) {
const result = { files: {} };
Unzip.fromBuffer(buffer, (err, zip) => {
if (err) {
return callback(err);
}
zip.on('error', function onError (err) {
zip.close();
callback(err);
});
zip.on('end', function onEnd () {
zip.close();
});
if (zip.entryCount === 0) {
return callback(null, result);
}
.then(buf => yauzl.fromBuffer(buf, yauzlOpts, this[YAUZL_CALLBACK]))
.catch(e => this.emit('error', e));
res.on("end", () => {
const zipBuffer = Buffer.concat(buffers);
yauzl.fromBuffer(zipBuffer, { lazyEntries: true }, (err: Error, zipFile: any) => {
if (err != null) throw err;
splashScreen.setProgressMax(zipFile.entryCount * 2);
splashScreen.setProgressValue(zipFile.entryCount);
let entriesProcessed = 0;
const rootFolderName = path.parse(downloadURL).name;
zipFile.readEntry();
zipFile.on("entry", (entry: any) => {
if (entry.fileName.indexOf(rootFolderName) !== 0) throw new Error(`Found file outside of root folder: ${entry.fileName} (${rootFolderName})`);
const filename = path.join(settings.corePath, entry.fileName.replace(rootFolderName, ""));
if (/\/$/.test(entry.fileName)) {
mkdirp(filename, (err) => {
if (err != null) throw err;
res.on("end", () => {
let zipBuffer = Buffer.concat(buffers);
yauzl.fromBuffer(zipBuffer, { lazyEntries: true }, (err: Error, zipFile: any) => {
if (err != null) throw err;
progress = zipFile.entryCount;
progressMax = zipFile.entryCount * 2;
let rootFolderName: string;
zipFile.readEntry();
zipFile.on("entry", (entry: any) => {
if (rootFolderName == null) rootFolderName = entry.fileName;
if (entry.fileName.indexOf(rootFolderName) !== 0) throw new Error(`Found file outside of root folder: ${entry.fileName} (${rootFolderName})`);
const filename = path.join(downloadPath, entry.fileName.replace(rootFolderName, ""));
if (/\/$/.test(entry.fileName)) {
mkdirp(filename, (err) => {
await new Promise((resolve, reject) => {
const done = new Set();
yauzl.fromBuffer(file, { lazyEntries: true }, (err, zip) => {
if (err)
return void reject(err);
const next = () => {
zip.readEntry();
};
zip.on("entry", (entry) => {
const name = entry.fileName;
if (name.endsWith("/"))
return void next();
const [key, messages, ...rest] = name.split("/");
if (messages !== "messages.json" || rest.length !== 0)
if (this._zipFileNameEncoding === 'utf-8') {
this._zipFileNameEncoding = 'utf8';
}
this[YAUZL_CALLBACK] = this[YAUZL_CALLBACK].bind(this);
const sourceType = utils.sourceType(opts.source);
const yauzlOpts = this._yauzlOpts = Object.assign({}, DEFAULTS, opts.yauzl);
if (sourceType === 'file') {
yauzl.open(opts.source, yauzlOpts, this[YAUZL_CALLBACK]);
return;
}
if (sourceType === 'buffer') {
yauzl.fromBuffer(opts.source, yauzlOpts, this[YAUZL_CALLBACK]);
return;
}
if (sourceType === 'stream') {
utils.streamToBuffer(opts.source)
.then(buf => yauzl.fromBuffer(buf, yauzlOpts, this[YAUZL_CALLBACK]))
.catch(e => this.emit('error', e));
return;
}
this.on('pipe', srcStream => {
srcStream.unpipe(srcStream);
utils.streamToBuffer(srcStream)
.then(buf => {
this._chunks.push(buf);
let result = new Promise( ( resolve, reject ) => {
yauzl.fromBuffer( content.body, { lazyEntries: true }, ( err, file ) => {
try {
if ( err ) {
return reject( err );
}
if ( file.entryCount > 100 ) {
return reject( new Error( `Too many files in the zip "${ file.entryCount }".` ) );
}
let foundSubs : boolean = false;
file.readEntry();
file.on( 'entry', entry => {
if ( isSubtitle( entry.fileName ) ) {
file.openReadStream( entry, ( err, stream : NodeJS.ReadableStream ) => {
return new Promise((resolve, reject) => {
yauzl.fromBuffer(buffer, (err, zipfile) => {
if (err) {
return reject(err);
}
zipfile!.once('end', resolve);
zipfile!.once('error', reject);
zipfile!.on('entry', entry => {
const destination = path.join(directory, entry.fileName);
if (entry.fileName.endsWith('/')) {
if (fs.existsSync(destination)) {
return;
}
try {
return fs.mkdirSync(destination);
} catch (e) {
return reject(e);
}