I want to parse a file's contents with a library that expects a std::io::Read. What's the most efficient way to do this in WASM-land?
I can use Node's readFileSync to get a Buffer object, but is there a better approach to getting a Read-able object than copying its entire contents into a byte array?
I don't think you'll be able to use the std::io::Read trait with Node types because Read is a synchronous pull-based API (i.e. the caller directly calls a read() method to read more), while JavaScript uses asynchronous push-based APIs (it does the reading in the background and will trigger a callback when it's done).
What I'd do is use fs.readFile() to ask Node to read the entire file into a buffer in the background, then pass that buffer to the WebAssembly code once it's done.
You could imagine the JavaScript looking something like this: