From c087e8fdddf256fd0a9a088cd62f608baaac0793 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Tue, 28 Mar 2023 21:57:17 -0500 Subject: [PATCH] filter: fix streaming of large events --- scripts/filter.ts | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/scripts/filter.ts b/scripts/filter.ts index 86460a1..65462eb 100644 --- a/scripts/filter.ts +++ b/scripts/filter.ts @@ -19,15 +19,24 @@ for await (const line of readLines(Deno.stdin)) { 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(); for await (const out of readLines(policy.stdout)) { const msg: OutputMessage = JSON.parse(out); if (msg.action === 'accept') { - console.log(JSON.stringify(event)); - break; + console.log(line); } + + break; } }