Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

interrupt feature while downloading folder from S3

I am using https://www.npmjs.com/package/s3 package to download folder from s3 but I am not able to find any method to cancel the download or interrupt the download process.

So how can I interrupt the ongoing download or stop the download process? Any suggestions for packages offering this feature?

Folder size is upto 10GB and folder contains 1000s of file so it is creating multiple requests for same folder.

like image 510
Varis Bhalala Avatar asked Jan 26 '23 15:01

Varis Bhalala


1 Answers

I modified the code of the s3 module to allow cancellation.

Here's the PR, but in the meantime you can use my fork for testing:

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);

What I added is a way to call request.abort() on the s3.getObject request.

like image 158
Marcos Casagrande Avatar answered Jan 29 '23 06:01

Marcos Casagrande