Krusen / BencodeNET

.NET library for encoding/decoding bencode and reading/writing torrent files
The Unlicense
152 stars 28 forks source link

How to write torrent file ? #46

Closed Sonic3R closed 4 years ago

Sonic3R commented 4 years ago

I have

      var file = @"C:\....\test.torrent";
      var parser = new BencodeParser();

      Torrent torrent = parser.Parse<Torrent>(file);

      torrent.Comment = "";
      torrent.CreatedBy = "";
      torrent.CreationDate = DateTime.Now;
      torrent.IsPrivate = true;

      var list = new List<IList<string>>();
      list.Add(new List<string> { "https://mytracker.org" });

      torrent.Trackers = list;

How to save back to test.torrent file ?

Krusen commented 4 years ago
using (var stream = File.OpenWrite("path.to.torrent"))
{
    // Async
    await torrent.EncodeToAsync(stream);

    // Sync
    torrent.EncodeTo(stream);
}
Sonic3R commented 4 years ago

I got it, thanks.