Skip to content

Commit

Permalink
Fix virtualfile.read
Browse files Browse the repository at this point in the history
Return io.EOF on reads after EOF, don't reset to begining of file.
  • Loading branch information
nkovacs committed Jul 20, 2017
1 parent cbe01ef commit 341d7a8
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions virtual.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,19 +80,21 @@ func (vf *virtualFile) read(bts []byte) (int, error) {
Err: errors.New("bad file descriptor"),
}
}
if vf.offset >= int64(len(vf.Content)) {
return 0, io.EOF
}

end := vf.offset + int64(len(bts))

var err error
if end >= int64(len(vf.Content)) {
// end of file, so return what we have + EOF
n := copy(bts, vf.Content[vf.offset:])
vf.offset = 0
return n, io.EOF
end = int64(len(vf.Content))
err = io.EOF
}

n := copy(bts, vf.Content[vf.offset:end])
vf.offset += int64(n)
return n, nil
return n, err

}

Expand Down

0 comments on commit 341d7a8

Please sign in to comment.