Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
What works on bun `1.1.6` and node `20`: | | macOS | Linux | | ------------------------------ | ------ | ------ | | 1. node + create/read stream | ok | ok | | 2. bun + create/read stream | broken | broken | | 3. bun + Bun.file/Bun.write | broken | sometimes? (works in ~75% of runs) | | 4. bun + onData + write stream | broken | ok | Code below: <details><summary>1. node + create/read stream</summary> ```js const fs = require("fs"); const { Pty } = require("../ruspty"); const pty = new Pty({ command: "/bin/sh", envs: { TERM: "xterm-256color", }, onExit: (err, exitCode) => { console.log({ err, exitCode }); pty.close(); }, }); const fd = pty.fd(); const readStream = fs.createReadStream("", { fd }); const writeStream = fs.createWriteStream("", { fd }); readStream.on("data", (chunk) => { console.log(Buffer.from(chunk).toString()); }); writeStream.write("ls --color=auto\n"); writeStream.write("exit\n"); ``` </details> <details><summary>2. bun + create/read stream</summary> ```js const fs = require("fs"); const { Pty } = require("../ruspty"); const pty = new Pty({ command: "/bin/sh", envs: { TERM: "xterm-256color", }, onExit: (err, exitCode) => { console.log({ err, exitCode }); pty.close(); }, }); const fd = pty.fd(); const readStream = fs.createReadStream("", { fd }); const writeStream = fs.createWriteStream("", { fd }); readStream.on("data", (chunk) => { console.log(Buffer.from(chunk).toString()); }); writeStream.write("ls --color=auto\n"); writeStream.write("exit\n"); ``` </details> <details><summary>3. bun + Bun.file/Bun.write</summary> ```js const { Pty } = require("../ruspty"); const pty = new Pty({ command: "/bin/sh", envs: { TERM: "xterm-256color", }, onExit: (err, exitCode) => { console.log({ err, exitCode }); pty.close(); }, }); const file = Bun.file(pty.fd()); async function read() { const stream = file.stream(); for await (const chunk of stream) { console.log(Buffer.from(chunk).toString()); } } read(); Bun.write(pty.fd(), "ls --color=auto\n"); Bun.write(pty.fd(), "exit\n"); ``` </details> <details><summary>4. bun + onData + write stream</summary> ```js const fs = require("fs"); const { Pty } = require("../ruspty"); const pty = new Pty({ command: "/bin/sh", envs: { TERM: "xterm-256color", }, onExit: (err, exitCode) => { console.log({ err, exitCode }); pty.close(); }, onData: (err, data) => { if (err) { console.log({ err }); } console.log(Buffer.from(data).toString()); }, }); const fd = pty.fd(); const writeStream = fs.createWriteStream("", { fd }); writeStream.write("ls --color=auto\n"); writeStream.write("exit\n"); // we have to wait and hope for the best setTimeout(() => {}, 3000); ``` </details> --------- Co-authored-by: lhchavez <[email protected]>
- Loading branch information