File: writers.go

package info (click to toggle)
golang-github-tdewolff-test 1.0.10%2Bgit20240106.7de5f7d-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 84 kB
  • sloc: makefile: 2
file content (20 lines) | stat: -rw-r--r-- 436 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
package test

// ErrorWriter implements an io.Writer that will do N successive writes before it returns ErrPlain.
type ErrorWriter struct {
	n int
}

// NewErrorWriter returns a new ErrorWriter.
func NewErrorWriter(n int) *ErrorWriter {
	return &ErrorWriter{n}
}

// Write implements the io.Writer interface.
func (w *ErrorWriter) Write(b []byte) (n int, err error) {
	if w.n == 0 {
		return 0, ErrPlain
	}
	w.n--
	return len(b), nil
}