I want to generate a .torrent file in Java, but I don’t want a big API that does anything like scraping trackers, seeding, etc. This is just for a client that generates meta data. What lightweight solutions exist? I am only generating a .torrent of a single .zip file.
Thanks!
I have put together this self-contained piece of Java code to prepare a .torrent file with a single file.
The .torrent file is created by calling
createTorrent()passing the name of the .torrent file, the name of the shared file and the tracker URL.createTorrent()useshashPieces()to hash the file pieces using Java’sMessageDigestclass. ThencreateTorrent()prepares a meta info dictionary containing the torrent meta-data. This dictionary is then serialized in the proper bencode format using theencode*()methods and saved in a .torrent file.See the BitTorrent spec for details.
Code edits: Make this a bit more compact, fix methods visibility, use character literals where appropriate, use
instanceof Number. And more recently read the file using block I/O because I ‘m trying to use it for real and byte I/O is just slow,