Reset the position of all readers before reading the data
Signed-off-by: Yanqiang Miao <miao.yanqiang@zte.com.cn>
This commit is contained in:
parent
54805701bd
commit
fd06bd6f96
2 changed files with 16 additions and 1 deletions
|
@ -152,7 +152,8 @@ func (r *multiReadSeeker) getOffsetToReader(rdr io.ReadSeeker) (int64, error) {
|
|||
|
||||
func (r *multiReadSeeker) Read(b []byte) (int, error) {
|
||||
if r.pos == nil {
|
||||
r.pos = &pos{0, 0}
|
||||
// make sure all readers are at 0
|
||||
r.Seek(0, os.SEEK_SET)
|
||||
}
|
||||
|
||||
bLen := int64(len(b))
|
||||
|
|
|
@ -55,6 +55,20 @@ func TestMultiReadSeekerReadAll(t *testing.T) {
|
|||
if string(b) != expected {
|
||||
t.Fatalf("ReadAll failed, got: %q, expected %q", string(b), expected)
|
||||
}
|
||||
|
||||
// The positions of some readers are not 0
|
||||
s1.Seek(0, os.SEEK_SET)
|
||||
s2.Seek(0, os.SEEK_END)
|
||||
s3.Seek(0, os.SEEK_SET)
|
||||
mr = MultiReadSeeker(s1, s2, s3)
|
||||
b, err = ioutil.ReadAll(mr)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if string(b) != expected {
|
||||
t.Fatalf("ReadAll failed, got: %q, expected %q", string(b), expected)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMultiReadSeekerReadEach(t *testing.T) {
|
||||
|
|
Loading…
Reference in a new issue