Documentation
¶
Overview ¶
Package progress provides Reader and Writer
Index ¶
Examples ¶
Constants ¶
View Source
const DefaultFlushInterval = time.Second / 30
DefaultFlushInterval is a reasonable default flush interval
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Progress ¶
type Progress struct {
Rewritable
}
type Reader ¶
type Reader struct {
io.Reader // Reader to read from
Bytes int64 // total number of bytes read (so far)
Rewritable
}
Reader consistently writes the number of bytes read to Progress.
Example ¶
source := strings.NewReader("hello world")
var progress strings.Builder
reader := &Reader{
Reader: source,
Rewritable: Rewritable{
FlushInterval: 0,
Writer: &progress,
},
}
reader.Read([]byte("hello"))
reader.Read([]byte(" world"))
// replace all the '\r's with '\n's for testing
fmt.Println(strings.ReplaceAll(progress.String(), "\r", "\n"))
Output: Read 5 B Read 11 B
type Rewritable ¶
type Rewritable struct {
Writer io.Writer
FlushInterval time.Duration // minimum time between flushes of the progress
// contains filtered or unexported fields
}
func (*Rewritable) Close ¶
func (rw *Rewritable) Close()
func (*Rewritable) Flush ¶
func (rw *Rewritable) Flush(force bool)
func (*Rewritable) Write ¶
func (rw *Rewritable) Write(value string)
type Writer ¶
type Writer struct {
io.Writer // Writer to write to
Bytes int64 // Total number of bytes written
Rewritable
}
Writer consistently writes the number of bytes written to Progress.
Example ¶
var progress strings.Builder
writer := &Writer{
Writer: io.Discard,
Rewritable: Rewritable{
FlushInterval: 0,
Writer: &progress,
},
}
writer.Write([]byte("hello"))
writer.Write([]byte(" world"))
// replace all the '\r's with '\n's for testing
fmt.Println(strings.ReplaceAll(progress.String(), "\r", "\n"))
Output: Wrote 5 B Wrote 11 B
Click to show internal directories.
Click to hide internal directories.