Efficient way to share data between Rust and JS, with WASM

In JS I'm loading in images (which will be displayed on a canvas). I need to read the width and height from these images, and send that data to Rust.

Do I just bundle the images' data in JS, to then send that; array?, object?, array of objects? to a Rust function at once?

Is this a good way?

I would want to setup something like this: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiateStreaming. But I'm using wasm-pack build, and it doesn't work off the bat like the example.

If you are sending the content of the image, i.e. width * height * depth bytes, you probably want Uint8Array.

If all you are sending is (width, height) i.e. (u32, u32), you can probably just use json.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.