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 🙏

© 2025 – Pkg Stats / Ryan Hefner

supfile

v1.0.4

Published

简洁、高可用的文件上传库

Readme

supfile

简洁、高可用的文件上传库

特性

  • 支持文件上传,断点续传
  • 支持异步计算hash
  • 支持多线程分片计算(Web Worker)
  • 可自定义请求策略
  • 支持自定义上传策略:只需实现 RequestStrategy 接口的四个方法,即可对接任意后端或业务流程,方法内部逻辑完全可自定义。
  • 支持秒传
  • 支持断点续传

快速开始

安装(从 npm):

npm install supfile
// 简单自定义 RequestStrategy(示意)
class MyRequestStrategy {
async createFile(file) {
// 返回用于后续请求的 token
return 'mock-token';
}
async patchHash(token, hash, type) {
// 向服务端校验 hash,示例返回需要补传的分片索引数组
return { hasFile: false, rest: [] };
}
async uploadChunk(chunk) {
// 上传分片实现
}
async mergeFile(token) {
// 合并并返回文件 URL
return 'https://example.com/uploaded-file';
}
}

// 使用示例
import { UploadController } from './dist/index.esm.js'; // 或直接 import 'supfile'(已发布包)
const requestStrategy = new MyRequestStrategy();
const controller = new UploadController({
file: /_ File 或 Blob _/,
requestStrategy,
// 可选回调
callbacks: {
onProgress: percent => console.log('progress:', percent + '%'),
onEnd: url => console.log('end:', url),
onError: err => console.error('error:', err)
}
});

// 启动上传(示例方法名,根据你的 SDK 接口调用)
controller.start();

参数说明

| 参数 | 类型 | 必填 | 默认 | 说明 | | ----------------- | ------------------: | :--: | :------: | ----------------------------------------------------------------------------- | | file | File | Blob | 是 | — | 要上传的文件或二进制对象。 | | concurrency | number | 否 | 4 | 并发上传分片数。 | | chunkSize | number | 否 | 5MB | 分片大小(字节)。示例常用值:1 _ 1024 _ 1024(1MB)或 1024 * 512(512KB)。 | | requestStrategy | RequestStrategy | 是 | — | 自定义请求策略实例,需实现 createFile / patchHash / uploadChunk / mergeFile。 | | splitStrategyType | 'simple' | 'mutil' | 否 | 'simple' | 分片策略类型:'simple'(单线程)或 'mutil'(使用 Worker 并行计算 hash)。 | | callbacks | Object | 否 | {} | 回调集合(见下)。 |

常用 callbacks 字段:

  • onProgress(percent: number) — 上传进度(0-100)
  • onEnd(url: string) — 上传完成并返回文件 URL
  • onError(err: any) — 上传出错回调
  • onChunkHashed( hash: string) — hash 计算完成