sharding-downloader
TypeScript icon, indicating that this package has built-in type declarations

1.3.0 • Public • Published

Quick Start

安装

npm i sharding-downloader

使用

import { Downloader } from 'sharding-downloader'

const downloader = new Downloader({
  action: 'https://sharding-download-server.vercel.app/api/file/download',
  chunkSize: 1024 * 1024 * 0.5,
  threads: 3
})
let downloadFileList = []

downloader.on(Callbacks.CHANGE, (file, fileList) => {
  downloadFileList = [...fileList]
})

downloader.on(Callbacks.SUCCESS, (file, fileList) => {
  console.log('Successful', file.link)
  window.open(file.link)
})

downloader.on(Callbacks.FAILED, (file, fileList) => {
  console.log('Failed !!!!!!', file, fileList)
})

downloader.on(Callbacks.PROGRESS, (file, fileList) => {
  console.log('progress', file.progress, fileList)
})

// 开始下载
const hanldeDownload = () => downloader.start('711.jpg')

// 重试
const handleRetry = (file) => file.retry()

// 暂停
const hanlePause = (file) => file.pause()

// 重新下载
const hanleResume = (file) => file.resume()

线上Demo

sharding-download-demo

Package Sidebar

Install

npm i sharding-downloader

Weekly Downloads

27

Version

1.3.0

License

MIT

Unpacked Size

70.6 kB

Total Files

7

Last publish

Collaborators

  • moyuderen.npm