mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-20 16:57:46 +00:00
feat: Allow combining -p and stdin for prompt input (#4406)
Co-authored-by: Allen Hutchison <adh@google.com>
This commit is contained in:
@@ -5,14 +5,26 @@
|
||||
*/
|
||||
|
||||
export async function readStdin(): Promise<string> {
|
||||
const MAX_STDIN_SIZE = 8 * 1024 * 1024; // 8MB
|
||||
return new Promise((resolve, reject) => {
|
||||
let data = '';
|
||||
let totalSize = 0;
|
||||
process.stdin.setEncoding('utf8');
|
||||
|
||||
const onReadable = () => {
|
||||
let chunk;
|
||||
while ((chunk = process.stdin.read()) !== null) {
|
||||
if (totalSize + chunk.length > MAX_STDIN_SIZE) {
|
||||
const remainingSize = MAX_STDIN_SIZE - totalSize;
|
||||
data += chunk.slice(0, remainingSize);
|
||||
console.warn(
|
||||
`Warning: stdin input truncated to ${MAX_STDIN_SIZE} bytes.`,
|
||||
);
|
||||
process.stdin.destroy(); // Stop reading further
|
||||
break;
|
||||
}
|
||||
data += chunk;
|
||||
totalSize += chunk.length;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user