fix: fall back to copy when OPFS move() throws on WebKit and retry failed worker downloads on the main thread

This commit is contained in:
Jonathan Sykes
2026-07-03 05:16:05 +08:00
parent 76f8ec525d
commit 048817bcf4
2 changed files with 18 additions and 11 deletions

View File

@@ -76,12 +76,16 @@ self.onmessage = async (e) => {
access.close();
}
// Finalize: .part → permanent name. Prefer the native rename; fall back
// to a chunked copy (still fully inside the worker, small fixed buffers).
// Finalize: .part → permanent name. Prefer the native rename, but treat
// ANY move() failure as "unavailable" and fall back to a chunked copy —
// WebKit's move() has a different signature/behavior than Chrome's and
// throws TypeError ("Not enough arguments") rather than being absent.
try { await dir.removeEntry(filename); } catch { /* no previous copy */ }
let renamed = false;
if (typeof partHandle.move === 'function') {
await partHandle.move(filename);
} else {
try { await partHandle.move(filename); renamed = true; } catch { /* copy below */ }
}
if (!renamed) {
const finalHandle = await dir.getFileHandle(filename, { create: true });
const out = await finalHandle.createSyncAccessHandle();
try {