another try to fix the zip export
This commit is contained in:
@@ -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) => {
|
|
||||||
|
// Create a ReadableStream from JSZip's internal stream
|
||||||
|
const readable = new ReadableStream({
|
||||||
|
start(controller) {
|
||||||
zip.generateInternalStream(zipOptions)
|
zip.generateInternalStream(zipOptions)
|
||||||
.on('data', async (chunk) => {
|
.on('data', (chunk) => controller.enqueue(chunk))
|
||||||
try {
|
.on('error', (err) => controller.error(err))
|
||||||
await writable.write(chunk);
|
.on('end', () => controller.close())
|
||||||
} catch (e) {
|
|
||||||
reject(e);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.on('error', reject)
|
|
||||||
.on('end', resolve)
|
|
||||||
.resume();
|
.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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user