Csharp/C#教程:解码(BEncode)种子文件分享


解码(BEncode)种子文件

您好我正在使用C#在VS15中创建一个控制台应用程序。

我怎样才能解码torrent文件? 获取torrent文件的名称,大小和日期? 我想从服务器下载一个torrent文件,然后对其进行解码以查看名称,大小和日期。 到目前为止,我可以使用WebCLient下载文件,但我已经搜索并搜索如何解码torrent文件,但没有运气。

我试过这个库并做了这个:

using (var fs = File.OpenRead("Ubuntu.torrent")) { BDictionary bdictionary = Bencode.DecodeDictionary(fs); } 

但我不太明白bdictionary给了我什么? 我想在控制台中输出种子信息。

我最近添加了专门用于torrent文件的function。 到目前为止它是非常基本的,只是具有易于访问某些信息的属性。

您应该能够提取这样的文件的名称和大小:

 TorrentFile torrent = Bencode.DecodeTorrentFile("Ubuntu.torrent"); // Calculate info hash (eg "B415C913643E5FF49FE37D304BBB5E6E11AD5101") string infoHash = torrent.CalculateInfoHash(); // Get name and size of each file in 'files' list of 'info' dictionary ("multi-file mode") BList files = (BList)torrent.Info["files"]; foreach (BDictionary file in files) { // File size in bytes (BNumber has implicit conversion to int and long) int size = (BNumber) file["length"]; // List of all parts of the file path. 'dir1/dir2/file.ext' => dir1, dir2 and file.ext BList path = (BList) file["path"]; // Last element is the file name BString fileName = (BString) path.Last(); // Converts fileName (BString = bytes) to a string string fileNameString = fileName.ToString(Encoding.UTF8); } 

有关存储在.torrent的数据的更多信息,请查看BitTorrentSpecification 。

上述就是C#学习教程:解码(BEncode)种子文件分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/cdevelopment/1021563.html

(0)
上一篇 2022年1月6日
下一篇 2022年1月6日

精彩推荐