Varis Bhalala
Varis Bhalala

Reputation: 123

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.

Upvotes: 4

Views: 484

Answers (1)

Marcos Casagrande
Marcos Casagrande

Reputation: 40444

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.

Upvotes: 8

Related Questions