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.

Source Distribution

bendercoder-1.2.1.tar.gz (3.9 kB view details)

Uploaded Source

Built Distribution

bendercoder-1.2.1-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

Details for the file bendercoder-1.2.1.tar.gz.

File metadata

  • Download URL: bendercoder-1.2.1.tar.gz
  • Upload date:
  • Size: 3.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/39.1.0 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.7.0b3

File hashes

Hashes for bendercoder-1.2.1.tar.gz
Algorithm Hash digest
SHA256 b85a8a56732a19853e277640cc752502c70c46fc6635580fc35cf32ae35807c3
MD5 7c895d3eeea599e9c65d5ecea1d5eeea
BLAKE2b-256 ea3171b06381a9aead39a32878cae0fc6ce7cc7e7fdf276231487687afebf2cc

See more details on using hashes here.

File details

Details for the file bendercoder-1.2.1-py3-none-any.whl.

File metadata

  • Download URL: bendercoder-1.2.1-py3-none-any.whl
  • Upload date:
  • Size: 5.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/39.1.0 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.7.0b3

File hashes

Hashes for bendercoder-1.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 04ceb77c53d834634cd4266459e93603af0e14b6e5c23c433ec6439f9725d34d
MD5 02abc0fc6b840bfa53e074b647a7f835
BLAKE2b-256 526e272e0a306fb5c2ab41e98d49958a411cf2caec16361fc33e63c94c1c08ce

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page