Fix dagstore pieceReader burn logic
This commit is contained in:
parent
8d955d5f30
commit
a9ee263682
@ -119,11 +119,18 @@ func (p *pieceReader) ReadAt(b []byte, off int64) (n int, err error) {
|
||||
|
||||
// check if we need to burn some bytes
|
||||
if off > p.rAt {
|
||||
if _, err := io.CopyN(io.Discard, p.r, p.rAt-off); err != nil {
|
||||
n, err := io.CopyN(io.Discard, p.r, off-p.rAt)
|
||||
p.rAt += n
|
||||
if err != nil {
|
||||
return 0, xerrors.Errorf("discarding read gap: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
// sanity check
|
||||
if off != p.rAt {
|
||||
return 0, xerrors.Errorf("bad reader offset; requested %d; at %d", off, p.rAt)
|
||||
}
|
||||
|
||||
// Read!
|
||||
n, err = p.r.Read(b)
|
||||
p.rAt += int64(n)
|
||||
|
Loading…
Reference in New Issue
Block a user