counter

package
v0.0.0-...-e15721f Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2020 License: MIT Imports: 1 Imported by: 10

Documentation

Overview

Package counter implements counting readers and writers

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CountCallback

type CountCallback func(count int64)

A CountCallback is called whenever some data is written or read and the byte count changes

type Counter

type Counter interface{}

A Counter counts how much data flows through it, in bytes

type Reader

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

A Reader keeps track of how many bytes have been read from a reader

func NewReader

func NewReader(reader io.Reader) *Reader

NewReader returns a new counting reader. If the specified reader is nil, it will still count all bytes written, then discard them

func NewReaderCallback

func NewReaderCallback(onRead CountCallback, reader io.Reader) *Reader

NewReaderCallback returns a new counting reader with a callback to be called on every read.

func (*Reader) Close

func (r *Reader) Close() error

Close closes the counting reader, but DOES NOT close the underlying reader

func (*Reader) Count

func (r *Reader) Count() int64

Count returns the number of bytes read through that counting reader

func (*Reader) Read

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

Read is our io.Reader implementation

type Writer

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

A Writer keeps track of how many bytes have been written to a writer

func NewWriter

func NewWriter(writer io.Writer) *Writer

NewWriter returns a new counting writer. If the specified writer is nil, it will still count all bytes written, then discard them

func NewWriterCallback

func NewWriterCallback(onWrite CountCallback, writer io.Writer) *Writer

NewWriterCallback returns a new counting writer with a callback to be called on every write.

func (*Writer) Close

func (w *Writer) Close() error

Close closes the counting writer, but DOES NOT close the underlying writer

func (*Writer) Count

func (w *Writer) Count() int64

Count returns the number of bytes written through this counting writer

func (*Writer) SetCount

func (w *Writer) SetCount(count int64)

func (*Writer) Write

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

Write is our io.Writer implementation

Jump to

Keyboard shortcuts

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