emscripten-core/emscripten

FS_createPreloadedFile not supported in MEMFS under node.js, but could easily be

Open

#16,742 创建于 2022年4月16日

在 GitHub 查看
 (3 评论) (0 反应) (0 负责人)C++ (27,361 star) (3,519 fork)batch import
good first bughelp wanted

描述

I have code that runs in the browser using lazily loaded files, and I would very much like to be able to test it on the command-line using node.js without having to recompile it. As noted in https://github.com/emscripten-core/emscripten/issues/16740, lazy loading is broken under node.js because it corrupts binary files. So the alternative is to pre-load these files in a preRun() callback.

Unfortunately this doesn't work either, because createPreloadedFile() calls Browser.handledByPreloadPlugin(), but since this is node.js, there is no Browser:

https://github.com/emscripten-core/emscripten/blob/c38e6c8cfba28980aea8f895c71b376e8a5155d5/src/library_fs.js#L1864

Well, that's fine, this is JavaScript after all, I can just make a dummy Browser object in my test code, and now it works:

Browser = {
    handledByPreloadPlugin() {
        return false;
    }
};

But really I shouldn't have to do this :) Am I missing something in the documentation, is there a better way to do this (yes, I know that I can just use NODEFS or NODERAWFS, but as mentioned above, I don't want to recompile just to run a test).

My emscripten version:

emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.8 (3ff7eff373d31d8c0179895165462019221f192e)
clang version 15.0.0 (https://github.com/llvm/llvm-project 80ec0ebfdc5692a58e0832125f2c6a991df9d63f)

贡献者指南

FS_createPreloadedFile not supported in MEMFS under node.js, but could easily be · emscripten-core/emscripten#16742 | Good First Issue