Use bytes.Reader instead of bytes.Buffer in a few places

This commit is contained in:
Matt Joiner 2021-05-05 15:48:57 +10:00
parent c3768da38c
commit 9ded7e7e87
2 changed files with 2 additions and 2 deletions

View File

@ -130,7 +130,7 @@ func MustMarshal(v interface{}) []byte {
// 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) {
buf := bytes.NewBuffer(data)
buf := bytes.NewReader(data)
e := Decoder{r: buf}
err = e.Decode(v)
if err == nil && buf.Len() != 0 {

View File

@ -48,7 +48,7 @@ func TestMarshalPexMessage(t *testing.T) {
msg = Message{}
dec := Decoder{
R: bufio.NewReader(bytes.NewBuffer(b)),
R: bufio.NewReader(bytes.NewReader(b)),
MaxLength: 128,
}
pmOut := PexMsg{}