hgouveia / node-downloader-helper

A simple http file downloader for node.js

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

how to cancel one file download when doing multiple downloads

D-cat1 opened this issue · comments

how to cancel one file download when doing multiple downloads

how to do this ?

@D-cat1 by default there is not way to do multiple download, so you will need to store each instance of each download and then cancel all one by one ex:

const { DownloaderHelper } = require('node-downloader-helper');
const destFolder = __dirname;
const urlList = ['http://url1.com', 'http://url2.com','http://url3.com'];
const downloads = [];

urlList.forEach( (url) =>{
   const dl = new DownloaderHelper(url, destFolder );
   downloads.push(dl);
   dl.on('end', () => console.log('Download Completed'))
   dl.start();
});

function cancelAll(){
  downloads.forEach( dl => dl.stop());
}

for functional question is better to use the new Discussion section