directoryOpen does not allow creating new files in an empty directory
See original GitHub issuedirectoryOpen() returns a 0 length array of FileWithDirectoryAndFileHandle
if there is nothing inside the directory having been opened. In my case I’m opening with a mode of readwrite
, so Chrome nicely prompts me that the application will have access to the directory. Per https://wicg.github.io/file-system-access/#api-filesystemdirectoryhandle, I can create new files by calling getFileHandle(create=true) on a directory handle; however, because directoryOpen returns 0 length, I don’t have a directory handle to create the initial file in.
If there’s an alternate way to accomplish this, please advise; but, I think the fix is to include a FileSystemDirectoryHandle as part of the directoryOpen response.
(I’m making an app with no server; data is stored in localstorage, and I’m adding sync to and from the filesystem.)
Issue Analytics
- State:
- Created 10 months ago
- Comments:5 (2 by maintainers)
Top GitHub Comments
Sure. I’m not much of a js programmer, but I followed the pattern in the codebase.
https://github.com/GoogleChromeLabs/browser-fs-access/pull/132
I chose to delegate to directoryOpen rather than reimplementing most of it - let me know what you think. I will test more thoroughly if the code looks reasonable.
@beaufortfrancois suggests maybe having a completely new convenience function
fileHierarchy()
or so might be cleanest, which would only work if the File System Access API is supported. The point ofbrowser-fs-access
is to be a ponyfill (not polyfill), so this potential new function that only works when the File System Access API is supported would be kind of against its philosophy, but I can see how it would add value. Do you want to work on a PR that would add it as a new filefile-hierarchy.mjs
insrc/fs-access/
?