(lineBuf *lineBuf, readBuf []byte, lineFn func([]byte))
| 35 | } |
| 36 | |
| 37 | func 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 | |
| 59 | func StreamToLines(input io.Reader, lineFn func([]byte)) error { |
| 60 | var lineBuf lineBuf |
no outgoing calls
no test coverage detected