hgouveia / node-downloader-helper

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

`resume()` fails if file does not exist. #107

Closed jwalton closed 11 months ago

jwalton commented 11 months ago

The documentation for resume() says: "resume the downloading if supported, if not it will start from the beginning". I assumed this meant I could just call resume() instead of start() to start downloading a file if it isn't there, or to continue downloading the file if it isn't. But, if you try:

const { DownloaderHelper } = require('node-downloader-helper');
const dl = new DownloaderHelper('https://proof.ovh.net/files/1Gb.dat', __dirname, {
    resumeIfFileExists: true,
    removeOnStop: false,
    removeOnFail: false,
});

dl.on('end', () => console.log('Download Completed'));
dl.on('error', (err) => console.log('Download Failed', err));
dl.on('progress', ({ downloaded, total }) => console.log(`Got ${downloaded}/${total}`));
dl.resume().catch((err) => console.error(err));

This will fail with:

TypeError: Cannot read properties of null (reading 'resolve')
    at b.a (/Users/jwalton/solink/interlink/interlink-builder-2/node_modules/node-downloader-helper/dist/index.js:1:8434)
    at b.a (/Users/jwalton/solink/interlink/interlink-builder-2/node_modules/node-downloader-helper/dist/index.js:1:4219)
    at Object.<anonymous> (/Users/jwalton/solink/interlink/interlink-builder-2/main.cjs:7:4)
    at Module._compile (node:internal/modules/cjs/loader:1256:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
    at Module.load (node:internal/modules/cjs/loader:1119:32)
    at Module._load (node:internal/modules/cjs/loader:960:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
    at node:internal/main/run_main_module:23:47
hgouveia commented 11 months ago

@jwalton in which version did this happened? if this happened with latest 2.1.8, could you try install to 2.1.7? and let me know if the same issue happens?

hgouveia commented 11 months ago

@jwalton nevermind i found the issue, i deployed a new version 2.1.9 , please update it