0.1.4 • Published 4 months ago

digest-wasm v0.1.4

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
4 months ago

DigestWasm

基于 RustCrypto 库编译而成的 wasm 哈希库

用于提高 Md5 Sha256 Sha512 等计算速度

WebAssembly

测试地址

Install

pnpm install digest-wasm

Usage

正常使用

import {Md5, Sha256, Sha512} from "digest-wasm";

const md5 = await Md5.digest("Hello World!")
const sha256 = await Sha256.digest("Hello World!")
const sha512 = await Sha512.digest("Hello World!")
const buffer = await new Blob(["Hello World!"]).arrayBuffer()
const md5 = await Md5.digest_u8(new Uint8Array(buffer))
const sha256 = await Sha256.digest_u8(new Uint8Array(buffer))
const sha512 = await Sha512.digest_u8(new Uint8Array(buffer))

增量计算

import {Md5, Sha256, Sha512} from "digest-wasm";

const file_hash = async (file, chunkSize = 128 << 20) => {
    const hash = Md5.new()
    // const hash = Sha256.new()
    // const hash = Sha512.new()

    for (let i = 0; i < Math.ceil(file.size / chunkSize); i++) {
        const chuck = await file.slice(chunkSize * i, chunkSize * (i + 1)).arrayBuffer()
        await hash.update(new Uint8Array(chuck))
    }

    return hash.finalize()
}
0.1.4

4 months ago

0.1.2

4 months ago

0.1.3

4 months ago

0.1.1

4 months ago

0.1.0

4 months ago