utils

package
v1.0.106 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package utils contains command functionality which is reused across multiple other packages.

Index

Constants

View Source
const MaxAttempts = 3

Variables

This section is empty.

Functions

func Retry

func Retry(f func() error) error

Retries the given function up to 3 times when it returns an RetryableError.

Types

type FileStream

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

The FileStream implements the stream interface for files on disk.

It provides the stream length by reading the file stats. The file name is used for the stream name.

func NewFileStream

func NewFileStream(path string) *FileStream

func (FileStream) Data

func (s FileStream) Data() (io.ReadCloser, error)

func (FileStream) Name

func (s FileStream) Name() string

func (FileStream) Size

func (s FileStream) Size() (int64, error)

type MemoryStream

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

The MemoryStream implements the stream interface using a simple byte array.

The byte array length is used as the stream length. The name needs to be provided when initializing a new MemoryStream instance.

func NewMemoryStream

func NewMemoryStream(name string, data []byte) *MemoryStream

func (MemoryStream) Data

func (s MemoryStream) Data() (io.ReadCloser, error)

func (MemoryStream) Name

func (s MemoryStream) Name() string

func (MemoryStream) Size

func (s MemoryStream) Size() (int64, error)

type Progress

type Progress struct {
	BytesRead      int64
	BytesPerSecond int64
	Completed      bool
}

The Progress structure contains statistics about how many bytes have been read from the underlying reader.

func NewProgress

func NewProgress(bytesRead int64, bytesPerSecond int64, completed bool) *Progress

type ProgressBar

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

The ProgressBar helps rendering a text-based progress indicator on the command-line. It uses the standard error output interface of the logger for writing progress.

func NewProgressBar

func NewProgressBar(logger log.Logger) *ProgressBar

func (*ProgressBar) Remove

func (b *ProgressBar) Remove()

func (*ProgressBar) Update

func (b *ProgressBar) Update(text string, current int64, total int64, bytesPerSecond int64)

type ProgressReader

type ProgressReader struct {
	io.Reader
	// contains filtered or unexported fields
}

The ProgressReader is a wrapper over the io.Reader interface which computes statistics while the data is read. This is used to show progress for file uploads and downloads.

The ProgressReader emits a Progress event whenever data is read from the reader. The event is debounced to avoid too many events.

func NewProgressReader

func NewProgressReader(reader io.Reader, progressFunc func(progress Progress)) *ProgressReader

func (*ProgressReader) Read

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

type ReaderStream

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

The ReaderStream implements the stream interface by wrapping the generic io.ReadCloser interface.

It does not provide any stream length information due to performance reasons. The reader does not have a name, so it needs to be provided when initializing a new ReaderStream instance.

func NewReaderStream

func NewReaderStream(name string, reader io.ReadCloser) *ReaderStream

func (ReaderStream) Data

func (s ReaderStream) Data() (io.ReadCloser, error)

func (ReaderStream) Name

func (s ReaderStream) Name() string

func (ReaderStream) Size

func (s ReaderStream) Size() (int64, error)

type RetryableError

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

RetryableError can be returned inside of the Retry() block to indicate that the function failed and should be retried.

func Retryable

func Retryable(err error) *RetryableError

func (RetryableError) Error

func (e RetryableError) Error() string

type Stream

type Stream interface {
	Name() string
	Size() (int64, error)
	Data() (io.ReadCloser, error)
}

A Stream provides access to data and abstracts where the data resides.

It enables streaming large files when sending the HTTP request instead of loading them in memory first.

Jump to

Keyboard shortcuts

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