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
|
@ -514,12 +514,9 @@ class OutputWaiter {
|
||||||
fileName += ".zip";
|
fileName += ".zip";
|
||||||
}
|
}
|
||||||
|
|
||||||
let fileExt = window.prompt("Please enter a file extension for the files: ", ".txt");
|
let fileExt = window.prompt("Please enter a file extension for the files, or leave blank to detect automatically.", "");
|
||||||
|
|
||||||
if (fileExt === null) {
|
if (fileExt === null) fileExt = "";
|
||||||
// Use .dat as the default file extension
|
|
||||||
fileExt = ".dat";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.zipWorker !== null) {
|
if (this.zipWorker !== null) {
|
||||||
this.terminateZipWorker();
|
this.terminateZipWorker();
|
||||||
|
@ -1076,7 +1073,7 @@ class OutputWaiter {
|
||||||
sliceToEl = document.getElementById("output-file-slice-to"),
|
sliceToEl = document.getElementById("output-file-slice-to"),
|
||||||
sliceFrom = parseInt(sliceFromEl.value, 10),
|
sliceFrom = parseInt(sliceFromEl.value, 10),
|
||||||
sliceTo = parseInt(sliceToEl.value, 10),
|
sliceTo = parseInt(sliceToEl.value, 10),
|
||||||
str = Utils.arrayBufferToStr(this.getActive(true).slice(sliceFrom, sliceTo));
|
str = Utils.arrayBufferToStr(this.getActive(false).slice(sliceFrom, sliceTo));
|
||||||
|
|
||||||
outputText.classList.remove("blur");
|
outputText.classList.remove("blur");
|
||||||
showFileOverlay.style.display = "block";
|
showFileOverlay.style.display = "block";
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
|
|
||||||
import zip from "zlibjs/bin/zip.min";
|
import zip from "zlibjs/bin/zip.min";
|
||||||
import Utils from "../core/Utils";
|
import Utils from "../core/Utils";
|
||||||
|
import {detectFileType} from "../core/lib/FileType";
|
||||||
|
|
||||||
const Zlib = zip.Zlib;
|
const Zlib = zip.Zlib;
|
||||||
|
|
||||||
|
@ -48,7 +49,7 @@ self.zipFiles = function(outputs, filename, fileExtension) {
|
||||||
|
|
||||||
for (let i = 0; i < inputNums.length; i++) {
|
for (let i = 0; i < inputNums.length; i++) {
|
||||||
const iNum = inputNums[i];
|
const iNum = inputNums[i];
|
||||||
const name = Utils.strToByteArray(iNum + fileExtension);
|
let ext = fileExtension;
|
||||||
|
|
||||||
let output;
|
let output;
|
||||||
if (outputs[iNum].data === null) {
|
if (outputs[iNum].data === null) {
|
||||||
|
@ -58,6 +59,18 @@ self.zipFiles = function(outputs, filename, fileExtension) {
|
||||||
} else {
|
} else {
|
||||||
output = new Uint8Array(outputs[iNum].data.dish.value);
|
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});
|
zip.addFile(output, {filename: name});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue