File: errreader.go

package info (click to toggle)
golang-github-jonas-p-go-shp 0.1.1-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid, trixie
  • size: 324 kB
  • sloc: makefile: 3
file content (24 lines) | stat: -rw-r--r-- 526 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package shp

import (
	"fmt"
	"io"
)

// errReader is a helper to perform multiple successive read from another reader
// and do the error checking only once afterwards. It will not perform any new
// reads in case there was an error encountered earlier.
type errReader struct {
	io.Reader
	e error
	n int64
}

func (er *errReader) Read(p []byte) (n int, err error) {
	if er.e != nil {
		return 0, fmt.Errorf("unable to read after previous error: %v", er.e)
	}
	n, er.e = er.Reader.Read(p)
	er.n += int64(n)
	return n, er.e
}