readLinePrefix will consume the entire line from the reader, but will return only the first maxLen bytes from it - the rest is discarded. Returns io.EOF when the end of the input has been reached.
(br *bufio.Reader, maxLen int)
| 99 | // but will return only the first maxLen bytes from it - the rest is discarded. |
| 100 | // Returns io.EOF when the end of the input has been reached. |
| 101 | func readLinePrefix(br *bufio.Reader, maxLen int) (line string, err error) { |
| 102 | for { |
| 103 | var raw []byte |
| 104 | var isPrefix bool |
| 105 | |
| 106 | raw, isPrefix, err = br.ReadLine() |
| 107 | if err != nil && err != io.EOF { //nolint:errorlint |
| 108 | return "", err |
| 109 | } |
| 110 | |
| 111 | if needMore := maxLen - len(line); needMore > 0 { |
| 112 | if len(raw) > needMore { |
| 113 | line += string(raw[:needMore]) |
| 114 | } else { |
| 115 | line += string(raw) |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | if !isPrefix || len(raw) == 0 { |
| 120 | break |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | return line, err |
| 125 | } |
no outgoing calls
searching dependent graphs…