@xmcl/file-transfer
v1.0.6
Published
A high performance downloader based on undici
Downloads
974
Maintainers
Readme
Download Core
Provide a high performance download file function based on undici.
- Support download by range request
- Customize the range size
- Support validating the checksum
- If the validation matched, it won't download the file.
- Also support customize validation.
- Support download and fallback to another url
- Support AbortSignal
- Fully customizable retry logic
Usage
Download the file by url
import { download } from '@xmcl/file-transfer'
await download({
url: 'http://example.com/file.zip', // required
destination: 'file.zip', // required
headers: { // optional
'customized': 'header'
},
abortSignal: new AbortController().signal, // optional
progressController: (url, chunkSize, progress, total) => { // optional
console.log(url)
console.log(chunkSize)
console.log(progress)
console.log(total)
},
// use validator to validate the file
validator: { // optional
algorithm: 'sha1',
hash: '1234567890abcdef1234567890abcdef12345678',
}
})
Download with fallback url
import { download } from '@xmcl/file-transfer'
await download({
// using array to fallback
url: ['http://example.com/file.zip', 'http://example.com/fallback.zip'],
destination: 'file.zip',
})