A fast bencode implementation in Cython supports both Python2 & Python3 .
pip install bencoder.pyx
from bencoder import bencode, bdecode, bdecode2
assert bencode("WWWWWW") == b'6:WWWWWW'
assert bencode(233) == b'i233e'
with open("debian-8.3.0-amd64-netinst.iso.torrent", "rb") as f:
torrent = bdecode(f.read())
print(torrent['announce'])
decoded, length = bdecode2(b'6:WWWWWWi233e')
assert decoded == b'WWWWWW'
assert length == 8
- Add bdecode2 method. #6
- Performance Improvement
- Fix package metainfo #3
- Support encode large int
- Use OrderedDict instaed of dict
- Support encoding subclasses of dict