How to print the bytes while the file is being downloaded ? -golang

后端 未结 4 2127
无人共我
无人共我 2021-01-31 06:29

I\'m wondering if it\'s possible to count and print the number of bytes downloaded while the file is being downloaded.

out, err := os.Create(\"file.txt\")
    d         


        
4条回答
  •  渐次进展
    2021-01-31 07:21

    The grab Go package implements progress updates (and many other features) for file downloads.

    An example of printing progress updates while a download is in process is included in the following walkthrough: http://cavaliercoder.com/blog/downloading-large-files-in-go.html

    You can basically call grab.GetAsync which downloads in a new Go routine and then monitor the BytesTransferred or Progress of the returned grab.Response from the calling thread.

提交回复
热议问题