aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Chabowski <kevin@kch42.de>2013-08-12 00:53:27 +0200
committerKevin Chabowski <kevin@kch42.de>2013-08-12 00:53:27 +0200
commita4a178329a0fd1f62924109a8e822737b0802122 (patch)
tree49c1604d7437bd3da5253d3e370862f5070020ea
parent944c2c74c0756e6b768757475546da459d06e95e (diff)
downloadkagus-a4a178329a0fd1f62924109a8e822737b0802122.tar.gz
kagus-a4a178329a0fd1f62924109a8e822737b0802122.tar.bz2
kagus-a4a178329a0fd1f62924109a8e822737b0802122.zip
CountWriter added.
-rw-r--r--CountWriter.go21
1 files changed, 21 insertions, 0 deletions
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
+}