GeezerVison is showing github.com — Send messages in chunks and not per character · PastureStack/host-api@973d782
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: exec/exec.go +14-14Lines changed: 14 additions & 14 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
1 | 1 | package exec |
2 | 2 |
|
3 | 3 | import ( |
4 | | - "bufio" |
5 | 4 | "encoding/base64" |
6 | 5 | "io" |
7 | 6 | "net/url" |
@@ -70,20 +69,21 @@ func (h *ExecHandler) Handle(key string, initialMessage string, incomingMessages |
70 | 69 | }(outputWriter) |
71 | 70 |
|
72 | 71 | go func(r *io.PipeReader) { |
73 | | - scanner := bufio.NewScanner(r) |
74 | | - scanner.Split(bufio.ScanRunes) |
75 | | - for scanner.Scan() { |
76 | | - data := scanner.Bytes() |
77 | | - text := base64.StdEncoding.EncodeToString(data) |
78 | | - message := common.Message{ |
79 | | - Key: key, |
80 | | - Type: common.Body, |
81 | | - Body: text, |
| 72 | + buffer := make([]byte, 4096, 4096) |
| 73 | + for { |
| 74 | + c, err := r.Read(buffer) |
| 75 | + if c > 0 { |
| 76 | + text := base64.StdEncoding.EncodeToString(buffer[:c]) |
| 77 | + message := common.Message{ |
| 78 | + Key: key, |
| 79 | + Type: common.Body, |
| 80 | + Body: text, |
| 81 | + } |
| 82 | + response <- message |
| 83 | + } |
| 84 | + if err != nil { |
| 85 | + break |
82 | 86 | } |
83 | | - response <- message |
84 | | - } |
85 | | - if err := scanner.Err(); err != nil { |
86 | | - log.WithFields(log.Fields{"error": err}).Error("Error with the exec scanner.") |
87 | 87 | } |
88 | 88 | }(outputReader) |
89 | 89 |
|
|