another try to fix the zip export

This commit is contained in:
2026-05-13 07:28:33 +02:00
parent 5d2dd3aca8
commit 817d66927c

View File

@@ -1502,11 +1502,9 @@
const zipOptions = { const zipOptions = {
type: 'uint8array', type: 'uint8array',
compression: 'STORE' // Media is already compressed, STORE saves massive CPU/RAM compression: 'STORE'
}; };
// Try Direct-to-Disk saving if supported (Chrome/Edge/Opera)
// This bypasses RAM entirely for the final file construction.
if ('showSaveFilePicker' in window) { if ('showSaveFilePicker' in window) {
try { try {
const handle = await window.showSaveFilePicker({ const handle = await window.showSaveFilePicker({
@@ -1518,26 +1516,28 @@
}); });
const writable = await handle.createWritable(); const writable = await handle.createWritable();
await new Promise((resolve, reject) => {
zip.generateInternalStream(zipOptions) // Create a ReadableStream from JSZip's internal stream
.on('data', async (chunk) => { const readable = new ReadableStream({
try { start(controller) {
await writable.write(chunk); zip.generateInternalStream(zipOptions)
} catch (e) { .on('data', (chunk) => controller.enqueue(chunk))
reject(e); .on('error', (err) => controller.error(err))
} .on('end', () => controller.close())
}) .resume();
.on('error', reject) }
.on('end', resolve)
.resume();
}); });
await writable.close();
await readable.pipeTo(writable);
// No need for writable.close() after pipeTo if it's handled, but createWritable's stream usually needs it.
// Actually pipeTo(writable) closes the destination by default.
exportStatusMsg.textContent = exportStatusText.dataset.complete || 'Export complete!'; exportStatusMsg.textContent = exportStatusText.dataset.complete || 'Export complete!';
} catch (e) { } catch (e) {
if (e.name === 'AbortError') { if (e.name === 'AbortError') {
exportStatusMsg.textContent = 'Export cancelled.'; exportStatusMsg.textContent = 'Export cancelled.';
} else { } else {
console.error('Streaming export failed:', e);
throw e; throw e;
} }
} }