forked from bencode to support latest version of python
- extra cython extension to speedup
typing
with mypy check
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
- There are alias function
loads
forbdecode
anddumps
forbencode
load
anddump
are useful for file-like object
from pprint import pprint
from bencode import load, dumps, loads, dumps
with open("test.torrent", "rb") as f:
data = load(f, decode=False)
pprint(data)
print(dumps(data, bufsize=1000000))
git clone https://github.com/synodriver/fast-bencode.git cd fast-bencode python setup.py build_ext -i