oficina / equipo Public

Clone
git clone https://amadan.net/oficina/equipo

Plain git — no account needed to clone.

Download

Download this file

1package copydesk
2
3import "sync"
4
5// Output keeps structured command output bounded without truncating JSON lines.
6type Output struct {
7 mu sync.Mutex
8 data []byte
9 over bool
10}
11
12func (o *Output) Write(p []byte) (int, error) {
13 o.mu.Lock()
14 defer o.mu.Unlock()
15 n := len(p)
16 remaining := (2 << 20) - len(o.data)
17 if len(p) > remaining {
18 o.over = true
19 p = p[:remaining]
20 }
21 o.data = append(o.data, p...)
22 return n, nil
23}
24func (o *Output) Result() (string, bool) {
25 o.mu.Lock()
26 defer o.mu.Unlock()
27 return string(o.data), o.over
28}
29