BrowserFS icon indicating copy to clipboard operation
BrowserFS copied to clipboard

`EmscriptenFS` and preloading

Open pmp-p opened this issue 2 years ago • 13 comments

Hi, I have the following layout for running Pygame games apk directly on web

   // VM is emscripten Module, modularized or not

    VM.APK = "org.pygame.asteroids"
    var BFS = new BrowserFS.EmscriptenFS()

    const Buffer = BrowserFS.BFSRequire('buffer').Buffer;

    function apk_cb(e, apkfs){
        console.log(__FILE__,"APK", VM.APK,"received")
        window.document.title = VM.APK
        BrowserFS.FileSystem.InMemory.Create(
            function(e, memfs) {
                BrowserFS.FileSystem.OverlayFS.Create({"writable" :  memfs, "readable" : apkfs },
                    function(e, ovfs) {
                                BrowserFS.FileSystem.MountableFileSystem.Create({
                                    '/' : ovfs
                                    }, async function(e, mfs) {
                                        await BrowserFS.initialize(mfs);
                                        // BFS is now ready to use!
                                        await VM.FS.mount(BFS, {root: "/"}, "/data/data/" + VM.APK );
                                        await VM.FS.mkdir("/data/data/" + VM.APK + "/need-preload");
                                        VM.vfs = BFS
                                    })
                    }
                );

            }
        );
    }

    fetch(VM.APK + ".apk").then(function(response) {
        return response.arrayBuffer();
    }).then(function(zipData) {
        BrowserFS.FileSystem.ZipFS.Create({"zipData" : Buffer.from(zipData),"name":"apkfs"}, apk_cb)
    })

but emscripten_run_preload_plugins() cannot operate on Wasm/Image/Audio files located under /data/data//. error messages are all like
Image blob:http://localhost:8000/b5c7a41e-0824-4c8c-b1b2-672608468e73 could not be decoded `

browserfs 1.4.3

ref: https://emscripten.org/docs/api_reference/emscripten.h.html#c.emscripten_run_preload_plugins

pmp-p avatar Apr 02 '22 23:04 pmp-p