github.com/weiwenhao/getter@v1.30.1/client_option_progress.go (about)

     1  package getter
     2  
     3  import (
     4  	"io"
     5  )
     6  
     7  // WithProgress allows for a user to track
     8  // the progress of a download.
     9  // For example by displaying a progress bar with
    10  // current download.
    11  // Not all getters have progress support yet.
    12  func WithProgress(pl ProgressTracker) func(*Client) error {
    13  	return func(c *Client) error {
    14  		c.ProgressListener = pl
    15  		return nil
    16  	}
    17  }
    18  
    19  // ProgressTracker allows to track the progress of downloads.
    20  type ProgressTracker interface {
    21  	// TrackProgress should be called when
    22  	// a new object is being downloaded.
    23  	// src is the location the file is
    24  	// downloaded from.
    25  	// currentSize is the current size of
    26  	// the file in case it is a partial
    27  	// download.
    28  	// totalSize is the total size in bytes,
    29  	// size can be zero if the file size
    30  	// is not known.
    31  	// stream is the file being downloaded, every
    32  	// written byte will add up to processed size.
    33  	//
    34  	// TrackProgress returns a ReadCloser that wraps the
    35  	// download in progress ( stream ).
    36  	// When the download is finished, body shall be closed.
    37  	TrackProgress(src string, currentSize, totalSize int64, stream io.ReadCloser) (body io.ReadCloser)
    38  }