Welcome to mirror list, hosted at ThFree Co, Russian Federation.

count.go « helper « internal - gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 77f1c94c9c7ce34c518fbd8919a86d10d94aa185 (plain)
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
package helper

import (
	"bytes"
	"io"
)

// CountingWriter wraps an io.Writer and counts all the writes. Accessing
// the count N is not thread-safe.
type CountingWriter struct {
	W io.Writer
	N int64
	b bytes.Buffer
}

func (cw *CountingWriter) Write(p []byte) (int, error) {
	n, err := cw.W.Write(p)
	cw.N += int64(n)
	cw.b.Write(p)
	return n, err
}

func (cw *CountingWriter) String() string {
	return cw.b.String()
}