progress

package module
v0.0.0-...-24666f8 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2014 License: MIT Imports: 0 Imported by: 2

README

progress

Making a progress for Reader or Writer write/read bytes.

View the docs.

Usage

import "github.com/go-libs/progress"
Writing bytes in progress
import "github.com/go-libs/progress"

filename := "progress_test.go"
f, err := os.Open(filename)
defer f.Close()
if err != nil {
  log.Fatalln(err)
}
fs, err := os.Stat(filename)
if err != nil {
  log.Fatalln(err)
}

p := Progress.New()
p.Total = fs.Size()
p.Progress = func(current, total, expected int64) {
  log.Println("Writing", current, total, expected)
}

b := new(bytes.Buffer)
w := io.MultiWriter(p, b)
_, err = io.Copy(w, f)
if err != nil {
  log.Fatalln(err)
}
Reading bytes in progress
import "github.com/go-libs/syncreader"
import "github.com/go-libs/progress"

filename := "progress_test.go"
f, err := os.Open(filename)
defer f.Close()
if err != nil {
  log.Fatalln(err)
}
fs, err := os.Stat(filename)
if err != nil {
  log.Fatalln(err)
}

p := Progress.New()
p.Total = fs.Size()
p.Progress = func(current, total, expected int64) {
  log.Println("Reading", current, total, expected)
}

b := new(bytes.Buffer)
r := syncreader.New(f, p)
_, err = b.ReadFrom(r)
if err != nil {
  log.Fatalln(err)
}
Using IgnoreTotal flag to ignore total size in Progress initialization.
p := Progress.New()
p.IgnoreTotal = true
p.Progress = func(current, total, expected int64) {
  log.Println("Reading", current, total, expected)
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultHandle = HandlerFunc(func(c, t, e int64) {})

Functions

This section is empty.

Types

type HandlerFunc

type HandlerFunc func(current, total, expected int64)

type Progress

type Progress struct {
	Current     int64
	Total       int64
	Expected    int64
	Finished    bool
	IgnoreTotal bool
	Progress    HandlerFunc
}

func New

func New() *Progress

func (*Progress) Read

func (p *Progress) Read(b []byte) (n int, err error)

func (*Progress) Write

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

Jump to

Keyboard shortcuts

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