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


i'm working on file parsing library in c emscripten compile support. takes file path user reads binary file , parses it.

i understand emscripten doesn't support direct loading of files, instead uses virtual filesystem. there way load file @ given path virtual filesystem emscripten compiled c lib can read it? i'm looking solutions both nodejs , in browser.

if want compile file directly library can use --preload-file or --embed-file option. this:

emcc main.cpp -o main.html --preload-file /tmp/my@/home/caiiiycuk/test.file 

after in c can open file normally:

fopen("/home/caiiiycuk/test.file", "rb") 

or can use emscripten javascript fs-api, example ajax:

$.ajax({     url: "/dataurl",     type: 'get',     beforesend: function (xhr) {         xhr.overridemimetype("text/plain; charset=x-user-defined");     },     success: function( data ) {         module['fs_createdatafile']("/tmp", "test.file", data, true, true);     } }); 

after can open file c. not best way pass data c code, can pass data directly in memory, read this.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -