繁体   English   中英

我将如何阅读bittorrent片段?

[英]How would I go about reading bittorrent pieces?

我目前正在为Ruby开发torrent元信息管理库。

我无法读取文件中的内容。 我只是不明白我应该怎么做。 我知道我应该一次对文件的片段长度字节进行SHA1提取(或者多次读取片段长度字节,或者什么?)

我指望您的帮助。 首选Pseudo / Python / Ruby / PHP代码。

提前致谢。

C#

// 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);
}

请在这里查看此分布:

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

用PHP编写,它包含一个Encoder和Decoder以及输入和输出,我相信!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM