progress

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2021 License: MIT Imports: 4 Imported by: 1

Documentation

Overview

Package progress provides an io.Writer that prints number of written bytes to stdout in a pretty way.

Use io.MultiWriter to chain it together with you destination writer like this:

f, err := os.Open(...)
...
fi, err := f.Stat()
...
n, err := io.Copy(io.MultiWriter(dst, progress.New(fi.Size())), src)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Writer

type Writer struct {
	Total  int64     // total number of bytes to be written, if known
	Output io.Writer // progress is written here, os.Stout by default
	// contains filtered or unexported fields
}

Writer on each Write call prints a progress info to os.Stdout. Progress format is "sum/total" ending with carriage return, so if os.Stdout is attached to a terminal output would update the same line over and over.

func New

func New(total int64) *Writer

New initializes new Writer printing progress to os.Stdout. If total is 0 or negative, only number of written bytes is printed.

func (*Writer) Write

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

Write always returns len(p), nil,

Jump to

Keyboard shortcuts

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