Metadata-Version: 2.2
Name: bcoder
Version: 1.1
Summary: Tool to decode and encode .torrent files
Author-email: Mykola Bezrukyi <kolya.bezrukiy.03@gmail.com>
License: Copyright (c) 2025 Mykola Bezrukyi
        
        Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
        
Project-URL: Homepage, https://github.com/mbezrukyi/bcoder
Requires-Python: >=3.13
Description-Content-Type: text/markdown
License-File: LICENSE

# bcoder

### About

---

A Python package to handle bencoded values, a serialization format commonly used in `.torrent` files within
the <u>BitTorrent</u> protocol.

### Usage

---

There are __2__ types of classes:
- `BDecoder` - handle decoding of bencoded data to common Python types
- `BEncoder` - handle encoding of common Python types to `bytes` type

Example of `BDecoder` usage:
```python
from bcoder import BDecoder

decoder = BDecoder()

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

decoded = decoder.decode(data)
```

Example of `BEncoder` usage:
```python
from bcoder import BEncoder

encoder = BEncoder()

data = {
    b"announce-list": [
        ["udp:..."],
        ["udp:..."],
    ],
    "info": {
        "piece": b"xfsasf",
        "piece length": 123,
    },
}

encoded = encoder.encode(data)
```

__NOTE__: `BEncoder` can handle mixed types of Python strings - `bytes` and `str`.
