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

smt-hash

v2.0.8

Published

Smart file hash calculator with web worker support

Readme

smt-hash

Smart Multi-threading Hash / 智能多线程哈希 一个基于SparkMD5的文件哈希计算库,支持单线程和多线程计算,并提供文件批量处理功能。

Dependencies / 依赖

  • SparkMD5
  • Worker
  • pLimit

Installation / 安装

npm install smt-hash

yarn add smt-hash

Usage / 使用

本模块支持多个默认导出,可以按需导入。

| Function Name / 函数名 | Description / 说明 | Parameters and Types / 参数及参数类型 | Callback Parameters / 回调参数 | Return Type / 返回类型 | | ---------------------- | --------------------------------------------------------------------------------------------- | --------------------------------------------------------- | ------------------------------------------------ | ---------------------- | | createChunks | Create file chunks / 创建文件切片 | file: File, chunkSize: number | None / 无 | Blob[] | | calculateHash | Calculate file hash (automatic mode) / 计算文件哈希值 (自动模式) | file: File, options: HashOptions | current: number, total: number, percent: string; | Promise | | singleThreadHash | Single-threaded file hash calculation (file < 10MB) / 单线程计算文件哈希值 (file<10MB) | chunks: Blob[], onProgress?: (data: ProgressData) => void | current: number, total: number, percent: string; | Promise | | multiThreadHash | Multi-threaded large file hash calculation (file > 10MB) / 多线程计算大文件哈希值 (file>10MB) | chunks: Blob[], onProgress?: (data: ProgressData) => void | current: number, total: number, percent: string; | Promise | | calculateAllHashes | Batch file hash calculation (files > 1) / 批量计算文件哈希值 (files > 1) | files: File[], options: AllHashOptions | current: number, total: number, percent: string; | Promise |

How to use callbacks? / 回调怎么使用?

Take calculateHash as an example, the callback parameters are as follows: 以 calculateHash 为例,回调参数如下:

calculateHash(file, {
  chunkSize: 1024 * 1024, // Set to 1MB per chunk / 设置为每1MB一次
  useWorkerThreshold: 1024 * 1024 * 10, // Set the threshold for starting multi-threading / 设置启动多线程的阈值
  onProgress: (data) => {
    console.log(data) // data.current: current file chunk being calculated / 当前计算的文件块
                      // data.total: total file chunks / 总文件块
                      // data.percent: percentage of current file chunk being calculated / 当前计算的文件块的百分比
  }
})

Types / 类型

ProgressData

interface ProgressData {
  name?: string;     // File name / 文件名
  current: number;   // Number of processed chunks / 已处理块数
  total: number;     // Total number of chunks / 总块数
  percent: string;   // Progress percentage / 进度百分比
}

HashOptions

interface HashOptions {
  chunkSize?: number; // Size of each chunk in bytes, default is 10MB / 每个分块的大小(字节),默认10MB
  useWorkerThreshold?: number; // Threshold for enabling multi-threading in bytes, files larger than this use Worker, default is 10MB / 启用多线程的阈值(字节),文件大于该值使用Worker,默认10MB
  onProgress?: (data: ProgressData) => void; // Progress callback for a single file / 单个文件进度回调
}

AllHashOptions

interface AllHashOptions extends HashOptions {
  maxConcurrency?: number; // Maximum number of concurrent file processing, default uses hardware concurrency / 最大并发文件处理数,默认使用硬件并发数
  onFileProgress?: (data: ProgressData & { file: string }) => void; // Progress callback for a single file with file name / 单个文件进度回调(带文件名)
  onTotalProgress?: (data: Omit<ProgressData, 'name'>) => void; // Global total progress callback / 全局总进度回调
}

HashResult

interface HashResult {
  name: string;     // File name / 文件名
  hash: string | null; // Hash value (null if failed) / 哈希值(失败为null)
  error?: Error;    // Error information / 错误信息
}

Browser Compatibility / 浏览器兼容性

| Browser / 浏览器 | Supported / 支持 | Notes / 注意事项 | | ---------------- | ---------------- | -------------------------------------------- | | Chrome 89+ | ✅ | Perfect support / 完美支持 | | Firefox 78+ | ✅ | Workers need to be enabled / 需要启用workers | | Safari 15+ | ✅ | Requires HTTPS environment / 需要 HTTPS 环境 | | Edge 89+ | ✅ | Perfect support / 完美支持 |

For issues with the module, please contact / 模块出现问题请联系

[email protected]

Fixed multi-threaded blob transfer error / 修复多线程计算blob传递错误