filter: fix streaming of large events

This commit is contained in:
Alex Gleason 2023-03-28 21:57:17 -05:00
parent ba482e5dfb
commit c087e8fddd
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7

View File

@ -19,15 +19,24 @@ for await (const line of readLines(Deno.stdin)) {
stdout: 'piped', stdout: 'piped',
}); });
await policy.stdin.write(new TextEncoder().encode(JSON.stringify(input))); const bytes = new TextEncoder().encode(JSON.stringify(input));
const writer = policy.stdin.writable.getWriter();
const chunkSize = 4096;
for (let i = 0; i < bytes.length; i += chunkSize) {
const chunk = bytes.slice(i, i + chunkSize);
await writer.write(chunk);
}
policy.stdin.close(); policy.stdin.close();
for await (const out of readLines(policy.stdout)) { for await (const out of readLines(policy.stdout)) {
const msg: OutputMessage = JSON.parse(out); const msg: OutputMessage = JSON.parse(out);
if (msg.action === 'accept') { if (msg.action === 'accept') {
console.log(JSON.stringify(event)); console.log(line);
}
break; break;
} }
} }
}