Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
albrow opened this issue Apr 16, 2019 · 3 comments

Comments

@albrow
Copy link

albrow commented Apr 16, 2019

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.

@dr-vortex
Copy link
Collaborator

@albrow BrowserFs doesn't even support stdout/stdin/stderr. As those streams are related to the process, maybe the could be introduced to bfs-process and forwarded to BrowserFS?

@albrow
Copy link
Author

albrow commented Mar 10, 2023

@dr-vortex thanks for your reply. It's been a long time since I opened this issue and I'm no longer working on the project that originally prompted me to open it.

At first glance, your suggestion of introducing stdout/stdin/stderr support to bfs-process seems like a good place to start. I also would have been fine with a more crude solution (something like special casing these file descriptors to print text directly via console.log or console.error).

That said, I don't really have a need for this anymore and unless someone else chimes in, you can feel free to close the issue.

@dr-vortex
Copy link
Collaborator

@albrow Thanks for the fast reply! I checked it using Node and using the FS API to interact with stdin/stdout/atderr actually results in EBADF... It's not a bug, it's a feature!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants