Count the number of bytes passing through an io.Writer
Module gophers.dev/pkgs/counting
provides a package with a utility function
for counting the number of bytes that pass through an io.Writer
.
The counting
package can be installed by running
go get gophers.dev/pkgs/counting
f, _ := ioutil.TempFile("", "counting-")
counter := counting.NewCountingWriter(f)
compressor, _ := gzip.NewWriterLevel(counter, 9)
s := []byte("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa") // 42 bytes
u, _ := compressor.Write(s)
compressor.Close()
c := counter.Written()
fmt.Println("uncompressed bytes written", u)
fmt.Println("compressed bytes written", c)
The gophers.dev/pkgs/counting
module is always improving with new features
and error corrections. For contributing bug fixes and new features please file an issue.
The gophers.dev/pkgs/counting
module is open source under the BSD-3-Clause license.