strfry-policies/src/io.ts

21 lines
509 B
TypeScript
Raw Normal View History

2023-03-24 19:36:11 +00:00
import { readLines } from './deps.ts';
import type { InputMessage, OutputMessage } from './types.ts';
2023-03-24 19:36:11 +00:00
/**
* Parse strfy messages from stdin.
* strfry may batch multiple messages at once.
2023-03-24 19:36:11 +00:00
*/
async function* readStdin(): AsyncGenerator<InputMessage> {
for await (const line of readLines(Deno.stdin)) {
yield JSON.parse(line);
}
2023-03-24 19:36:11 +00:00
}
/** Writes the output message to stdout. */
function writeStdout(msg: OutputMessage): void {
console.log(JSON.stringify(msg));
}
export { readStdin, writeStdout };