Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Web support #31

Open
daxpedda opened this issue Dec 16, 2023 · 2 comments
Open

Web support #31

daxpedda opened this issue Dec 16, 2023 · 2 comments

Comments

@daxpedda
Copy link

Would there be interest in adding support for Web through the File System API?

It would be pretty straightforward, as it's all natively async anyway and there would be no need to spawn any blocking threads. Probably the most interesting part is documentation and converting errors to io::Error.

All major browsers already support this, except Safari which doesn't support writing files in async, but only in sync.

Happy to make the PR of course!

@notgull
Copy link
Member

notgull commented Dec 17, 2023

I guess this falls under #24.

My main concern is how the File System API you linked would map onto the std::fs API. From a brief look at the API it looks like it doesn't map too well onto the file system of paths. I guess reading and writing would be relatively the same, but I'm concerned about how APIs like create_dir or metadata would map onto the web API.

I guess we could have a set of extension functions for opening the Files, having the Files open for reading and writing, and make all of the other APIs return "unsupported" errors. Does this make much sense?

@daxpedda
Copy link
Author

daxpedda commented Dec 17, 2023

I guess reading and writing would be relatively the same, but I'm concerned about how APIs like create_dir or metadata would map onto the web API.

I think we should use OPFS by default, see StorageManager.getDirectory(). This would allow us to implement create_dir() through FileSystemDirectoryHandle.getDirectoryHandle().

metadata is also mostly covered, but we would have to create our own type that mirrors Std's Metadata:

Will look into making a PR soon!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants