Closed Ravencentric closed 1 month ago
Thank your for contributing!
Have you considered checking for bytearray?
if isinstance(stream, (bytes, bytearray)):
Wouldn't it be better to throw an exception if len(stream) > MAX_TORRENT_FILE_SIZE?
I can't think of a scenario where a giant byte stream starts with valid torrent metadata.
And if someone encounters torrent metadata that is larger than MAX_TORRENT_FILE_SIZE, your current implementation would probably result in a confusing exception from bdecode().
In the TypeError message, type(stream).name would provide a nicer error message, e.g. "list" instead of "<class 'list'>".
Thanks for the pointers! I'll fix them up.
All three of these work now:
import io
import requests
from torf import Torrent
resp = requests.get("https://releases.ubuntu.com/24.04/ubuntu-24.04.1-desktop-amd64.iso.torrent")
print(Torrent.read_stream(bytes(resp.content)))
print(Torrent.read_stream(bytearray(resp.content)))
print(Torrent.read_stream(io.BytesIO(resp.content)))
Closes https://github.com/rndusr/torf/issues/48