emscripten-core / emscripten-core/emscripten

Best practice for handling blobs JS<->WASM in web-situations

Open
#18,769 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
27.6k
Forks
3.6k
Avg merge
1d 1h
Merged PRs (30d)
105

Description

I would like to request what is the current best practice to exchange binary-blobs between the C (wasm compiled by Emscripten) and JS parts.
There are `UInt8Array` conversions to `ptr` which can work but I would prefer to have more application-oriented variants of these. I couldn't find a documentation place that kind of gathers these.

- e.g. I would like to have information about a zone of memory that can be shared between both for a slightly long time (a few seconds?)
- e.g. there could be code examples of shared memory that is used for streaming APIs (e.g. when the JS receives chunks from the user or when the C produces a picture)
- e.g. I wish to find ways to read the bytes of a user-dropped file from web-assembly without it being converted to base64 before.
- e.g. I wish to find ways for the wasm to produce the bytes of a file that is downloaded to the user's desktop

This ticket is thus to request hints and, possibly, documentation pages that could do so.
Or maybe a best practice github project could show this.

- - -
Please include the following in your bug report:

**Version of emscripten/emsdk:**
versions up to 3.1.31

**Full link command and output with `-v` appended:**
`emcc -c "x.cpp" -o "x.bc" -I"cpp" -DUSE_CA_MODULES -DDISABLE_OPENGL -DHAVE_EXPAT_CONFIG_H -DW_DOTS --bind -s WASM=1 -g -O0`

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.