首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >解码(BEncode) torrent文件

解码(BEncode) torrent文件
EN

Stack Overflow用户
提问于 2015-08-18 16:33:05
回答 1查看 4.5K关注 0票数 3

你好,我正在使用C#在VS15中制作一个控制台应用程序。

如何解码torrent文件?获取torrent文件的名称、大小和日期?我想从服务器上加载一个torrent文件,然后对其进行解码,以查看文件的名称、大小和日期。到目前为止,我可以使用WebCLient下载文件,但我一直在寻找如何解码torrent文件,但没有运气。

我尝试过this library,并这样做:

代码语言:javascript
复制
using (var fs = File.OpenRead("Ubuntu.torrent"))
{
    BDictionary bdictionary = Bencode.DecodeDictionary(fs);
}

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

EN

回答 1

Stack Overflow用户

发布于 2015-09-21 19:19:30

我最近添加了专门用于torrent文件的功能。到目前为止,它是非常基本的,只是为了方便地访问一些信息而具有的属性。

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

代码语言:javascript
复制
TorrentFile torrent = Bencode.DecodeTorrentFile("Ubuntu.torrent");

// Calculate info hash (e.g. "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

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32067409

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档