diff --git a/src/web/OutputWaiter.mjs b/src/web/OutputWaiter.mjs index d3cbc8c7..8e21c2d3 100755 --- a/src/web/OutputWaiter.mjs +++ b/src/web/OutputWaiter.mjs @@ -514,12 +514,9 @@ class OutputWaiter { 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) { - // Use .dat as the default file extension - fileExt = ".dat"; - } + if (fileExt === null) fileExt = ""; if (this.zipWorker !== null) { this.terminateZipWorker(); @@ -1076,7 +1073,7 @@ class OutputWaiter { sliceToEl = document.getElementById("output-file-slice-to"), sliceFrom = parseInt(sliceFromEl.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"); showFileOverlay.style.display = "block"; diff --git a/src/web/ZipWorker.mjs b/src/web/ZipWorker.mjs index 039b1e32..6af603cc 100644 --- a/src/web/ZipWorker.mjs +++ b/src/web/ZipWorker.mjs @@ -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}); }