Skip to content

Commit 24bd52c

Browse files
committed
use buffer methods
1 parent ada991b commit 24bd52c

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

api/agent/func_logger.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,20 +103,20 @@ func (li *lineWriter) Write(ogb []byte) (int, error) {
103103
}
104104
li.b.Write(ogb) // bytes.Buffer is guaranteed, read it!
105105

106+
var n int
106107
for {
107-
b := li.b.Bytes()
108-
i := bytes.IndexByte(b, '\n')
109-
if i < 0 {
110-
break // no more newlines in buffer
108+
// read the line and advance buffer past it
109+
l, err := li.b.ReadBytes('\n')
110+
if err != nil {
111+
break // no more newlines in buffer (see ReadBytes contract)
111112
}
112113

113-
// write in this line and advance buffer past it
114-
l := b[:i+1]
114+
// write in the line
115115
ns, err := li.w.Write(l)
116+
n += ns
116117
if err != nil {
117-
return ns, err
118+
return n, err
118119
}
119-
li.b.Next(len(l))
120120
}
121121

122122
// technically we wrote all the bytes, so make things appear normal

0 commit comments

Comments
 (0)