diff options
| author | Robby Zambito <contact@robbyzambito.me> | 2026-01-24 10:55:29 -0500 |
|---|---|---|
| committer | Robby Zambito <contact@robbyzambito.me> | 2026-01-24 11:28:18 -0500 |
| commit | fc9c5bcd5db71cc93b78b34165485ceb92ffacc8 (patch) | |
| tree | d96b72b3de3a9b8afaed48081d12bd39b1eb2584 /src/main.zig | |
| parent | 157afa13b1f670ec7e8264056c19785f46cb339c (diff) | |
Chunk messages to 1000 byte payloads
Diffstat (limited to 'src/main.zig')
| -rw-r--r-- | src/main.zig | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/src/main.zig b/src/main.zig index e8b2e5b..d6d825a 100644 --- a/src/main.zig +++ b/src/main.zig @@ -127,14 +127,21 @@ pub fn main(init: std.process.Init) !void { var child_stderr: std.ArrayList(u8) = .empty; defer child_stderr.deinit(init.gpa); - try child.collectOutput(init.gpa, &child_stdout, &child_stderr, 2048); + try child.collectOutput(init.gpa, &child_stdout, &child_stderr, std.math.maxInt(usize)); - const b64e = std.base64.standard.Encoder; - var cmd_output_buf: [2048]u8 = undefined; - const encoded_cmd_output = b64e.encode(&cmd_output_buf, child_stdout.items); + // const b64e = std.base64.standard.Encoder; + var cmd_output: Writer = blk: { + var cmd_output_buf: [2048]u8 = undefined; + break :blk .fixed(&cmd_output_buf); + }; - connection.send(init.io, encoded_cmd_output) catch continue; - try init.io.sleep(.fromMilliseconds(40), .real); + var cmd_output_window_iter = std.mem.window(u8, child_stdout.items, SaprusClient.max_payload_len, SaprusClient.max_payload_len); + while (cmd_output_window_iter.next()) |chunk| { + cmd_output.end = 0; + try cmd_output.print("{b64}", .{chunk}); + try connection.send(init.io, cmd_output.buffered()); + try init.io.sleep(.fromMilliseconds(40), .real); + } } } } |
