在下载过程中添加暂停和恢复功能。

huangapple go评论87阅读模式
英文:

Add Pause and Resume functionality while downloading

问题

我正在使用这种方法来从给定的URL下载任何文件。我想在下载过程中添加暂停和恢复功能。我尝试使用通道,但没有成功。

英文:

I am using this approach for downloading any file from the given URL. I want to add pause and resume functionality while downloading. I tried to use channels but was not able to succeed.

答案1

得分: 4

你不能真正“暂停”一个下载。你只能取消它。你可以通过在http.Request上执行close(req.Cancel)来取消下载。

“恢复”下载实际上只是再次发送相同的请求,但告诉服务器从哪里开始。通常是通过设置一个“Range”头。

这个问题在superuser上更好地解释了它的工作原理。如果你想进一步获得帮助,你可能需要提供更多细节。

英文:

You don't really "pause" a download. You can only cancel it. You can do that on an http.Request by doing close(req.Cancel).

"Resuming" a download is really just making the same request again, but telling the server where to start. Usually by setting a "Range" header.

This question on superuser explains a bit better how it works usually. You will probably need to provide more details if you want us to help you further.

huangapple
  • 本文由 发表于 2015年10月30日 14:57:04
  • 转载请务必保留本文链接:https://go.coder-hub.com/33430341.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定