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:
parent
b0b1af4b3b
commit
3e160d6f5d
27
jsoniter.go
27
jsoniter.go
@ -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
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user