Debian Codegraph @

pack/io.go

raw
1 package pack
2
3 import "io"
4
5 // OffsetReaderAt transforms an io.ReaderAt into an io.Reader by beginning and
6 // advancing all reads at the given offset.
7 type OffsetReaderAt struct {
8 // r is the data source for this instance of *OffsetReaderAt.
9 r io.ReaderAt
10
11 // o if the number of bytes read from the underlying data source, "r".
12 // It is incremented upon reads.
13 o int64
14 }
15
16 // Read implements io.Reader.Read by reading into the given []byte, "p" from the
17 // last known offset provided to the OffsetReaderAt.
18 //
19 // It returns any error encountered from the underlying data stream, and
20 // advances the reader forward by "n", the number of bytes read from the
21 // underlying data stream.
22 func (r *OffsetReaderAt) Read(p []byte) (n int, err error) {
23 n, err = r.r.ReadAt(p, r.o)
24 r.o += int64(n)
25
26 return n, err
27 }