4

I'm working on a download manager for electron js project which requires downloading large files.

The multipart-download package unfortunately does not support pausing or cancelling downloads. Are there any other solution which uses Fetch or Axios or anything with pause and cancellation supports?

Sai Krishna
  • 547
  • 1
  • 12
  • 26

2 Answers2

0

Did you consider using asynchronous functions? You can do a lot with JS Promise..

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise

zergski
  • 793
  • 3
  • 10
  • I'm not sure Promises can help with downloading single in multple parts – Sai Krishna Nov 27 '20 at 14:29
  • video and large zip files – Sai Krishna Nov 28 '20 at 02:32
  • I have mainly worked with blobs but should be fairly similar to split video into chunks. Ergo: `createChunks = (file,cSize/* cSize should be byte 1024*1 = 1KB */) => { let startPointer = 0; let endPointer = file.size; let chunks = []; while(startPointer – zergski Nov 29 '20 at 03:36
0

Useful info to write your own downloader implementation: HTML5 File API downloading file from server and saving it in sandbox So you need to download the file via XMLHttpRequest, with HTML5 FileAPI and streamsaver you can save it into client file sandbox. For pausing, you should abort the request and make another with Content-Range headers (Range requests). Of course, they also should be supported on the backend side.

Dmitriy Mozgovoy
  • 1,419
  • 2
  • 8
  • 7
  • The descriptions says it is for uploads – Sai Krishna Nov 27 '20 at 16:16
  • @SaiKrishna Oops. I read it inattentively. In this case it seems you will have to write your own implementation. There are few dead npm packages, but I'm not sure that using it is a good idea (su-downloader3-enhance , cordova-plugin-pause-resume-download). I'm not aware of stable and popular implementation and according to StackOverflow (https://stackoverflow.com/questions/47507608/how-to-pause-and-resume-a-download-file)- nobody does. But it's possible if you have around a week to write your own implementation for both sides- client and server. – Dmitriy Mozgovoy Nov 27 '20 at 17:22