I have an application which runs in desktop (compiled with gcc 10 for x86_64 arch) and in emscripten (compiled with emscripten and run through nodejs). This code produces some files I need to save.
In the case of x86_64 its pretty simple, I just use std::ofstream, but in the case of emscripten, I am not sure how to proceed. I have read the wiki and it says the filesystem that emscripten provides is virtual and lives in memory, but they also say there are some ways to save files into the host filesystem (https://emscripten.org/docs/api_reference/Filesystem-API.html).
However, I haven't been able to save a file from emscripten directly to the host filesystem
I would appreciate an example on how to save a file using emscripten.
As an example of what I am trying to achieve,
main.cpp:
#include <fstream>
int main()
{
std::ofstream os("log.txt", std::ios::trunc);
os << "a";
}
compiled with
em++ main.cpp
and executed as
node a.out.wasm
The issue is that this doesn't saves the log.txt
. How could I tell emscripten to write that file to my host filesystem?