3

I would like to create a web application that utilizes some C library (EDFLib) to read EDF files. The idea would be that the user picks a local file through a <input type="file" /> to be parsed by the C library. The C library uses fopen to read a given path file to parse the header and then you can read chunks of that file at any offset, which makes reading quite optimal. EDF files are usually quite big as they contain a significant number of bio signals (a normal file can be around 400MB).

I have been able to compile the C library with the emscripten tools and make the calls to the library successfully. However, I am not sure how to address this situation of passing a file that has been picked by the user due to the limitation of the sandbox of the VM.

I have found other similar question, but the solution proposed is about copying the content of the file to the virtual file system, and then use that copied file in the routines of the library. I would like to know if there is some workaround to avoid copying the file to avoid the overload of reading such a big file directly in javascript as it would penalty the performance of the app significantly.

In my mind, as the user picks the file, it should be also accessible to the WebAssembly context without having to perform any extra action. This is well illustrated in the following picture (taken from this Mozilla post on WASI). So when the user selects a file, there should be some path or file descriptor that can be passed to the C code. However, I have not found a way to do so.

illustration of webassembly indicating which files and folders are accessible for the JS application

Any idea whether what I am trying to do is feasible or not?

Humberto
  • 31
  • 1
  • WASI -> run WebAssembly outside the web.. Your best approach is maybe using Streams.. – Keith Jun 24 '20 at 11:09
  • I also thought of streams as an option, but I cannot picture how to translate from JS stream into C stream – Humberto Jun 24 '20 at 16:05

0 Answers0