synodriver / fast-bencode

fast bencode for python, based on cython
8 stars 1 forks source link
bencode cython

✨ fast-bencode ✨

The cython version of bencode

pypi python implementation wheel license action

forked from bencode to support latest version of python

Usage

from pprint import pprint
from bencode import bdecode, bencode

with open("test.torrent", "rb") as f:
    data = f.read()

raw = bdecode(data, decode=False) # do not decode bytes to str, use this to speedup. default is True
pprint(raw)

assert bencode(raw, bufsize=1000000) == data # customize buffer size(in bytes) to speedup, this reduces call to realloc

with open("test.torrent", "rb") as f: data = load(f, decode=False)

pprint(data)

print(dumps(data, bufsize=1000000))


### build
git clone https://github.com/synodriver/fast-bencode.git
cd fast-bencode
python setup.py build_ext -i