Skip to content

Commit 94c0cb3

Browse files
fix various issues with createWritable for Safari (#70)
1 parent b0a3aad commit 94c0cb3

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/FileSystemFileHandle.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ if (
5656
let workerUrl
5757

5858
// Worker code that should be inlined (can't use any external functions)
59-
function code () {
59+
const code = () => {
6060
let fileHandle, handle
6161

6262
onmessage = async evt => {
@@ -96,7 +96,8 @@ if (
9696
globalThis.FileSystemFileHandle.prototype.createWritable = async function (options) {
9797
// Safari only support writing data in a worker with sync access handle.
9898
if (!workerUrl) {
99-
const blob = new Blob([code.toString() + `;${code.name}();`], {
99+
const stringCode = `(${code.toString()})()`
100+
const blob = new Blob([stringCode], {
100101
type: 'text/javascript'
101102
})
102103
workerUrl = URL.createObjectURL(blob)
@@ -123,7 +124,7 @@ if (
123124
// So we need to pass the path to the worker. This is a bit hacky and ugly.
124125
const root = await navigator.storage.getDirectory()
125126
const parent = await wm.get(this)
126-
const path = await parent.resolve(root)
127+
const path = await root.resolve(parent)
127128

128129
// Should likely never happen, but just in case...
129130
if (path === null) throw new DOMException(...GONE)

0 commit comments

Comments
 (0)