A browser based multi-threaded downloader implemented in vanilla JavaScript.
Fetches parts of a file using the HTTP Range header and downloads those pieces in parallel. When the pieces have all been downloaded, the original file is re-assembled and saved in the browser's Downloads folder.
The downloader should fetch the file directly from the web browser without a server needed to proxy the file. The download process should not need any client software or browser plugin to be installed. It should allow for resuming an interrupted download, or at least retrying a part of the file that was interrupted.
This project will allow us to specify the number of download threads and the size of each request... so we can tune it for specific network conditions, if that is necessary.
100% client side JavaScript, no plug-ins or proxy required
The Multithread constructor accepts a single object parameter:
new MultiThread({
url: 'http://some-url/', // The request url
headers: { // Request headers to pass-though
'Authorization': `Bearer ${accessToken}`
},
fileName: 'some-file.ext', // The final output fileName
chunkSize: 4, // Size of each chunk in MB
threads: 6, // Number of concurrent request threads
retries: 2, // Number of retry attempts
retryDelay: 1000 // Delay before another retry attempt in ms
})
Multithread triggers several events that you can attach callbacks to. The callbacks will be called with a single object consisting of the following keys:
Each individual chunk will also trigger it's own events:
PromiseQueue provides concurrency by using a queue of promises. It will automatically retry a configurable amount of times before triggering either an "onFinish" or "onError" event.