progress

package module
v0.0.0-...-e9d0304 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2015 License: MIT Imports: 1 Imported by: 0

README

progress

Circle CI

GoDoc

Progress provides methods for monitoring the progress of io operations.

License

progress is MIT licensed, details can be found here.

Documentation

Overview

Package progress provides methods for monitoring the progress of io.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Copy

func Copy(dst io.Writer, src io.Reader, n int64) (chan *Status, chan error)

Copy tracks progress of copied data from src to dst, progress events are sent to the return status channel, once completed the IsFinished routine will report true.

Example
package main

import (
	"bytes"
	"os"

	"github.com/Bowery/progress"
)

func main() {
	file, err := os.Open("/path/to/file")
	if err != nil {
		panic(err)
	}
	defer file.Close()

	stat, err := file.Stat()
	if err != nil {
		panic(err)
	}

	var buf bytes.Buffer
	progChan, errChan := progress.Copy(&buf, file, stat.Size())

	isCopied := false
	for !isCopied {
		select {
		case status := <-progChan:
			if status.IsFinished() {
				isCopied = true
				break
			}
		case err := <-errChan:
			panic(err)
		}
	}
}
Output:

Types

type Status

type Status struct {
	Current int64
	Total   int64
	// contains filtered or unexported fields
}

Status represents the copy progress. It contains the current progress and total size in bytes.

func (*Status) Completion

func (s *Status) Completion() float64

Completion returns the current completion in the range [0, 1].

func (*Status) IsFinished

func (s *Status) IsFinished() bool

IsFinished returns a boolean indicating whether the copy has completed.

Jump to

Keyboard shortcuts

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