Until implements Connection.
(delim byte)
| 196 | |
| 197 | // Until implements Connection. |
| 198 | func (c *connection) Until(delim byte) (line []byte, err error) { |
| 199 | var n, l int |
| 200 | for { |
| 201 | if err = c.waitRead(n + 1); err != nil { |
| 202 | // return all the data in the buffer |
| 203 | line, _ = c.inputBuffer.Next(c.inputBuffer.Len()) |
| 204 | return |
| 205 | } |
| 206 | |
| 207 | l = c.inputBuffer.Len() |
| 208 | i := c.inputBuffer.indexByte(delim, n) |
| 209 | if i < 0 { |
| 210 | n = l // skip all exists bytes |
| 211 | continue |
| 212 | } |
| 213 | return c.Next(i + 1) |
| 214 | } |
| 215 | } |
| 216 | |
| 217 | // ReadString implements Connection. |
| 218 | func (c *connection) ReadString(n int) (s string, err error) { |