metered

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 11, 2023 License: MIT Imports: 2 Imported by: 1

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.

Documentation ΒΆ

Index ΒΆ

Constants ΒΆ

This section is empty.

Variables ΒΆ

This section is empty.

Functions ΒΆ

This section is empty.

Types ΒΆ

type ReadCloser ΒΆ

type ReadCloser struct {
	*Reader
	io.Closer
}

Implements io.ReadCloser

func NewReadCloser ΒΆ

func NewReadCloser(r io.ReadCloser) *ReadCloser

type ReadWriteCloser ΒΆ

type ReadWriteCloser struct {
	*ReadWriter
	io.Closer
}

Implements io.ReadWriteCloser

func NewReadWriteCloser ΒΆ

func NewReadWriteCloser(rw io.ReadWriteCloser) *ReadWriteCloser

type ReadWriter ΒΆ

type ReadWriter struct {
	// contains filtered or unexported fields
}

Implements io.ReadWriter

func NewReadWriter ΒΆ

func NewReadWriter(rw io.ReadWriter) *ReadWriter

func (*ReadWriter) Read ΒΆ

func (rw *ReadWriter) Read(p []byte) (n int, err error)

func (*ReadWriter) Rx ΒΆ

func (rw *ReadWriter) Rx() uint64

func (*ReadWriter) Tx ΒΆ

func (rw *ReadWriter) Tx() uint64

func (*ReadWriter) Write ΒΆ

func (rw *ReadWriter) Write(p []byte) (n int, err error)

type Reader ΒΆ

type Reader struct {
	// contains filtered or unexported fields
}

Implements io.Reader

func NewReader ΒΆ

func NewReader(reader io.Reader) *Reader

func (*Reader) Read ΒΆ

func (r *Reader) Read(p []byte) (n int, err error)

func (*Reader) Rx ΒΆ

func (r *Reader) Rx() uint64

type RuneReader ΒΆ

type RuneReader struct {
	// contains filtered or unexported fields
}

Implements io.RuneWriter

func NewRuneReader ΒΆ

func NewRuneReader(rw io.RuneReader) *RuneReader

func (*RuneReader) ReadRune ΒΆ

func (rw *RuneReader) ReadRune() (r rune, n int, err error)

func (*RuneReader) Tx ΒΆ

func (rw *RuneReader) Tx() uint64

type StringWriter ΒΆ

type StringWriter struct {
	// contains filtered or unexported fields
}

Implements io.StringWriter

func NewStringWriter ΒΆ

func NewStringWriter(sw io.StringWriter) *StringWriter

func (*StringWriter) Tx ΒΆ

func (sw *StringWriter) Tx() uint64

func (*StringWriter) WriteString ΒΆ

func (sw *StringWriter) WriteString(p string) (n int, err error)

type WriteCloser ΒΆ

type WriteCloser struct {
	*Writer
	io.Closer
}

Implements io.WriterCloser

func NewWriteCloser ΒΆ

func NewWriteCloser(w io.WriteCloser) *WriteCloser

type Writer ΒΆ

type Writer struct {
	// contains filtered or unexported fields
}

Implements io.Writer

func NewWriter ΒΆ

func NewWriter(writer io.Writer) *Writer

func (*Writer) Tx ΒΆ

func (w *Writer) Tx() uint64

func (*Writer) Write ΒΆ

func (w *Writer) Write(p []byte) (n int, err error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL