-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bun currently has a bug where raw FDs don't interact well with `fs.createReadStream`, and the result is that not all data is seen by the `'data'` callback: oven-sh/bun#9907 This change is an egregious workaround that makes Rust read the file until the process closes it. It is suboptimal because of all the data copying that happens, and crossing the FFI barrier also takes some time, but at least this should let us not be completely blocked. Now there is one more (optional) argument to `Pty` that is a replacement of the `'data'` callback. ```shell ~/ruspty$ cat test.js const { Pty } = require('./index'); const fs = require('fs'); const ENV = process.env; const CWD = '.'; let firstread = true; const pty = new Pty( 'sh', [], ENV, CWD, { rows: 24, cols: 80 }, (...result) => { console.log({ result }); pty.close(); }, (err, chunk) => { if (err !== null) { throw err; } console.log(chunk.toString()); if (firstread) { write.write('ls\n', () => { console.log('ls written'); write.end('exit\n', () => { console.log('end done'); }); }); firstread = false; } }, ); const write = fs.createWriteStream('', { fd: pty.fd(), autoClose: true, }); write.on('close', () => { console.log('write close'); }); write.on('error', (err) => { if (err.code && err.code.indexOf('EIO') !== -1) { console.log('YAY'); } else { console.log('write error', { err }); } }); console.log('gonna wait'); setTimeout(() => { console.log('done, hopefully'); }, 3000); ~/ruspty$ ./node_modules/.bin/bun --version 1.1.7 ~/ruspty$ ./node_modules/.bin/bun test.js gonna wait sh-5.2$ ls written end done ls exit write close 1.0.26.txt build.rs index.js package-lock.json src 1.1.7.txt bun.lockb index.test.ts package.json target Cargo.lock flake.lock node.txt replit.nix test.js Cargo.toml flake.nix node_modules ruspty.linux-x64-gnu.node README.md index.d.ts npm rustfmt.toml sh-5.2$ exit { result: [ null, 0 ], } done, hopefully ``` --------- Co-authored-by: Szymon Kaliski <[email protected]>
- Loading branch information
1 parent
443152a
commit d83a57a
Showing
4 changed files
with
163 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters