slreader

package
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2023 License: GPL-3.0 Imports: 7 Imported by: 1

README

S.L.Reader

Speed-Limited Reader

A reader based on io.Reader and using speed limits.

Main features of this reader are following.

  • Reader uses a common io.Reader interface.
  • Changes of speed limits on the fly are supported.
  • Speed limit changes are in their turn limited by the special ratio set in the constructor.
  • Zero speed limit is forbidden as it is nonsense.
  • Reader implements io.Closer interface.

Documentation

Index

Constants

View Source
const (
	ErrBurstToNormalRatioOverflow = "overflow in burst-to-normal ratio: %v vs %v"
	ErrZeroSpeed                  = "zero speed is not allowed"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type SLReader

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

SLReader is a speed-limited reader.

func NewReader

func NewReader(r io.Reader, normalLimit float64, burstLimit int, bnr float64) (slr *SLReader, err error)

NewReader creates a new SLReader. 'normalLimit' and 'burstLimit' are speed limits set in bytes per second. 'bnr' is the maximum burst-to-normal ratio allowed, i.e. max(burst/normal).

func (*SLReader) ChangeLimits

func (slr *SLReader) ChangeLimits(normalLimit float64, burstLimit int) (err error)

ChangeLimits changes the speed limit settings.

func (*SLReader) Close added in v0.10.2

func (slr *SLReader) Close() (err error)

Close closes the reader. It is a standard method for the 'io.Closer' interface.

func (*SLReader) Read

func (slr *SLReader) Read(dst []byte) (n int, err error)

Read tries to read bytes into the destination (dst). For more information see the io.Reader interface.

Jump to

Keyboard shortcuts

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