multipart-get
Run multiple http requests in parallel. Useful for downloading a large file with higher speeds.
Install
npm install multipart-get
Usage
const { promises: fs } = require("fs")
const multipartGet = require("multipart-get")
await fs.writeFile("unicorn.png", await multipartGet("https://example.com/unicorn.png"))
API
multipartGet(url, options?)
Returns a promise which resolves with a buffer.
url
Type: string
The url to send the http requests to.
options
Type: object
Same options as got
in addition to the following:
threads
Type: number
Default: Amount of cpu cores
The number of request threads to use in parallel.
retries
Type: number
Default: 3
The maximum amount of times to try downloading each chunk of data before failing.
Progress updates
You can call .onProgress
on the resulting promise and provide it with a callback to receive progress updates on the http request. The callback will be called with a decimal between 0
and 1
representing the completion percentage.
const { promises: fs } = require("fs")
const multipartGet = require("multipart-get")
const request = multipartGet("https://example.com/unicorn.png")
request.onProgress(percent => {
console.log(`The request is now ${Math.round(percent * 100)}% complete.`)
})
await fs.writeFile("unicorn.png", await request)