Closed marcosc90 closed 2 months ago
Added the ability to cancel a download.
You can use: downloader.emit('cancel') to cancel the download, and downloader.on('cancelled') to check that it was cancelled.
downloader.emit('cancel')
downloader.on('cancelled')
const downloader = client.downloadFile(params); downloader.on('error', function(err) { console.error('unable to download:', err.stack); }); downloader.on('cancelled', function() { console.log('Download was cancelled:'); }); downloader.on('progress', function() { console.log('progress', downloader.progressAmount, downloader.progressTotal); }); downloader.on('end', function() { console.log('done downloading'); }); setTimeout(() => { downloader.emit('cancel'); }, 2000);
I can change the the API to provide a .cancel method, but since downloader is an EventEmitter using .emit seemed like a good idea.
.cancel
downloader
EventEmitter
.emit
Added the ability to cancel a download.
You can use:
downloader.emit('cancel')
to cancel the download, anddownloader.on('cancelled')
to check that it was cancelled.I can change the the API to provide a
.cancel
method, but sincedownloader
is anEventEmitter
using.emit
seemed like a good idea.