-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #227 from arethetypeswrong/bug/184
Fix truncated stdout when piping more than 64kb
- Loading branch information
Showing
4 changed files
with
48 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@arethetypeswrong/cli": patch | ||
--- | ||
|
||
Fix truncated stdout when piping more than 64kb to another process |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { Readable, Writable } from "node:stream"; | ||
|
||
// JSON output is often longer than 64 kb, so we need to use streams to write it to stdout | ||
// in order to avoid truncation when piping to other commands. | ||
export async function write(data: string, out: Writable): Promise<void> { | ||
return new Promise((resolve, reject) => { | ||
const stream = new Readable({ | ||
read() { | ||
this.push(data); | ||
this.push("\n"); | ||
this.push(null); | ||
}, | ||
}); | ||
|
||
stream.on("data", (chunk) => { | ||
out.write(chunk); | ||
}); | ||
|
||
stream.on("end", () => { | ||
resolve(); | ||
}); | ||
|
||
out.on("error", (err) => { | ||
reject(err); | ||
}); | ||
}); | ||
} |
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