Skip to main content

Library for encoding and decoding bencode data.

Project description

Bendercoder

Build Status Coverage Status

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 and encoding the integer number 10.

# coding=utf-8
from decoder import Decoder
from encoder import Encoder

decoder = Decoder(payload=b'i10e')
decoded_value = decoder.decode()
print(decoded_value)

encoder = Encoder(payload=decoded_value)
encoded_value = encoder.encode()
print(encoded_value)

For decoding and encoding the string foo.

# coding=utf-8
from decoder import Decoder
from encoder import Encoder

decoder = Decoder(payload=b'3:foo')
decoded_value = decoder.decode()
print(decoded_value)

encoder = Encoder(payload=decoded_value)
encoded_value = encoder.encode()
print(encoded_value)

For decoding and encoding the list [1, 2, 3, 'bar']

# coding=utf-8
from decoder import Decoder
from encoder import Encoder

decoder = Decoder(payload=b'li1ei2ei3e3:bare')
decoded_value = decoder.decode()
print(decoded_value)

encoder = Encoder(payload=decoded_value)
encoded_value = encoder.encode()
print(encoded_value)

For decoding and encoding the dictionary {'test': 'foo', 'bar': 2}

# coding=utf-8
from decoder import Decoder
from encoder import Encoder

decoder = Decoder(payload=b'd4:test3:foo3:bari2ee')
decoded_value = decoder.decode()
print(decoded_value)

encoder = Encoder(payload=decoded_value)
encoded_value = encoder.encode()
print(encoded_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.

Files for bendercoder, version 1.2.1
Filename, size File type Python version Upload date Hashes
Filename, size bendercoder-1.2.1-py3-none-any.whl (5.4 kB) File type Wheel Python version py3 Upload date Hashes View hashes
Filename, size bendercoder-1.2.1.tar.gz (3.9 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page