Reset the position of all readers before reading the data

Signed-off-by: Yanqiang Miao <miao.yanqiang@zte.com.cn>
Upstream-commit: fd06bd6f96f1be5c14f30314b9c8c323b19219ed
Component: engine
This commit is contained in:
Yanqiang Miao
2017-04-08 13:38:15 +08:00
parent 798aa28677
commit aebc58bf87
2 changed files with 16 additions and 1 deletions
+2 -1
View File
@@ -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) {