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 process.stdin, process.stdout and process.stderr #894

Closed
Perodactyl opened this issue Jul 28, 2022 · 7 comments
Closed

Add process.stdin, process.stdout and process.stderr #894

Perodactyl opened this issue Jul 28, 2022 · 7 comments
Labels
node.js Compatibility with Node.js APIs

Comments

@Perodactyl
Copy link

Perodactyl commented Jul 28, 2022

What is the problem this feature will solve?

It will allow more compatibility with node.js programs and make it easy(or maybe even stop it from being impossible) to receive user input.

What is the feature you are proposing to solve the problem?

Adding More support for process.stdin and process.stdout (specifically, process.stdin.on("data", ()=>{...} and process.stdout.write("..."))

What alternatives have you considered?

I have no fix for stdin so far, stdout I could maybe store all my lines in a string and log them whenever (would still always end in a newline, but would fix writing chars without an automatic newline)

@Perodactyl Perodactyl added the enhancement New feature or request label Jul 28, 2022
@xHyroM xHyroM added node.js Compatibility with Node.js APIs polyfill and removed enhancement New feature or request labels Aug 4, 2022
@franciscop
Copy link

I'd be happy to provide a polyfill for process.stdin and process.stdout, but I'm blocked (which in turns blocks me on #311 (comment)) in trying to get process.stdout behave like a WritableStream at all see original:

console.log(Bun.stdin.stream(), Bun.stdout.stream());
// ReadableStream { } ReadableStream { }

I have tried many things in JS-land to no avail, so would love some input about how to make Bun.stdout behave somehow like a WritableStream instead of a ReadableStream, or how to write data to it in any way. Unfortunately the Zig source code is illegible for me, so I've been trying things in JS-land only.

@samfundev
Copy link
Contributor

@franciscop You need to use Bun.write and Bun.stdout together:

// log a file to stdout
await Bun.write(Bun.stdout, Bun.file("input.txt"));

@xHyroM xHyroM changed the title Add process.stdin and process.stdout Add process.stdin, process.stdout and process.stderr Aug 25, 2022
@samccone
Copy link

samccone commented Sep 4, 2022

Shimming my global process.stderr does the trick in my case: (your mileage might vary)

if (typeof process.stderr == "undefined") {
  process.stderr = Bun.stderr;
}

@guest271314
Copy link
Contributor

Do not repeat the same restrictive pattern as Node.js where 'readable' event must be set with handler for process.stdin.read() to work nodejs/node#43918 (comment)

The implementation is such that the readable event must be used it has nothing to do with the readable state indicator.

Use a pattern the similar to QuickJS

const header = new Uint32Array(1);
std.in.read(header.buffer, 0, 4);

or Deno

const header = new Uint32Array(1);
await Deno.stdin.read(header);

@guest271314
Copy link
Contributor

@franciscop You need to use Bun.write and Bun.stdout together:

// log a file to stdout
await Bun.write(Bun.stdout, Bun.file("input.txt"));

Unfortunately I can't get Bun.read() or Bun.write() to work within a Native Messaging host #1297. I didn't locate any documentation nor tests for Bun.write() and Bun.read(), particularly missing as TypedArray input to Bun.write() and getting stdin from a non-TTY application. It would be helpful to write out what is being shipped now, with tests, even if the implementation is temporary.

@samfundev
Copy link
Contributor

I believe this issue can be closed with the release of v0.3.0.

@Electroid
Copy link
Contributor

Yep! This is now supported in Bun v0.3.0 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
node.js Compatibility with Node.js APIs
Projects
None yet
Development

No branches or pull requests

7 participants