首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我该怎么读bittorrent的文章?

问我该怎么读bittorrent的文章?
EN

Stack Overflow用户
提问于 2010-09-21 07:00:58
回答 2查看 186关注 0票数 0

我目前正在为Ruby开发一个用于管理库的洪流方法。

我很难从文件中读到这些片段。我只是不明白我该怎么做。我知道我应该对一个文件的SHA1片段长度字节进行一次消化(或者多次读取片段长度字节,或者什么?)

我指望你的帮助。伪/ Python / Ruby / PHP代码首选。

提前谢谢。

EN

回答 2

Stack Overflow用户

发布于 2010-09-21 07:10:36

C

代码语言:javascript
复制
// Open the file
using (var file = File.Open(...))
{
    // Move to the relevant place in the file where the piece begins
    file.Seek(piece * pieceLength, SeekOrigin.Begin);

    // Attempt to read up to pieceLength bytes from the file into a buffer
    byte[] buffer = new byte[pieceLength];
    int totalRead = 0;
    while (totalRead < pieceLength)
    {
        var read = stream.Read(buffer, totalRead, pieceLength-totalRead);
        if (read == 0)
        {
            // the piece is smaller than the pieceLength,
            // because it’s the last in the file
            Array.Resize(ref buffer, totalRead);
            break;
        }
        totalRead += read;
    }

    // If you want the raw data for the piece:
    return buffer;

    // If you want the SHA1 hashsum:
    return SHA1.Create().ComputeHash(buffer);
}
票数 1
EN

Stack Overflow用户

发布于 2010-09-21 07:28:19

请看一下这个发行版:

http://prdownload.berlios.de/torrentparse/TorrentParse.GTK.0.21.zip

用PHP编写,它包含一个编码器和解码器,以及我相信的输入和输出!

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

https://stackoverflow.com/questions/3757965

复制
相关文章

相似问题

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