Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to download a file with resume support? [closed]

Tags:

download

go

Am using golang as a programming tool of choice.

What i wanted to write is a program that downloads large files with resume support utilising range requests in the http headers something similar to aria2c.

like image 745
Degreane Avatar asked Jan 18 '14 08:01

Degreane


People also ask

How do I resume a forbidden download?

Alternatively, you can press Ctrl+J on Windows or Command+J on macOS. In the list of downloads, find the failed item and click “Resume”. If everything goes right, your download will resume from where it left off before you were disconnected.

Can I resume download after shutdown?

If the SERVER that is providing the download supports resuming downloads, then after you resume from hibernation, you should have no issues resuming the download. After you pause the download, there is no need to touch Chrome. Just pause, and hibernate. By that I mean, don't close Chrome.

How do I download without interruption?

download large files without interrupt in smartphone To do this, long-press the download button on the website, and you can see the option Copy Link Address. Now, open the FDM app and you can see the option to add a download link. Paste the link you copied in that textbox and click on OK. And again, click on Download.

Can I resume software update downloading after internet connection is interrupted?

All major browsers, including Firefox, Internet Explorer and Chrome, enable you to resume a download from where it left off in case of a lost connection, so your download will pause, but it won't be lost. Once you've restored your connection and browser, you can resume the download.


1 Answers

To do that you should study the part 14.16 — Content-Range — of the RFC document describing the HTTP/1.1 protocol and then apply that knowledge to manipulate the set of HTTP headers sent when the client request is executed — see the documentation and examples there.

To calculate the range to request, to continue downloading, you should get the current file's size. This can be found in the results returned by the Stat() function which can be called on an opened file — *os.File returned by a call to os.Open().

You should open your file in append mode and then use something like io.Copy() to stream the data from the Body HTTP response member to the file object.

Do your own research on how to read data from HTTP responses in Go — they are abundant on the Internet.

like image 152
kostix Avatar answered Oct 12 '22 03:10

kostix