Documentation
¶
Overview ¶
Package progress provides io.Reader and io.Writer with progress and remaining time estimation.
ctx := context.Background() // get a reader and the total expected number of bytes s := `Now that's what I call progress` size := len(s) r := progress.NewReader(strings.NewReader(s)) // Start a goroutine printing progress go func() { ctx := context.Background() progressChan := progress.NewTicker(ctx, r, size, 1*time.Second) for p := range progressChan { fmt.Printf("\r%v remaining...", p.Remaining().Round(time.Second)) } fmt.Println("\rdownload is completed") }() // use the Reader as normal if _, err := io.Copy(dest, r); err != nil { log.Fatalln(err) }
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewTicker ¶
NewTicker gets a channel on which ticks of Progress are sent at duration d intervals until the operation is complete at which point the channel is closed. The counter is either a Reader or Writer (or any type that can report its progress). The size is the total number of expected bytes being read or written. If the context cancels the operation, the channel is closed.
Types ¶
type Counter ¶
type Counter interface { // N gets the current count value. // For readers and writers, this is the number of bytes // read or written. // For other contexts, the number may be anything. N() int64 // Err gets the last error from the Reader or Writer. // When the process is finished, this will be io.EOF. Err() error }
Counter counts bytes. Both Reader and Writer are Counter types.
type Progress ¶
type Progress struct {
// contains filtered or unexported fields
}
Progress represents a moment of progress.
func (Progress) Complete ¶
Complete gets whether the operation is complete or not. Always returns false if the Size is unknown (-1).
func (Progress) Estimated ¶
Estimated gets the time at which the operation is expected to finish. Use Remaining to get a Duration. Estimated().IsZero() is true if no estimate is available.
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
Reader counts the bytes read through it.
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
Writer counts the bytes written through it.