From a4a178329a0fd1f62924109a8e822737b0802122 Mon Sep 17 00:00:00 2001 From: Kevin Chabowski Date: Mon, 12 Aug 2013 00:53:27 +0200 Subject: CountWriter added. --- CountWriter.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 CountWriter.go diff --git a/CountWriter.go b/CountWriter.go new file mode 100644 index 0000000..d942a8e --- /dev/null +++ b/CountWriter.go @@ -0,0 +1,21 @@ +package kagus + +import ( + "io" +) + +// CountWriter wraps around an io.Writer and counts the amount of bytes written. +type CountWriter struct { + W io.Writer + N int64 // Total number of bytes written +} + +func NewCountWriter(w io.Writer) *CountWriter { + return &CountWriter{W: w} +} + +func (cw *CountWriter) Write(p []byte) (int, error) { + n, err := cw.W.Write(p) + cw.N += int64(n) + return n, err +} -- cgit v1.2.3-54-g00ecf