Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/flying-sheep/bcode
bencoding & -decoding library
https://github.com/flying-sheep/bcode
Last synced: about 1 month ago
JSON representation
bencoding & -decoding library
- Host: GitHub
- URL: https://github.com/flying-sheep/bcode
- Owner: flying-sheep
- License: mit
- Created: 2013-01-11T00:56:32.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2014-03-24T19:41:33.000Z (almost 11 years ago)
- Last Synced: 2024-09-17T00:24:35.840Z (3 months ago)
- Language: Python
- Homepage: http://flying-sheep.github.com/bcode/
- Size: 231 KB
- Stars: 26
- Watchers: 7
- Forks: 5
- Open Issues: 1
-
Metadata Files:
- Readme: README.rst
- License: LICENSE
Awesome Lists containing this project
README
bcoding
=======yet another… but mine is fast as hell.
install
-------.. code-block:: bash
pip install bcoding
use
---.. code-block:: python
from bcoding import bencode, bdecode
decoding:
~~~~~~~~~.. code-block:: python
# decoding from binary files or streams:
with open('some.torrent', 'rb') as f:
torrent = bdecode(f)
print(torrent['announce'])# decoding from (byte)strings:
one = bdecode(b'i1e')
two = bdecode('3:two')encoding (note that any iterable or mapping can be bencoded):
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~.. code-block:: python
# encoding into binary files or streams:
bencode({'a': 0}, sys.stdout.buffer) # ⇒ d1:ai0ee# encoding to bytestrings:
assert bencode(('a', 0)) == b'l1:ai0ee'