passthru

package
v12.130.0 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2024 License: Apache-2.0 Imports: 6 Imported by: 2

Documentation

Overview

Package passthru provides Reader and Writer with information about the amount of data being passed.

Example
Output:

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	ErrNilReader = errors.New("Reader is nil")
	ErrNilWriter = errors.New("Writer is nil")
)

Functions

This section is empty.

Types

type Calculator

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

Calculator calculates pass-thru speed and remaining time

func NewCalculator

func NewCalculator(total int64, winSizeSec float64) *Calculator

NewCalculator creates new Calculator struct

func (*Calculator) Calculate

func (c *Calculator) Calculate(current int64) (float64, time.Duration)

Calculate calculates speed and remaining time

func (*Calculator) SetTotal

func (c *Calculator) SetTotal(total int64)

SetTotal sets total number of objects

type Reader

type Reader struct {
	Calculator *Calculator
	Update     func(n int)
	// contains filtered or unexported fields
}

Reader is pass-thru Reader

func NewReader

func NewReader(reader io.ReadCloser, total int64) *Reader

NewReader creates new passthru reader

func (*Reader) Close

func (r *Reader) Close() error

Close closes the reader

func (*Reader) Current

func (r *Reader) Current() int64

Current returns read amount of data

func (*Reader) IsClosed

func (r *Reader) IsClosed() bool

IsClosed returns true if reader is closed

func (*Reader) Progress

func (r *Reader) Progress() float64

Progress returns percentage of data read

func (*Reader) Read

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

Read implements the standard Read interface

func (*Reader) SetTotal

func (r *Reader) SetTotal(total int64)

SetTotal sets total amount of data

func (*Reader) Speed

func (r *Reader) Speed() (float64, time.Duration)

Speed calculates passthru speed and time remaining to process all data. If Calculator was not set on the first call, a default calculator with a 10 second window is created.

func (*Reader) Total

func (r *Reader) Total() int64

Total returns total amount of data

type Writer

type Writer struct {
	Calculator *Calculator
	Update     func(n int)
	// contains filtered or unexported fields
}

Writer is pass-thru Writer

func NewWriter

func NewWriter(writer io.WriteCloser, total int64) *Writer

NewWriter creates new passthru writer

func (*Writer) Close

func (w *Writer) Close() error

Close closes the writer

func (*Writer) Current

func (w *Writer) Current() int64

Current returns written amount of data

func (*Writer) IsClosed

func (w *Writer) IsClosed() bool

IsClosed returns true if writer is closed

func (*Writer) Progress

func (w *Writer) Progress() float64

Progress returns percentage of data written

func (*Writer) SetTotal

func (w *Writer) SetTotal(total int64)

SetTotal sets total amount of data

func (*Writer) Speed

func (w *Writer) Speed() (float64, time.Duration)

Speed calculates passthru speed and time remaining to process all data. If Calculator was not set on the first call, a default calculator with a 10 second window is created.

func (*Writer) Total

func (w *Writer) Total() int64

Total returns total amount of data

func (*Writer) Write

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

Write implements the standard Write interface

Jump to

Keyboard shortcuts

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