Documentation ¶
Overview ¶
Package progress provides wrappers for io.Writer and io.Reader that report the progress of the read or write operation via a callback.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
Reader is an io.ReadSeekCloser that reports the number of bytes read from it via a callback.
The callback is called at most every "updateInterval" bytes. The updateInterval can be set using the Reader.WithUpdateInterval method. The callback will also be called whenever Reader.Seek is called.
The following is an example of how to use Reader to report the progress of reading from a file:
file, _ := os.Open("file.txt") progressReader := NewReader(f, func(readBytes int) { fmt.Printf("Read %d bytes\n", readBytes) }) io.ReadAll(progressReader)
func (*Reader) WithUpdateInterval ¶
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
Writer is an io.Writer that reports the number of bytes written to it via a callback. The callback is called at most every "updateInterval" bytes. The updateInterval can be set using the Writer.WithUpdateInterval method.
The following is an example of how to use Writer to report the progress of writing to a file:
file, _ := os.Create("file.txt") progressWriter := progress.NewWriter(func(processedBytes int) { fmt.Printf("Processed %d bytes\n", processedBytes) }) writerWithProgress := io.MultiWriter(file, progressWriter) io.Copy(writerWithProgress, bytes.NewReader(bytes.Repeat([]byte{42}, 1024*1024)))