mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-21 07:16:17 -04:00
Use detectFileType to autodetect file extensions in zip
This commit is contained in:
parent
0cff7bdd04
commit
6237db9ba6
2 changed files with 17 additions and 7 deletions
|
@ -8,6 +8,7 @@
|
|||
|
||||
import zip from "zlibjs/bin/zip.min";
|
||||
import Utils from "../core/Utils";
|
||||
import {detectFileType} from "../core/lib/FileType";
|
||||
|
||||
const Zlib = zip.Zlib;
|
||||
|
||||
|
@ -48,7 +49,7 @@ self.zipFiles = function(outputs, filename, fileExtension) {
|
|||
|
||||
for (let i = 0; i < inputNums.length; i++) {
|
||||
const iNum = inputNums[i];
|
||||
const name = Utils.strToByteArray(iNum + fileExtension);
|
||||
let ext = fileExtension;
|
||||
|
||||
let output;
|
||||
if (outputs[iNum].data === null) {
|
||||
|
@ -58,6 +59,18 @@ self.zipFiles = function(outputs, filename, fileExtension) {
|
|||
} else {
|
||||
output = new Uint8Array(outputs[iNum].data.dish.value);
|
||||
}
|
||||
|
||||
if (fileExtension === "") {
|
||||
// Detect automatically
|
||||
const types = detectFileType(output);
|
||||
if (!types.length) {
|
||||
ext = ".dat";
|
||||
} else {
|
||||
ext = `.${types[0].extension.split(",", 1)[0]}`;
|
||||
}
|
||||
}
|
||||
const name = Utils.strToByteArray(iNum + ext);
|
||||
|
||||
zip.addFile(output, {filename: name});
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue