1.0.2 • Published 3 years ago

wuxun-downloadfile v1.0.2

Weekly downloads
-
License
ISC
Repository
github
Last release
3 years ago

wuxun-downloadfile

下载文件 Download files

Install

$ npm install wuxun-downloadfile

API

downloadFile(options)

传递一个对象,返回一个 Promise 对象和文件流对象 Returns both a Promise<Buffer> and File stream

options

fileUrl

Type: String 文件路径 Path to where your file will be written.

fileName

Type: String 文件名称 File name

fileType

Type: String 文件类型 如果没传类型,则会从文件名称获取类型 例如'video.mp4' If there is no type, the file name will be intercepted to get the type

isDownload

Type: Boolean Default:true 是否默认下载文件 Whether to download files by default.

onprogress

Type: Function 文件下载进度回调方法 File download progress callback method.

Usage

import downloadFile from 'wuxun-downloadfile'

downloadFile({
    fileUrl: "https://cdn.apedesign.net/github/logo.png",
    fileName: "CDN",
    fileType: "png",
    onprogress: (progress) => {
      // 获取下载进度 / get progress
    },
  })
    .then((data) => {
      // 下载结束时调用/Called when download ended
      console.log(data);
    })
    .catch((error) => {
      // 发生错误时调用/ Called when an error occurred
      console.log(error);
    });
1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago