Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I read a user-specified file in an emscripten compiled library?

I'm currently working on a file parsing library in C with emscripten compile support. It takes a file path from the user where it reads the binary file and parses it.

I understand that emscripten doesn't support direct loading of files, but instead uses a virtual filesystem. Is there any way to load the file at the given path into the virtual filesystem so that the emscripten compiled C lib can read it? I'm looking for solutions for both NodeJS and in the browser.

like image 714
Ryan LeFevre Avatar asked Jun 02 '14 14:06

Ryan LeFevre


1 Answers

Emscripten, as of today (June 2016), supports a filesystem called NODEFS which provides access to the local file-system when running on nodejs.

You need to manually mount the NODEFS filesystem into the root filesystem. For example:

EM_ASM(
  FS.mkdir('/working');
  FS.mount(NODEFS, { root: '.' }, '/working');
);

You can then access ./abc from the local filesystem via the virtual path /working/abc.

like image 183
HRJ Avatar answered Sep 21 '22 17:09

HRJ