英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论