@xmcl/file-transfer
TypeScript icon, indicating that this package has built-in type declarations

1.0.6 • Public • Published

Download Core

npm version Downloads Install size npm Build Status

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',
})

Package Sidebar

Install

npm i @xmcl/file-transfer

Weekly Downloads

128

Version

1.0.6

License

MIT

Unpacked Size

176 kB

Total Files

44

Last publish

Collaborators

  • ci010