-
Notifications
You must be signed in to change notification settings - Fork 1.7k
[native/js/wasm] Platform independent File I/O #56404
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
Comments
It probably does make sense yes, I don't see why not. It already exists and has a good name, plus much of it is already written. Note that I don't actually work on the package though (I think it has no official owner currently). We would probably want to more officially support it and figure out an owner. Using this package also makes testing easier/faster because you can use an in memory file system. |
It's a hack that you can import So a new API is a better idea for supporting other platforms.
Maybe just "operations". Is "file" even the best abstraction? It's not Unix, not everything has to be a file. A file system is contains
If we are going to abstract over "file system" to platforms that are not POSIX, not operating systems, and has no real file system, it might be worth upping the abstraction level. And figure out which subset of operations is really needed, without trying to support too much. (What does "mounting files" mean?) |
In the context where we use it, native code compiled to WASM with emscripten, it is a Posix-like file API. https://emscripten.org/docs/api_reference/Filesystem-API.html Trying to use a different abstraction than a file system will not work if the native code is also trying to use the file system. We need to write a file and then pass in a file path to the native code.
Precisely. That's why should come up with something for users that is intended to be used. |
I think there's actually a need to go higher in abstraction and lower: Example: With our existing What would be nice is to have
|
Note that So, it currently has the exact same layer of abstraction as |
Overall I like this direction and I'd love to eventually remove |
From a browser perspective (JS/Wasm) we're trying to AVOID supporting concrete types in Having interfaces that can be implemented is a GREAT idea. I think But I worry about making promises about implementations. A The important thing is having the API surface that can be shared across use cases but backed by any implementation. (I originally read this as wanting |
+1 on the web-specific thoughts so far. We're definitely in favor of moving away from |
+1. Less things to patch to run the |
I like the idea of having a package that represents an abstract filesystem but
I have a presentation with a link to a repo containing some ideas that seem lined up with yours. Some other ideas:
|
this seems to me at least tangentially related to |
Current situation
Dart's file IO capabilities are fragmented across different platforms and mechanisms. The
dart:io
library provides comprehensive file handling for native platforms but all methods throw in web dart2js and dart2wasm. IOOverrides enable overriding a subset of the APIs, butdart:io
contains many more APIs that might not be implementable in the wasm and js backends.MemFSIOOverrides
Thanks @TheComputerM! 🚀
If users want to write code that uses file IO that works across multiple backends, this is what they currently can use.
Problems
dart:io
APIs might be implementable on all backends. (locks? sockets? stdio? http requests?)dart:io
intopackage:io
cc @brianquinlan)Proposed solution
Introduce a File API in a package, potentially
package:file
, that works seamlessly across all Dart platforms. The new API would expose a subset of file operations supported by all targets, enabling developers to write platform-agnostic code for essential file interactions.We should then be opinionated and tell users to use that package instead of
dart:io
directly.This is how it's done with http, we have
package:http
which works on all platforms and it uses conditional imports to usedart:io
on VM anddart:html
on web.I believe
package:file
is currently missing support for using the file system on the web.Using the memory file system works for producing (temporary) files in Dart, but does not work for:
Some open questions:
package:file
the right place to provide the platform abstraction?CallbackFileSytem
would allow wiring up from inside Dart, but it's probably preferable to do this at the embedder level.)Soliciting input from
package:file
@jonahwilliams @jakemac53dart:io
boss @brianquinlanAny feedback is welcome. Should we take a different direction?
Thanks @mkustermann for suggesting this approach. 🙏 And thanks @TheComputerM for bringing this issue up! 🚀
Let's enable our users to write code with file I/O that works everywhere.
The text was updated successfully, but these errors were encountered: