(fileDataArray, zipName="untitled")
| 6 | * @param {[]} fileDataArray - [{fileData: "", fileName: "", folder: ""}] |
| 7 | */ |
| 8 | export async function createFilesAndDownload(fileDataArray, zipName="untitled"){ |
| 9 | |
| 10 | const zip = new JSZip() |
| 11 | |
| 12 | fileDataArray.forEach(file => { |
| 13 | const { fileData, fileName, folder } = file |
| 14 | |
| 15 | // If a folder is specified, create it if it doesn't exist |
| 16 | if (folder) { |
| 17 | const folderRef = zip.folder(folder) |
| 18 | folderRef.file(fileName, fileData) |
| 19 | |
| 20 | } else { |
| 21 | // If no folder is specified, place the file in the root |
| 22 | zip.file(fileName, fileData) |
| 23 | } |
| 24 | }) |
| 25 | |
| 26 | // Generate the ZIP asynchronously |
| 27 | zip.generateAsync({ type: "blob" }).then(function(content) { |
| 28 | const link = document.createElement("a") |
| 29 | link.href = URL.createObjectURL(content) |
| 30 | link.download = `${zipName}.zip` |
| 31 | link.click() |
| 32 | }) |
| 33 | |
| 34 | } |
no outgoing calls
no test coverage detected