Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

synodriver/fast-bencode

Repository files navigation

✨ fast-bencode ✨

The cython version of bencode

pypi python implementation wheel license action

forked from bencode to support latest version of python

  • extra cython extension to speedup
  • typing with mypy check

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
  • There are alias function loads for bdecode and dumps for bencode
  • load and dump 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))

build

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

About

fast bencode for python, based on cython

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published