@rishighan/tth-cli
v1.0.0
Published
Tiger Tree Hash (TTH) calculator for files and directories, with a parallelized batch CLI for comic archives (cbr/cbz) and anything else
Maintainers
Readme
tth-cli
Tiger Tree Hash (TTH) calculator — the fingerprint scheme used by DC++, Gnutella,
and eD2K/magnet links (urn:tth:<value>). Includes a parallelized batch CLI
originally built for hashing comic archives (.cbr/.cbz), but it works on any
file.
Install
npm install -g @rishighan/tth-cliUsage
Hash one or more files, or recursively scan directories for .cbr/.cbz:
tth-cli path/to/file.cbz
tth-cli path/to/comics/ --out results.csv
tth-cli path/to/comics/ --concurrency 4- With no
--out, results print to stdout astth,size,path. - With
--out, results are written to a CSV file (tth,size,pathheader). --concurrencysets the number of worker threads (default: number of CPU cores).
As a library:
const { tthOfFile, tthOfBuffer } = require('@rishighan/tth-cli/tth-core');
tthOfFile('/path/to/file.cbz'); // => 'QCX7JC7IAEMJZ7PYXKEQMSJIGX2DQX36OBDPURY'
tthOfBuffer(Buffer.from('...'));How it works
TTH builds a Merkle tree over 1024-byte blocks of the file:
- Each 1024-byte block is a leaf, hashed as
Tiger192(0x00 || block). - Leaves are combined pairwise into internal nodes:
Tiger192(0x01 || left || right). If a level has an odd node out, it's promoted unchanged to the next level. - The root digest is Base32-encoded (RFC 4648, no padding) to produce the final 39-character TTH string.
This matches the THEX/TTH scheme documented by DC++ and used in magnet links.
Verified against the well-known reference TTH for a zero-byte file:
LWPNACQDBZRYXW3VHJVCJ64QBZNGHOHHHZWCLNQ.
Performance
The underlying Tiger hash implementation (fb-tiger-hash)
is pure-JS BigInt and single-threaded throughput is roughly 4 MB/s. The batch
CLI parallelizes across files (not within a single file) using Node's
worker_threads, so hashing many files scales close to your core count.
License
MIT
