File: io.go

package info (click to toggle)
golang-github-git-lfs-gitobj 2.1.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 432 kB
  • sloc: makefile: 2; sh: 1
file content (27 lines) | stat: -rw-r--r-- 811 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package pack

import "io"

// OffsetReaderAt transforms an io.ReaderAt into an io.Reader by beginning and
// advancing all reads at the given offset.
type OffsetReaderAt struct {
	// r is the data source for this instance of *OffsetReaderAt.
	r io.ReaderAt

	// o if the number of bytes read from the underlying data source, "r".
	// It is incremented upon reads.
	o int64
}

// Read implements io.Reader.Read by reading into the given []byte, "p" from the
// last known offset provided to the OffsetReaderAt.
//
// It returns any error encountered from the underlying data stream, and
// advances the reader forward by "n", the number of bytes read from the
// underlying data stream.
func (r *OffsetReaderAt) Read(p []byte) (n int, err error) {
	n, err = r.r.ReadAt(p, r.o)
	r.o += int64(n)

	return n, err
}