0.1.0 • Published 1 year ago

kun-hash v0.1.0

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year ago

Introduce

Kun-hash is a library for quickly calculating file hashes. It leverages WebWorkers for parallel computation based on hash-wasm, accelerating the speed of calculation when processing file chunks. Kun-hash supports two algorithms for hash calculation: md5 and crc32.

!WARNING The merkleHash calculated using Kun-hash is derived from computing the MerkleTree based on the hashes of file chunks, resulting in the rootHash, rather than the hash of the file itself.

Install

$ yarn add kun-hash

# or

$ npm install kun-hash

Usage

import { getFileHashChunks, Strategy, FileHashChunksResult, FileHashChunksParam } from 'kun-hash'

function handleGetHash() {
  const param: FileHashChunksParam = {
    file: file!,
    strategy: Strategy.crc32
  }

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

Options

FileHashChunksParam

paramstypedefaultdescription
fileFile/The file for which the Hash is to be calculated (required)
chunkSizenumber10 (MB)Chunk size
maxWorkerCountnumber8The maximum number of webWorkers that can run simultaneously when calculating the Hash
strategyStrategyStrategy.mixedHash calculation strategy
borderCountnumber100The boundary point of hash calculation rules in 'mixed' mode
// strategy.ts
export enum Strategy {
  md5 = 'md5',
  crc32 = 'crc32',
  mixed = 'mixed',
}

When using the Strategy.mixed strategy, if the number of file fragments is less than the borderCount, the md5 value will be used to construct the MerkleTree; otherwise, crc32 will be used.

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

0.1.0

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago

1.0.0

1 year ago