Can someone explain the gibberish characters at the end of every .torrent
file?
The picture shows the understandable information along with only a part of the gibberish section. It just seems like the comprehensible part ends so abruptly at the pink pipeline I painted.
By the way, I am viewing it in VIM with UTF-8 encoding, which torrent files should be encoded with if I am not mistaken.
The data you are referring to is the value for the dictionary entry with a key of pieces
. The 6:pieces129140:
before your marked position indicates that the entry's key has a length of 6 characters, which allows us to determine that the key is pieces
. The 129140
which follows the key is the length of the entry's value, in bytes. This data structure is a result of bencoding.
The pieces
dictionary entry in the .torrent
file contains the SHA1 hashes for all pieces concatenated into one long string. Hashes are important as they allow the user to ensure the pieces they have downloaded are valid. Using hashes for individual pieces is better than only having the hash for the whole file, as it reduces the wasted data; you don't have to download the whole file before your client realises that the data is invalid.
SHA1 hashes consist of 20 bytes, which are stored as raw bytes in the .torrent
file. This is why the data appears malformed in your editor.
pieces
maps to a string whose length is a multiple of 20. It is to be subdivided into strings of length 20, each of which is the SHA1 hash of the piece at the corresponding index.
Taken from this BitTorrent protocol specification document.