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 123
  • 5:hello → string "hello"
  • l...e → list
  • d...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 tracker
  • announce-list — tiered tracker list
  • info — contains name, files, piece length, and info_hash source
  • private flag — if present and 1

Computing the Info Hash

The info_hash is a SHA-1 hash of the Bencoded info dictionary. We:

  1. Re-encode the info object (preserving key order)
  2. Pass it to crypto.subtle.digest('SHA-1', ...)
  3. 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