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 🙏

© 2026 – Pkg Stats / Ryan Hefner

hash-worker

v2.0.1

Published

hash-worker is a tool for quickly calculating file's hash

Readme

Hash Worker npm package Bundle size codecov GitHub License

Introduce

中文文档

Hash-worker is a library for fast calculation of file chunk hashes.

It is based on hash-wasm and utilizes WebWorkers for parallel computation, which speeds up computation when processing file blocks.

Hash-worker supports two hash computation algorithms: md5, xxHash64, xxHash128.

Both browser and Node.js are supported.

[!WARNING] The merkleHash computed by the Hash-worker is the root hash of a MerkleTree constructed based on file block hashes. Note that this is not directly equivalent to a hash of the file itself.

Install

$ pnpm install hash-worker

Usage

[!WARNING] If you are using Vite as your build tool, you need to add the following configuration to your Vite config file to exclude hash-worker from Vite's pre-bundling process.

// vite.config.js
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'

export default defineConfig({
  plugins: [vue()],
  // other configurations ...
  optimizeDeps: {
    exclude: ['hash-worker'] // new added..
  }
})

Global

<script src="./global.js"></script>
<script src="./worker/browser.worker.mjs"></script>
<script>
  HashWorker.getFileHashChunks()
</script>

The global.js and browser.worker.mjs are the build artifacts resulting from executing build:core in package.json.

The build artifacts are located in the packages/core/dist directory.

ESM

[!WARNING] Import from 'hash-worker' in the browser environment

Import from 'hash-worker/node' in the browser environment

import { getFileHashChunks, destroyWorkerPool, HashWorkerResult, HashWorkerOptions } from 'hash-worker'

function handleGetHash(file: File) {
  const param: HashWorkerOptions = {
    file: file,
    config: {
      workerCount: 8,
      strategy: Strategy.md5
    }
  }

  getFileHashChunks(param).then((data: HashWorkerResult) => {
    console.log('chunksHash', data.chunksHash)
  })
}

/**
 * Destroy Worker Thread
 */
function handleDestroyWorkerPool() {
  destroyWorkerPool()
}

Options

HashWorkerOptions

HashWorkerOptions is used to configure the parameters needed to calculate the hash.

| filed | type | default | description | |----------|--------|---------|--------------------------------------------------------------------------------------| | file | File | / | Files that need to calculate the hash (required for browser environments) | | filePath | string | / | Path to the file where the hash is to be calculated (required for Node environments) | | config | Config | Config | Parameters for calculating the Hash |

Config

| filed | type | default | description | |--------------------------|----------|----------------|-----------------------------------------------------------------------------------| | chunkSize | number | 10 (MB) | Size of the file slice | | workerCount | number | 8 | Number of workers turned on at the same time as the hash is calculated | | strategy | Strategy | Strategy.xxHash128 | Hash computation strategy | | isCloseWorkerImmediately | boolean | true | Whether to destroy the worker thread immediately when the calculation is complete | | isShowLog | boolean | false | Whether to show log in console when he calculation is complete | | hashFn | HashFn | async (hLeft, hRight?) => (hRight ? md5(hLeft + hRight) : hLeft)| The hash method for build MerkleTree |

// strategy.ts
enum Strategy {
  md5 = 'md5',
  xxHash64 = 'xxHash64',
  xxHash128 = 'xxHash128',
}

type HashFn = (hLeft: string, hRight?: string) => Promise<string>

HashWorkerResult

HashWorkerResult is the returned result after calculating the hash value.

| filed | type | description | |------------|--------------|-------------------------------------------------------------------------| | chunksBlob | Blob[] | In a browser environment only, the Blob[] of the file slice is returned | | chunksHash | string[] | Hash[] for file slicing | | merkleHash | string | The merkleHash of the file | | metadata | FileMetaInfo | The metadata of the file |

FileMetaInfo

| filed | type | description | |--------------|--------|-------------------------------------------------| | name | string | The name of the file used to calculate the hash | | size | number | File size in KB | | lastModified | number | Timestamp of the last modification of the file | | type | string | file extension |

Benchmark (MD5)

| Worker Count | Speed | |--------------|-----------| | 1 | 229 MB/s | | 4 | 632 MB/s | | 8 | 886 MB/s | | 12 | 1037 MB/s |

The above data is run on the Chrome v131 and AMD Ryzen9 5950X CPU, by using md5 to calculate hash.

LICENSE

MIT

Contributions

Contributions are welcome! If you find a bug or want to add a new feature, please open an issue or submit a pull request.

Author and contributors