1
package moxio
2
3
import (
4
"io"
5
)
6
7
// LimitAtReader is a reader at that returns ErrLimit if reads would extend
8
// beyond Limit.
9
type LimitAtReader struct {
10
R io.ReaderAt
11
Limit int64
12
}
13
14
// ReadAt passes the read on to R, but returns an error if the read data would extend beyond Limit.
15
func (r *LimitAtReader) ReadAt(buf []byte, offset int64) (int, error) {
16
if offset+int64(len(buf)) > r.Limit {
17
return 0, ErrLimit
18
}
19
return r.R.ReadAt(buf, offset)
20
}
21