Categorygithub.com/samber/go-metered-io
modulepackage
1.0.0
Repository: https://github.com/samber/go-metered-io.git
Documentation: pkg.go.dev

# README

Metered io.Reader and io.Writer

tag Go Version GoDoc Build Status Go report Coverage Contributors License

A drop-in replacement to io.Reader and io.Writer from the standard library with the total number of bytes transfered.

🚀 Install

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

Byte:

  • metered.NewReader
  • metered.NewWriter
  • metered.NewReadCloser
  • metered.NewWriteCloser
  • metered.NewReadWriter

String:

  • metered.NewStringWriter

Rune:

  • metered.NewRuneReader

Examples

Metered reader

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

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

Don't hesitate ;)

# Install some dev dependencies
make tools

# Run tests
make test
# or
make watch-test

👤 Contributors

Contributors

💫 Show your support

Give a ⭐️ if this project helped you!

GitHub Sponsors

📝 License

Copyright © 2023 Samuel Berthe.

This project is MIT licensed.

# Functions

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Structs

Implements io.ReadCloser.
Implements io.Reader.
Implements io.ReadWriteCloser.
Implements io.ReadWriter.
Implements io.RuneWriter.
Implements io.StringWriter.
Implements io.WriterCloser.
Implements io.Writer.