1
0
mirror of https://github.com/json-iterator/go.git synced 2024-11-27 08:30:57 +02:00

fix read from io.Reader, n == 0 is not eof

This commit is contained in:
Tao Wen 2016-12-05 14:18:16 +08:00
parent b0b1af4b3b
commit 3e160d6f5d

View File

@ -73,20 +73,25 @@ func (iter *Iterator) readByte() (ret byte) {
iter.Error = io.EOF
return
}
n, err := iter.reader.Read(iter.buf)
if err != nil {
iter.Error = err
return
for {
n, err := iter.reader.Read(iter.buf)
if n == 0 {
if err != nil {
iter.Error = err
return
} else {
// n == 0, err == nil is not EOF
continue
}
} else {
iter.head = 0
iter.tail = n
break
}
}
if n == 0 {
iter.Error = io.EOF
return
}
iter.head = 0
iter.tail = n
}
ret = iter.buf[iter.head]
iter.head += 1
iter.head++
return ret
}