Open vadimkantorov opened 3 years ago
For apps that use stdin a lot it would be nice to have a way to pass whole arrays/buffers in.
I made this work-around for my project, to intercept calls to getc
and read from a buffer.
https://github.com/curiousdannii/emglken/blob/master/src/getc.c
But if you need more functions it would get increasingly messy. And it requires ASYNCIFY.
Okay, this version is much faster, but the original feature request to allo direct uint8array consumption still stands:
stdin()
{
const ord = Module.input_stdin_binary[Module.input_stdin_binary_iterator++];
return ord === undefined ? null : ord;
}
I don't know if this would be enough for your use case, but some people might only need to provide a single buffer at the start (in the Module object), which could be handled without too much difficulty. But if someone needed to provided more buffers later on, then that would be much more complex.
This issue has been automatically marked as stale because there has been no activity in the past year. It will be closed automatically if no further activity occurs in the next 30 days. Feel free to re-open at any time if this issue is still relevant.
stale bump
Same for stdout. It'd be much more convenient to have such an option as built-in instead of inefficiently appending bytes in stdout(ord)
overload in JavaScript
It would also be nice to support bash-like redirects from/to file
Overriding Module.stdin and doing an iterator works, but is very slow for large-ish inputs:
I'm using this to calculate sha1 hash with busybox's sha1sum. I'm comparing providing file contents as stdin and calling sha1sum versus saving the contents to a temp file and calling sha1sum. The first is so much slower - probably for no good reason