Fix use of cap in MultiReadSeeker
Signed-off-by: Tom Wilkie <tom.wilkie@gmail.com>
This commit is contained in:
parent
8a6c5358af
commit
158bb9bbd5
|
@ -155,7 +155,7 @@ func (r *multiReadSeeker) Read(b []byte) (int, error) {
|
|||
r.pos = &pos{0, 0}
|
||||
}
|
||||
|
||||
bCap := int64(cap(b))
|
||||
bCap := int64(len(b))
|
||||
buf := bytes.NewBuffer(nil)
|
||||
var rdr io.ReadSeeker
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ package ioutils
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
|
@ -188,3 +189,23 @@ func TestMultiReadSeekerCurAfterSet(t *testing.T) {
|
|||
t.Fatalf("reader size does not match, got %d, expected %d", size, mid+18)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMultiReadSeekerSmallReads(t *testing.T) {
|
||||
readers := []io.ReadSeeker{}
|
||||
for i := 0; i < 10; i++ {
|
||||
integer := make([]byte, 4, 4)
|
||||
binary.BigEndian.PutUint32(integer, uint32(i))
|
||||
readers = append(readers, bytes.NewReader(integer))
|
||||
}
|
||||
|
||||
reader := MultiReadSeeker(readers...)
|
||||
for i := 0; i < 10; i++ {
|
||||
var integer uint32
|
||||
if err := binary.Read(reader, binary.BigEndian, &integer); err != nil {
|
||||
t.Fatalf("Read from NewMultiReadSeeker failed: %v", err)
|
||||
}
|
||||
if uint32(i) != integer {
|
||||
t.Fatalf("Read wrong value from NewMultiReadSeeker: %d != %d", i, integer)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue