-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Expose web_sys::File
via FileEngine
#1081
Comments
This would be a great addition! Dioxus does not include Instead we could expose the inner type as Any type and allow users to downcast it to a platform specific type. We do something similar to this with the onmounted event. We could expose an extension trait on each platform to make downcasting to the platform type more easy: #[async_trait::async_trait(?Send)]
pub trait FileEngine {
// get a list of file names
fn files(&self) -> Vec<String>;
// read a file to bytes
async fn read_file(&self, file: &str) -> Option<Vec<u8>>;
async fn read_native_file(&self, file: &str) -> Option<Box<dyn Any>>;
// read a file to string
async fn read_file_to_string(&self, file: &str) -> Option<String>;
}
trait WebFileEngineExt {
fn read_web_file(&self, file: &str) -> Option<web_sys::File>;
}
impl WebFileEngineExt for std::sync::Arc<dyn FileEngine> {
fn read_web_file(&self, file: &str) -> Option<web_sys::File> {
self.read_native_file().map(|file| *file.downcast())
}
} |
also related to #93 |
I can work on a PR if the above approach is acceptable, let me know. |
That would be great! |
Specific Demand
On wasm I need to access the raw
web_sys::File
object in order to deal with big files (bigger than available memory), however,FileEngine
only providesread_to_string
andread_to_bytes
.Implement Suggestion
#[cfg...]
onwasm
to returnweb_sys::Filie
The text was updated successfully, but these errors were encountered: