Revert "bencode: Trailing bytes on Unmarshal is an error"
This reverts commit ad73a0ea89
.
This commit is contained in:
parent
0403d4185d
commit
577ea21793
|
@ -3,7 +3,6 @@ package bencode
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"bytes"
|
"bytes"
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"reflect"
|
"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'
|
// Unmarshal the bencode value in the 'data' to a value pointed by the 'v'
|
||||||
// pointer, return a non-nil error if any.
|
// 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))}
|
e := decoder{Reader: bufio.NewReader(bytes.NewBuffer(data))}
|
||||||
err = e.decode(v)
|
return 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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
|
|
Loading…
Reference in New Issue