Parsing .torrent Files in the Browser
The Torrent Tracker Analyzer can read and interpret .torrent files entirely in your browser — no server, no upload, no third-party tools. This deep dive explains how.
Bencode: The Torrent Format
Torrent files use Bencode — a simple, text-based serialization format. It supports four types:
i123e→ integer 1235:hello→ string "hello"l...e→ listd...e→ dictionary
Our parser reads the file as an ArrayBuffer, then recursively decodes these structures into a JavaScript object.
Extracting Key Data
From the decoded dictionary, we extract:
announce— primary trackerannounce-list— tiered tracker listinfo— contains name, files, piece length, andinfo_hashsourceprivateflag — if present and1
Computing the Info Hash
The info_hash is a SHA-1 hash of the Bencoded info dictionary. We:
- Re-encode the
infoobject (preserving key order) - Pass it to
crypto.subtle.digest('SHA-1', ...) - Convert to hex and base32
File List Handling
For multi-file torrents, the info.files array contains path and length. We reconstruct full paths like folder/subfolder/file.mp4.
Performance & Accuracy
Parsing a 1 MB torrent takes <100 ms. We validate dictionary keys and handle edge cases like missing fields or malformed Bencode.
FAQ
Why not use a library?
We use a lightweight, zero-dependency Bencode parser for full control and tree-shaking.
Does it support magnet links?
Yes — we extract xt=urn:btih:... and tr=... parameters.
Ready to inspect your own torrent? Launch the Analyzer