// Since JSZip and FileSaver are included globally via script tags, no need for imports export function downloadFileSystem(fileSystem, printLine, newtypebox) { const zip = new JSZip(); // Recursive function to add files and folders to the zip function addToZip(directory, folder) { directory.forEach(item => { if (item.type === "") { const subFolder = folder.folder(item.name); addToZip(item.contents, subFolder); // Recurse into subdirectories } else if (item.type === "") { folder.file(item.name, item.content || ""); // Add file with its content } }); } addToZip(fileSystem, zip); // Generate the zip file and trigger download zip.generateAsync({ type: "blob" }).then(content => { // Global access to saveAs function from FileSaver saveAs(content, "TerminalFiles.zip"); // Using the global saveAs function printLine("File system successfully downloaded as TerminalFiles.zip."); newtypebox(); }).catch(err => { printLine("An error occurred while generating the download."); console.error(err); newtypebox(); }); }