From 239e4dfbd8d8ab29ad75ea67288abaa31a63233e Mon Sep 17 00:00:00 2001 From: Eric Bower Date: Sat, 23 Nov 2024 22:17:12 -0500 Subject: [PATCH] fix: StdCopy into io.Pipe into bufio.Scanner --- main.go | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index 98f2600..cbf46bd 100644 --- a/main.go +++ b/main.go @@ -1,6 +1,7 @@ package main import ( + "bufio" "context" "flag" "io" @@ -71,9 +72,19 @@ func containerStart(ctx context.Context, logger *slog.Logger, client *client.Cli } go func() { - _, err = stdcopy.StdCopy(reconn, reconn, readCloser) - if err != nil { - logger.Error("cannot write to pipe topic", "err", err) + r, w := io.Pipe() + go func() { + _, err = stdcopy.StdCopy(w, w, readCloser) + if err != nil { + logger.Error("cannot write to pipe topic", "err", err) + } + }() + scanner := bufio.NewScanner(r) + for { + for scanner.Scan() { + line := scanner.Text() + reconn.Write([]byte(line + "\n")) + } } }()