Alright so now I need to do the opposite and I am having some difficulties.

I am using FileSaver,js located at 
http://purl.eligrey.com/github/FileSaver.js to allow the user to download a 
file from the Emscripten file system to a location on the user's system.

In my C++ code, I can do something like this to call the JavaScript to save 
a text file:
emscripten_run_script(
        (char*)((std::string)
        "var fileName = 'em_file.txt'; " +
        "var text = Module.ccall('EM_readFile', 'string', ['string'], 
[fileName]); " + // EM_readFile returns a char* of the file content
        "var blob = new Blob([text], {type: \"text/plain;charset=utf-8\"}); 
" +
        "saveAs(blob, fileName+\".txt\");"
        ).c_str()
    );

This code works and brings up a dialog to save the file to a location, but 
doesn't correctly save files with binary data (such as an image). *Note 
that if I save the contents to a location in the Emscripten file system, I 
am able to load the image (so I know the content in the char* is not 
corrupt)*

I tried returning 'array' from EM_readFile in hopes I could make it a 
Uint8Array, but that didn't work (Assert failed, return type cannot be 
'array').

Could someone see where I am making a mistake?

-- 
You received this message because you are subscribed to the Google Groups 
"emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to