Revert "bencode: Trailing bytes on Unmarshal is an error"

This reverts commit ad73a0ea89.
This commit is contained in:
Matt Joiner 2015-08-23 19:10:22 +10:00
parent 0403d4185d
commit 577ea21793
1 changed files with 2 additions and 17 deletions

View File

@ -3,7 +3,6 @@ package bencode
import (
"bufio"
"bytes"
"errors"
"fmt"
"io"
"reflect"
@ -128,23 +127,9 @@ func Marshal(v interface{}) ([]byte, error) {
// Unmarshal the bencode value in the 'data' to a value pointed by the 'v'
// pointer, return a non-nil error if any.
func Unmarshal(data []byte, v interface{}) (err error) {
func Unmarshal(data []byte, v interface{}) error {
e := decoder{Reader: bufio.NewReader(bytes.NewBuffer(data))}
err = e.decode(v)
if err != nil {
return
}
_, err = e.Reader.ReadByte()
if err == io.EOF {
return nil
}
if err == nil {
err = &SyntaxError{
Offset: e.offset,
What: errors.New("trailing bytes"),
}
}
return
return e.decode(v)
}
//----------------------------------------------------------------------------