From 94c0cb360d5db039fd15922023367f0651f843ee Mon Sep 17 00:00:00 2001 From: Sargis Date: Mon, 26 Feb 2024 13:11:43 -0800 Subject: [PATCH] fix various issues with createWritable for Safari (#70) --- src/FileSystemFileHandle.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/FileSystemFileHandle.js b/src/FileSystemFileHandle.js index 4ea392f..bf104fc 100644 --- a/src/FileSystemFileHandle.js +++ b/src/FileSystemFileHandle.js @@ -56,7 +56,7 @@ if ( let workerUrl // Worker code that should be inlined (can't use any external functions) - function code () { + const code = () => { let fileHandle, handle onmessage = async evt => { @@ -96,7 +96,8 @@ if ( globalThis.FileSystemFileHandle.prototype.createWritable = async function (options) { // Safari only support writing data in a worker with sync access handle. if (!workerUrl) { - const blob = new Blob([code.toString() + `;${code.name}();`], { + const stringCode = `(${code.toString()})()` + const blob = new Blob([stringCode], { type: 'text/javascript' }) workerUrl = URL.createObjectURL(blob) @@ -123,7 +124,7 @@ if ( // So we need to pass the path to the worker. This is a bit hacky and ugly. const root = await navigator.storage.getDirectory() const parent = await wm.get(this) - const path = await parent.resolve(root) + const path = await root.resolve(parent) // Should likely never happen, but just in case... if (path === null) throw new DOMException(...GONE)