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

large-file-upload-worker

v1.0.0

Published

A JavaScript library for uploading large files using Web Workers and FileReader. The library computes the SHA-1 hash of the files and supports parallel uploads.

Downloads

2

Readme

Large File Upload Worker

Large File Upload Worker 是一个用于处理大文件上传的 JavaScript 库。它使用 Web Workers 和 FileReader 进行文件的分片和并行上传,同时计算文件的 SHA-1 哈希值。计算哈希值使用了 Web Crypto API

特性

  • 使用 Web Workers 进行文件上传,不阻塞主线程。
  • 使用 FileReader 读取文件,防止一次性读取大文件导致内存溢出。
  • 计算文件的 SHA-1 哈希值,使用 Web Crypto API
  • 支持文件上传进度跟踪和错误处理。

安装

npm install large-file-upload-worker

使用

import FileUploader from 'large-file-upload-worker';

const fileUploader = new FileUploader({
  workerPoolSize: 5,
  fileReaderPoolSize: 5,
  chunkSize: 1024 * 1024,
  workerScript: './upload-worker.js',
  algorithm: 'SHA-1',
});

fileUploader.upload(file, uploadConfig);

API

new FileUploader(options)

创建一个新的文件上传器实例。

参数:

  • options: 配置对象。
    • workerPoolSize: Worker 池大小,默认为 5。
    • fileReaderPoolSize: FileReader 池大小,默认为 5。
    • chunkSize: 文件分片大小,默认为 1MB。
    • workerScript: Worker 脚本的路径,需要相对于使用者的环境,默认为 './upload-worker.js'。
    • algorithm: 用于计算文件哈希值的算法,默认为 'SHA-1',其他支持算法请查看 Web Crypto API

fileUploader.upload(file, uploadConfig)

上传一个文件。

参数:

  • file: 要上传的文件对象。
  • uploadConfig: 上传配置对象。
    • url: 上传的 URL。
    • headers: 上传请求的头部信息。
    • params: 上传请求的参数。
    • workerScript: Worker 脚本的路径,需要相对于使用者的环境,默认为 './upload-worker.js'。
    • algorithm: 用于计算文件哈希值的算法,默认为 'SHA-1'。 返回一个 Promise,解析为上传结果。

自定义事件

| 事件名称 | 返回值 | 功能 | | ------------------------ | ----------------------------------------------- | ------------------------------------------------ | | hashProgress | { progress, processedSlices, totalSlices } | 在文件哈希计算过程中触发,返回当前进度信息 | | hashCompleteEvent | { hashHex } | 当文件哈希计算完成时触发 | | uploadProgress | { fileHash, index, success, total } | 在文件上传过程中触发,返回当前上传的进度信息 | | uploadError | { fileHash, index, total, error } | 当文件上传出错时触发,返回错误信息 | | uploadComplete | { fileHash, total } | 当文件上传完成时触发 |

以上信息是根据具体代码实现进行调整的,如果有任何错误或遗漏,请随时告知。

开发和调试

运行以下命令启动开发服务器:

npm test

此命令将启动 browser-sync,你可以在浏览器中打开 localhost:3000 来查看和调试。

问题反馈

如果你在使用过程中遇到问题,欢迎通过 GitHub Issues 提交问题。

许可证

此项目使用 MIT 许可证,详见 LICENSE 文件。

贡献

欢迎任何形式的贡献,包括提出问题、添加新功能、改进文档等。