1
0
mirror of https://github.com/json-iterator/go.git synced 2025-04-04 21:34:16 +02:00

fix lazy load more

This commit is contained in:
Tao Wen 2017-12-23 10:52:17 +08:00
parent e7a8aea845
commit 96fcb84835
2 changed files with 4 additions and 7 deletions

@ -71,8 +71,10 @@ type Decoder struct {
// Decode decode JSON into interface{}
func (adapter *Decoder) Decode(obj interface{}) error {
if adapter.iter.Error == io.EOF {
return io.EOF
if adapter.iter.head == adapter.iter.tail && adapter.iter.reader != nil {
if !adapter.iter.loadMore() {
return io.EOF
}
}
adapter.iter.ReadVal(obj)
err := adapter.iter.Error

@ -337,11 +337,6 @@ func (cfg *frozenConfig) NewEncoder(writer io.Writer) *Encoder {
func (cfg *frozenConfig) NewDecoder(reader io.Reader) *Decoder {
iter := Parse(cfg, reader, 512)
if reader != nil {
if !iter.loadMore() {
iter.Error = io.EOF
}
}
return &Decoder{iter}
}