Closed jimmywarting closed 1 year ago
@jimmywarting any estimate of when you'll publish a stable version on NPM including this fix?
oh... did i forget to publish?
sry about that. i have nothing else in the work that needs to be completed. expect a new release soon-ish
@jimmywarting I had an issue with this... I published the library myself to test out this code. In my react app, I have:
const opfsRoot = await getOriginPrivateDirectory();
const userDir = await opfsRoot.getDirectoryHandle('123', {
create: true,
});
const fileHandle = await userDir.getFileHandle('test.txt', {
create: true,
});
try {
const writable = await fileHandle.createWritable();
} catch (e) {
console.log('****', e);
}
This works in Chrome. But Safari (17.2) throws an error: **** NotFoundError: A requested file or directory could not be found at the time an operation was processed.
UPDATE: I think I may have found the issue. See comments.
Safari do have a OPFS but it's lacking any good method of writing things to it unless you are not using the
syncAccessHandle
that's only available in web workers.This will patch/repair/polyfill the missing features in the broken api.
FileSystemWritableFileStream
is added to global scope only if it dose not exist but a File system dose.FileSystemFileHandle.prototype.createWritable
is conditionally polyfilled if needed.getFileHandle
to keep track of what the parent directory is ascreateWritable
needs to know the path of where it's located in order to re-create theFileSystemFile
handle inside of a worker ( cuz they can't be structural cloned / postMessaged )