Skip to content

Commit

Permalink
fix various issues with createWritable for Safari (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
SargisPlusPlus authored Feb 26, 2024
1 parent b0a3aad commit 94c0cb3
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/FileSystemFileHandle.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit 94c0cb3

Please sign in to comment.