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

Drag and Drop: read incrementally #4654

Open
rm-dr opened this issue Jun 13, 2024 · 0 comments · May be fixed by #4667
Open

Drag and Drop: read incrementally #4654

rm-dr opened this issue Jun 13, 2024 · 0 comments · May be fixed by #4667

Comments

@rm-dr
Copy link

rm-dr commented Jun 13, 2024

Is your feature request related to a problem? Please describe.

When dropping a large file into egui on the web, eframe always reads the whole file---even if file drop events aren't handled. Drag a particularly large file into egui, and eframe will try to load the whole thing into memory. This isn't ideal.

The code below is problematic:

if let Some(file) = files.get(i) {
let name = file.name();
let mime = file.type_();
let last_modified = std::time::UNIX_EPOCH
+ std::time::Duration::from_millis(file.last_modified() as u64);
log::debug!("Loading {:?} ({} bytes)…", name, file.size());
let future = wasm_bindgen_futures::JsFuture::from(file.array_buffer());
let runner_ref = runner_ref.clone();
let future = async move {
match future.await {
Ok(array_buffer) => {
let bytes = js_sys::Uint8Array::new(&array_buffer).to_vec();
log::debug!("Loaded {:?} ({} bytes).", name, bytes.len());
if let Some(mut runner_lock) = runner_ref.try_lock() {
runner_lock.input.raw.dropped_files.push(
egui::DroppedFile {
name,
mime,
last_modified: Some(last_modified),
bytes: Some(bytes.into()),
..Default::default()
},
);

Describe the solution you'd like

It would be nice to read dropped files in parts, and only on demand. Seems that Blob.stream() is how JS usually does it, but my knowledge of web is limited.

May be related to #3702

@Its-Just-Nans Its-Just-Nans linked a pull request Jun 16, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant