hgouveia / node-downloader-helper

A simple http file downloader for node.js
MIT License
247 stars 54 forks source link

Workaround for resuming downloads after app restart no longer working with v1.0.19 #72

Closed AS-Omar closed 2 years ago

AS-Omar commented 2 years ago

I was using this workaround you posted for resuming downloads after restarting the Electron app: https://github.com/hgouveia/node-downloader-helper/issues/13#issuecomment-637779060

It was working fine with v1.0.18. However, after upgrading to v1.0.19, this workaround is no longer working and throws an error. Can the workaround be modified so that it works with v1.0.19?

Chaphasilor commented 2 years ago

If you could share your code snippet, error message and Node version, I'd take a look at what's going on :)

AS-Omar commented 2 years ago

Here's the code snippet (which works with v1.0.18):

downloader = new DownloaderHelper(fileUrl, downloadDirectory, {
  fileName: fileName,
  override: true,
  retry: { maxRetries: 3, delay: 1000 },
  removeOnStop: false,
  removeOnFail: false
})

downloader.__total = fileSize
downloader.__filePath = path.join(downloadDirectory + fileName)
downloader.__downloaded = downloader.__getFilesizeInBytes(downloader.__filePath)
downloader.__isResumable = true

downloader.resume()

When I call downloader.resume(), I get the this: TypeError: Cannot read property 'resolve' of null.

The Node.js version is 14.16.0 (which comes bundled with Electron 13.6.2).

Alzar commented 2 years ago

Any fix ever come for this? Running into the same issue with 1.0.19 running Node 16.9.1 (Electron v16.0.7). If I downgrade to v1.0.18 it works without issue

Chaphasilor commented 2 years ago

okay so it looks like there's a bit more going on than I initially thought, I'll take a closer look at it over the coming days :)

hgouveia commented 2 years ago

@Chaphasilor is this covered with your PR #76 ?

Chaphasilor commented 2 years ago

Nope, didn't get around to this just yet. There was some refactoring and internal method renaming from 1.0.18 to 1.0.19 that seems to be causing this issue...

hgouveia commented 2 years ago

@Chaphasilor not a problem, i though was related, i will take a look on my part 👍🏽

milkliker commented 2 years ago

Found a walk around like this

downloader.__total = fileSize;
downloader.__filePath = path.join(downloadDirectory + fileName);
downloader.__downloaded = downloader.__getFilesizeInBytes(downloader.__filePath);
downloader.__setState(downloader.__states.RESUMED);
downloader.__isResumed = true;
downloader.__options['headers']['range'] = 'bytes=' + downloader.__downloaded + '-';
downloader.start();

It's very dirty, but works. I wish this could be implemented as a spec.

hgouveia commented 2 years ago

Implemented resume from file in 2.1.0