@rotko/blake3 Usage

Example of using the npm packages via esm.sh CDN

Installation

npm install @rotko/blake3        # Pure JS - works everywhere
npm install @rotko/blake3-wasm   # WASM + Rayon - fastest, needs COOP/COEP headers
npm install @rotko/blake3-auto   # Auto-selects best available

Pure JS (@rotko/blake3)

import { blake3 } from '@rotko/blake3';

const data = new TextEncoder().encode('hello world');
const hash = blake3(data);
console.log(blake3.hex(data)); // hex string
Click "Run Example" to see output

WASM + Rayon (@rotko/blake3-wasm)

import { init, blake3, blake3Parallel } from '@rotko/blake3-wasm';

await init();  // or init(8) for 8 threads
const hash = blake3(data);           // single-threaded WASM
const hashPar = blake3Parallel(data); // multi-threaded with Rayon

Note: WASM package requires COOP/COEP headers for multi-threading. See benchmark for full example.

Auto-select (@rotko/blake3-auto)

import { init, blake3, getBackend } from '@rotko/blake3-auto';

await init();  // auto-detects best backend
const hash = blake3(data);
console.log(getBackend()); // 'wasm-rayon', 'wasm', or 'js'

Live Demo (@rotko/blake3-auto via CDN)

This demo uses pure JS mode. When you install via npm and bundle with your app, @rotko/blake3-auto will automatically use the faster WASM backend if your server sends the required COOP/COEP headers.

Initializing...