File: inspection-reader.go

package info (click to toggle)
moor 2.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 16,112 kB
  • sloc: sh: 174; ansic: 12; xml: 6; makefile: 5
file content (28 lines) | stat: -rw-r--r-- 436 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
28
package reader

import "io"

// Pass-through reader that counts the number of bytes read.
type inspectionReader struct {
	base       io.Reader
	bytesCount int64

	endedWithNewline bool
}

func (r *inspectionReader) Read(p []byte) (n int, err error) {
	n, err = r.base.Read(p)
	r.bytesCount += int64(n)

	if err != nil {
		return
	}

	if n > 0 {
		r.endedWithNewline = p[n-1] == '\n'
	} else {
		r.endedWithNewline = false
	}

	return
}