BrowserFS icon indicating copy to clipboard operation
BrowserFS copied to clipboard

Add support for special file descriptors 0, 1, and 2 (stdin, stdout, and stderr).

Open albrow opened this issue 6 years ago • 0 comments

In Node.js, the special file descriptors 0, 1, and 2 correspond to stdin, stdout, and stderr. You can write to these file descriptors directly using e.g., fs.writeSync:

const fs = require("fs");
fs.writeSync(1, "Hello\n");
> Hello

It would be awesome if BrowserFS could add support for this. Currently, if you try to the same code above with BrowserFS you get an "EBADF: Invalid file descriptor." error.

I think the right place to start is the fd2file method.

FWIW I'm using LocalStorage as a backend, but I think this applies to all backends.

As to why this would be useful, it's a bit complicated. I'm currently working on a project that compiles to WebAssembly. Some low level code in a dependency wants to be able to write directly to these special file descriptors. The low level code was written with Node.js in mind, but if BrowserFS supported these file descriptors, we could use it as a drop in solution. Happy to provide more information if needed. There are probably other applications which could benefit from this as well.

albrow avatar Apr 16 '19 23:04 albrow