overlookmotel/got-resume

manual pause/ resume download

karmac2015 opened this issue · 5 comments

How can I pause and resume download using got-resume. If there is no way to do that I will abort the download if I need to pause it, but I need a function to start the download from defined start offset

There are two ways to do this.

  1. Abort to pause and then start a new transfer when you want to resume using offset option (see the README).
  2. If you are using the stream method (i.e. not gotResume.toFile()) then when you want to pause, stop your write stream indicating it's ready for more. Then back pressure will apply and pause the download. Please read about streams back pressure if you don't understand what I'm talking about.

(2) will only work for short pauses (a few seconds), because the requests will timeout after a while, triggering a retry.

I will start a new transfer but how if I have a reference to the aborted one how can I start it again without registering events again, if there is a resume() function in the api so I don't need to register events each time I want to start the request

There is no pause/resume functionality built in to got-resume. If you abort one transfer and start another, it's a completely new transfer as far as got-resume is concerned, so you need to handle the events and somehow stitch the data from the two transfers together yourself.

This is a pretty niche requirement and I don't need it myself, so I'm afraid I'm not going to implement it. But I would be happy to receive a PR to add this functionality if you want to do it.

I like your library and I tried it in my app, but I found that got has a retry feature, what is the difference between your library and that feature. I know that you don't need to implement the resume functionality but node-download-helper has this feature, if any one need to get the concept from it.

My understanding is that got's retry option will cause it to start the download again from the start. i.e. if on first attempt the download gets to 95% and fails, got will try again, starting from 0% again.

With this module, if the download fails at 95%, it will try again from where it left off i.e. will only download the final 5% rather than starting again from the beginning.

This module is designed for downloading large files where transfer failures are common due to flaky internet etc and you don't want to repeat work which may have taken hours.

Like I said, I'd encourage you to submit a PR for pause/resume if you want it. But I'm afraid I'm not able to offer you further support beyond that.