diff --git a/benchmarks/bench_test.go b/benchmarks/bench_test.go index db85546..438ff03 100644 --- a/benchmarks/bench_test.go +++ b/benchmarks/bench_test.go @@ -14,6 +14,7 @@ import ( "bytes" "compress/gzip" "fmt" + "io" "io/ioutil" "os" "strings" @@ -373,7 +374,9 @@ func BenchmarkCodeDecoder(b *testing.B) { buf.WriteByte('\n') buf.WriteByte('\n') if err := dec.Decode(&r); err != nil { - b.Fatal("Decode:", err) + if err != io.EOF { + b.Fatal("Decode:", err) + } } } }) @@ -390,7 +393,9 @@ func BenchmarkUnicodeDecoder(b *testing.B) { b.ResetTimer() for i := 0; i < b.N; i++ { if err := dec.Decode(&out); err != nil { - b.Fatal("Decode:", err) + if err != io.EOF { + b.Fatal("Decode:", err) + } } r.Seek(0, 0) } @@ -414,7 +419,9 @@ func BenchmarkDecoderStream(b *testing.B) { } x = nil if err := dec.Decode(&x); err != nil || x != 1.0 { - b.Fatalf("Decode: %v after %d", err, i) + if err != io.EOF { + b.Fatalf("Decode: %v after %d", err, i) + } } } } diff --git a/decode.go b/decode.go index 20e2e18..255a7b5 100644 --- a/decode.go +++ b/decode.go @@ -61,7 +61,6 @@ const ( // read data from r beyond the JSON values requested. func NewDecoder(r io.Reader) *Decoder { s := newStream(r) - s.read() return &Decoder{ s: s, } diff --git a/decode_stream.go b/decode_stream.go index c5d203b..c955e53 100644 --- a/decode_stream.go +++ b/decode_stream.go @@ -26,6 +26,7 @@ func newStream(r io.Reader) *stream { return &stream{ r: r, bufSize: initBufSize, + buf: []byte{nul}, } }