【发布时间】:2022-10-15 13:41:52
【问题描述】:
不久前我看到一个帖子,其中包含使用github.com/cheggaaa/pb 包的进度条功能,内容如下:
func download(destinationPath, downloadUrl string) error {
tempDestinationPath := destinationPath + ".tmp"
request, err := http.NewRequest("GET", downloadUrl, nil)
...
var progressBar *pb.ProgressBar
contentLength := strconv.Atoi(request.Header.Get("Content-Length"))
...
io.MultiWriter(writer, progressBar)
...
我在一些代码中使用了它,但几天前我丢失了那个代码,我再也找不到这个函数了。如果有人可以帮助我至少重写它,我将非常感激。它使用 io.Writer 和 io.MultiWriter 将数据写入文件并立即增加进度条。感谢您的帮助!
【问题讨论】: