r.go | 14 +++----------- diff --git a/r.go b/r.go index 4833688cf6e9f7c230291fe3df9fa59a3ec353313e27272a29e958d0b3b24d4b..6789d4fc89f7b6e28e1835a9c135329a6765ad4f91eb1e6147d2c1b53bd3e9d2 100644 --- a/r.go +++ b/r.go @@ -19,7 +19,6 @@ package netstring import ( "bufio" - "bytes" "errors" "io" "strconv" @@ -44,19 +43,12 @@ func (r *Reader) Next() (uint64, error) { if !r.eof { return 0, errors.New("current chunk is unread") } - p, _ := r.r.Peek(21) - if len(p) == 0 { - return 0, io.EOF - } - idx := bytes.IndexByte(p, ':') - if idx == -1 { - return 0, errors.New("no length separator found") - } - size, err := strconv.ParseUint(string(p[:idx]), 10, 64) + lenRaw, err := r.r.ReadSlice(':') if err != nil { return 0, err } - if _, err = r.r.Discard(idx + 1); err != nil { + size, err := strconv.ParseUint(string(lenRaw[:len(lenRaw)-1]), 10, 64) + if err != nil { return 0, err } r.left = size