npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

file-slice-upload

v2.0.2

Published

file-slice-upload

Downloads

30

Readme

📄 File-Slice-Upload

快速开始

1. 安装

  • 使用 npm 安装
npm install file-slice-upload
  • 使用 yarn 安装
yarn add file-slice-upload

2. 使用 file-slice-upload 上传文件碎片

import fileUpload from 'file-slice-upload'
fileUpload(1024 * 1024)
.setFile(youFile)
.setAjax(async({chunk, md5})=>{
  const success = await postChunkFile(chunk, md5)
  return success   /* 返回 true 将会上传下一个文件碎片 */
})
.start()

在线demo

  1. live-demo-原生
  2. live-demo-react demo源码: github

🔥🔥🔥 特点

  1. 只需专注上传逻辑!
  2. 友好、易读的 api .start() .cancel()
  3. 支持事件 start finish stop progress error, 降低代码耦合
  4. 轻量
  5. 使用 typescript 编码, 类型提示良好

API文档

默认导出

FileSliceUpload类的工厂函数,返回 FileSliceUpload 实例

  1. factory(chunkSize) => FileSliceUpload

| 参数名 | 类型 | 必传 | 说明 | |------| --------------- | ----- | ---------------- | | chunkSize | int | false | 分片大小(BYTE), 默认值1024 * 1024(1MB) |

FileSliceUpload 类

方法列表

  1. setFile(file) => this

| 参数名 | 类型 | 必传 | 说明 | | ------ | --------------- | ----- | ---------------- | | file | File | true | 分片上传的文件 |

  1. fileUpload.setAjax(ajax) => this

| 参数名 | 类型 | 必传 | 说明 | | ------ | --------------- | ----- | ---------------- | | ajax | ({chunk: File, index: number, md5: string, all: number}) => Promise<boolean> | true | 上传文件碎片的函数,该函数被调用返回true就上传下一个碎片|

  1. fileUpload.start() 开始上传
  2. fileUpload.cancel() 取消上传
  3. fileUpload.on(eventName, cb) => this 监听上传事件

| eventName | 说明 | cb函数类型 | ------ | --------------- | ----- | | start | 开始上传 | () => void | | finish | 上传完成 | ({ file: File, chunkSize: number, md5: string, all: number }) => void| | cancel | 取消上传 | () => void | | progress | 上传进度 | ({done: number, all: number, type: 'md5' | 'upload'}) => void | | chunk-uploaded | 分片上传成功 |({chunk: File, index: number, file: File, md5: string}) => void | | error | 上传失败 | () => void |

  1. fileUpload.getFile() => file 获取原始完整文件

  2. fileUpload.off(eventName, cb) => this 取消事件注册