A drop-in replacement to io.Reader
and io.Writer
from the standard library with the total number of bytes transfered.
go get github.com/samber/go-metered-io
This library is v1 and follows SemVer strictly. No breaking changes will be made to exported APIs before v2.0.0.
GoDoc: https://pkg.go.dev/github.com/samber/go-metered-io
Byte:
- metered.NewReader
- metered.NewWriter
- metered.NewReadCloser
- metered.NewWriteCloser
- metered.NewReadWriter
String:
- metered.NewStringWriter
Rune:
- metered.NewRuneReader
import "github.com/samber/go-metered-io"
r := metered.NewReader(strings.NewReader("Lorem ipsum dolor sit amet..."))
for {
buff := make([]byte, 10)
_, err := r.Read(buff)
if err != nil {
break
}
}
fmt.Printf("Total bytes: %d", r.Rx())
import "github.com/samber/go-metered-io"
var buf bytes.Buffer
w := metered.NewWriter(&buf)
for i := 0 ; i < 10 ; i++ {
_, err := w.Write("Hello world\n")
if err != nil {
break
}
}
fmt.Printf("Total bytes: %d", w.Tx())
- Ping me on twitter @samuelberthe (DMs, mentions, whatever :))
- Fork the project
- Fix open issues or request new features
Don't hesitate ;)
# Install some dev dependencies
make tools
# Run tests
make test
# or
make watch-test
Give a βοΈ if this project helped you!
Copyright Β© 2023 Samuel Berthe.
This project is MIT licensed.