Library for encoding and decoding bencode data.
Project description
Bendercoder
Library for encoding and decoding bencode data.
Table of content
Introduction
Bencode (pronounced like B-encode) is the encoding used by the peer-to-peer file sharing system BitTorrent for storing and transmitting loosely structured data. It supports four different types of values:
- byte strings,
- integers,
- lists,
- dictionaries (associative arrays).
Bencoding is most commonly used in torrent files. These metadata files are simply bencoded dictionaries.
Description from wikipedia.
Installing
pip install bendercoder
Usage
For decoding the integer number 10.
# coding=utf-8
from decoder import Decoder
decoder = Decoder(payload=b'i10e')
decoded_value = decoder.decode()
print(decoded_value)
For decoding the string foo.
# coding=utf-8
from decoder import Decoder
decoder = Decoder(payload=b'3:foo')
decoded_value = decoder.decode()
print(decoded_value)
For decoding the list [1, 2, 3, 'bar']
# coding=utf-8
from decoder import Decoder
decoder = Decoder(payload=b'li1ei2ei3e3:bare')
decoded_value = decoder.decode()
print(decoded_value)
For decoding the dictionary {'test': 'foo', 'bar': 2}
# coding=utf-8
from decoder import Decoder
decoder = Decoder(payload=b'd4:test3:foo3:bari2ee')
decoded_value = decoder.decode()
print(decoded_value)
Links
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
bendercoder-1.0.tar.gz
(3.6 kB
view hashes)
Built Distribution
Close
Hashes for bendercoder-1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | db72462f103fc94d2e1297923bcb6c1367fc08defede07d323b5060a113c1601 |
|
MD5 | d6f98a032a0ed9f4a9c89fd8154d203b |
|
BLAKE2b-256 | 39585cd9e92eef30ab6f181f7efd172021556474efdef1208515b20fd5757bb6 |