streamy

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2022 License: MIT Imports: 8 Imported by: 0

README

Streamy

Godoc Release Build

A Golang library that provides functions for streams.

Usage

See streamy_test.go, reader_test.go, progress_test.go and have_test.go.

Test

# Run tests
make test

# Continuous testing
make test-ui

# Benchmarks
make test-benchmarks

Contributing

See CONTRIBUTING.md

License

Licensed under The MIT License (MIT)
For the full copyright and license information, please view the LICENSE.txt file.

Documentation

Overview

Package streamy provides functions for streams.

Index

Constants

This section is empty.

Variables

View Source
var ErrProgressStopped = errors.New("stopped")

ErrProgressStopped means that a progress stopped (i.e. by calling Stop method).

View Source
var (
	// ProgressStatsModeSimple represents the simple progress stats mode.
	ProgressStatsModeSimple = ProgressStatsMode{/* contains filtered or unexported fields */}
)

Functions

func HaveSeeker

func HaveSeeker(i interface{}) bool

HaveSeeker checks whether the given interface implements io.Seeker or not.

func HaveStdin

func HaveStdin() (bool, error)

HaveStdin checks whether there is data in the stdin or not.

func Index

func Index(r io.Reader, search []byte, readSize int) (index int64, read int64, err error)

Index returns the index of the first instance of the given byte slice, number of bytes read and error if any.

func ReaderOnly

func ReaderOnly(r io.Reader) io.Reader

ReaderOnly takes any interface that implements io.Reader and returns just an io.Reader. It's useful for converting "advanced" readers (i.e. io.Seeker) to streams.

func TeeReaderN

func TeeReaderN(r io.Reader, w io.Writer, n int64) io.Reader

TeeReaderN returns an io.Reader that writes to the given writer what it reads from the given reader. It's similar to io.TeeReader but takes an additional argument that controls the number of bytes to write.

Types

type BinaryUnit

type BinaryUnit int64

BinaryUnit represents the binary unit type.

const (
	// Byte represent the byte unit type.
	Byte BinaryUnit = 1

	// KB represent the KB unit type.
	KB BinaryUnit = 1000
	// MB represent the MB unit type.
	MB BinaryUnit = 1000 * KB
	// GB represent the GB unit type.
	GB BinaryUnit = 1000 * MB
	// TB represent the TB unit type.
	TB BinaryUnit = 1000 * GB
	// PB represent the PB unit type.
	PB BinaryUnit = 1000 * TB

	// KiB represent the KiB unit type.
	KiB BinaryUnit = 1024
	// MiB represent the MiB unit type.
	MiB BinaryUnit = 1024 * KiB
	// GiB represent the GiB unit type.
	GiB BinaryUnit = 1024 * MiB
	// TiB represent the TiB unit type.
	TiB BinaryUnit = 1024 * GiB
	// PiB represent the PiB unit type.
	PiB BinaryUnit = 1024 * TiB
)

type Progress

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

Progress implements the io.Writer interface for tracking bytes.

func (*Progress) BytesWritten

func (progress *Progress) BytesWritten() int64

BytesWritten returns the number of bytes written.

func (*Progress) DisableStats

func (progress *Progress) DisableStats()

DisableStats disables the progress stats.

func (*Progress) EnableControls added in v0.2.0

func (progress *Progress) EnableControls() error

EnableControls enables the progress controls such as pause and stop.

func (*Progress) EnableStats

func (progress *Progress) EnableStats(mode ProgressStatsMode) error

EnableStats enables the progress stats.

func (*Progress) SetTotalSize

func (progress *Progress) SetTotalSize(size int64, unit BinaryUnit)

SetTotalSize sets the total size by the given size and binary unit.

func (*Progress) Stats

func (progress *Progress) Stats() ProgressStats

Stats returns the progress stats.

func (*Progress) Stop added in v0.2.0

func (progress *Progress) Stop()

Stop stops the the progress writer.

func (*Progress) TotalBytes

func (progress *Progress) TotalBytes() int64

TotalBytes returns the total number of bytes.

func (*Progress) Write

func (progress *Progress) Write(p []byte) (n int, err error)

Write implements the io.Writer interface.

type ProgressStats

type ProgressStats struct {
	TotalBytes     int64
	BytesWritten   int64
	BytesPerSecond int64
	Took           time.Duration
	Remaining      time.Duration
	Percentage     int
}

ProgressStats represents the progress stats.

type ProgressStatsMode

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

ProgressStatsMode represents a progress stats mode.

Jump to

Keyboard shortcuts

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