MCPcopy Index your code
hub / github.com/wavetermdev/waveterm / streamToLines_processBuf

Function streamToLines_processBuf

tsunami/util/streamtolines.go:37–57  ·  view source on GitHub ↗
(lineBuf *lineBuf, readBuf []byte, lineFn func([]byte))

Source from the content-addressed store, hash-verified

35}
36
37func streamToLines_processBuf(lineBuf *lineBuf, readBuf []byte, lineFn func([]byte)) {
38 for len(readBuf) > 0 {
39 nlIdx := bytes.IndexByte(readBuf, '\n')
40 if nlIdx == -1 {
41 if lineBuf.inLongLine || len(lineBuf.buf)+len(readBuf) > maxLineLength {
42 lineBuf.buf = nil
43 lineBuf.inLongLine = true
44 return
45 }
46 lineBuf.buf = append(lineBuf.buf, readBuf...)
47 return
48 }
49 if !lineBuf.inLongLine && len(lineBuf.buf)+nlIdx <= maxLineLength {
50 line := append(lineBuf.buf, readBuf[:nlIdx]...)
51 lineFn(line)
52 }
53 lineBuf.buf = nil
54 lineBuf.inLongLine = false
55 readBuf = readBuf[nlIdx+1:]
56 }
57}
58
59func StreamToLines(input io.Reader, lineFn func([]byte)) error {
60 var lineBuf lineBuf

Callers 2

StreamToLinesFunction · 0.70
WriteMethod · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected