https://github.com/samber/go-metered-io
📐 A drop-in replacement to io.Reader and io.Writer with the total number of bytes transfered.
https://github.com/samber/go-metered-io
buffer bytes go io measure metric monitoring reader rune stream string writer
Last synced: about 2 months ago
JSON representation
📐 A drop-in replacement to io.Reader and io.Writer with the total number of bytes transfered.
- Host: GitHub
- URL: https://github.com/samber/go-metered-io
- Owner: samber
- License: mit
- Created: 2023-08-11T18:03:35.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-11-09T18:03:33.000Z (7 months ago)
- Last Synced: 2024-11-09T19:17:47.206Z (7 months ago)
- Topics: buffer, bytes, go, io, measure, metric, monitoring, reader, rune, stream, string, writer
- Language: Go
- Homepage: https://pkg.go.dev/github.com/samber/go-metered-io
- Size: 33.2 KB
- Stars: 24
- Watchers: 3
- Forks: 2
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# Metered io.Reader and io.Writer
[](https://github.com/samber/go-metered-io/releases)

[](https://pkg.go.dev/github.com/samber/go-metered-io)

[](https://goreportcard.com/report/github.com/samber/go-metered-io)
[](https://codecov.io/gh/samber/go-metered-io)
[](https://github.com/samber/go-metered-io/graphs/contributors)
[](./LICENSE)A drop-in replacement to `io.Reader` and `io.Writer` from the standard library with the total number of bytes transfered.
## 🚀 Install
```sh
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.
## 💡 Spec
GoDoc: [https://pkg.go.dev/github.com/samber/go-metered-io](https://pkg.go.dev/github.com/samber/go-metered-io)
Byte:
- metered.NewReader
- metered.NewWriter
- metered.NewReadCloser
- metered.NewWriteCloser
- metered.NewReadWriterString:
- metered.NewStringWriterRune:
- metered.NewRuneReader## Examples
### Metered reader
```go
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())
```### Metered writer
```go
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())
```## 🤝 Contributing
- Ping me on twitter [@samuelberthe](https://twitter.com/samuelberthe) (DMs, mentions, whatever :))
- Fork the [project](https://github.com/samber/go-metered-io)
- Fix [open issues](https://github.com/samber/go-metered-io/issues) or request new featuresDon't hesitate ;)
```bash
# Install some dev dependencies
make tools# Run tests
make test
# or
make watch-test
```## 👤 Contributors

## 💫 Show your support
Give a ⭐️ if this project helped you!
[](https://github.com/sponsors/samber)
## 📝 License
Copyright © 2023 [Samuel Berthe](https://github.com/samber).
This project is [MIT](./LICENSE) licensed.