forked from oven-sh/bun
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix ReadFileUV not reading to the end of a non-regular file on Windows (
- Loading branch information
Showing
3 changed files
with
24 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,18 @@ | ||
console.write(await Bun.stdin.text()); | ||
const input = await Bun.stdin.text(); | ||
|
||
if (process.platform == "win32") { | ||
// powershell unavoidably appends \r\n to text sent from a powershell command (like Get-Content) | ||
// to an external program (like bun) | ||
// https://github.com/PowerShell/PowerShell/issues/5974 | ||
// so we have to remove it | ||
// for sanity check that it actually ends in \r\n | ||
const CR = "\r".charCodeAt(0); | ||
const LF = "\n".charCodeAt(0); | ||
if (input.charCodeAt(input.length - 2) !== CR || input.charCodeAt(input.length - 1) !== LF) { | ||
throw new Error(`input of ${input.length} bytes does not end in CRLF`); | ||
} | ||
const trimmed = input.substring(0, input.length - 2); | ||
console.write(trimmed); | ||
} else { | ||
console.write(input); | ||
} |
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