Loading AI tools
Data serialization format From Wikipedia, the free encyclopedia
Bencode (pronounced like Bee-encode) is the encoding used by the peer-to-peer file sharing system BitTorrent for storing and transmitting loosely structured data.[1]
It supports four different types of values:
Bencoding is most commonly used in torrent files, and as such is part of the BitTorrent specification. These metadata files are simply bencoded dictionaries.
Bencoding is simple and (because numbers are encoded as text in decimal notation) is unaffected by endianness, which is important for a cross-platform application like BitTorrent. It is also fairly flexible, as long as applications ignore unexpected dictionary keys, so that new ones can be added without creating incompatibilities.
Bencode uses ASCII characters as delimiters and digits.
i42e
, 0 as i0e
; and -42 as i-42e
. Negative zero is not permitted.4:spam
. The specification does not deal with encoding of characters outside the ASCII set; to mitigate this, some BitTorrent applications explicitly communicate the encoding (most commonly UTF-8) in various non-standard ways. This is identical to how netstrings work, except that netstrings additionally append a comma suffix after the byte sequence.l4:spami42ee
. Note the absence of separators between elements, and the first character is the letter 'l', not digit '1'.{"bar": "spam", "foo": 42}
), would be encoded as follows: d3:bar4:spam3:fooi42ee
.There are no restrictions on what kind of values may be stored in lists and dictionaries; they may (and usually do) contain other lists and dictionaries. This allows for arbitrarily complex data structures to be encoded.
Bencode is a very specialized kind of binary coding with some unique properties:
However, this uniqueness can cause some problems:
Seamless Wikipedia browsing. On steroids.
Every time you click a link to Wikipedia, Wiktionary or Wikiquote in your browser's search results, it will show the modern Wikiwand interface.
Wikiwand extension is a five stars, simple, with minimum permission required to keep your browsing private, safe and transparent.