本文整理汇总了C#中FileReader.Start方法的典型用法代码示例。如果您正苦于以下问题:C# FileReader.Start方法的具体用法?C# FileReader.Start怎么用?C# FileReader.Start使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileReader
的用法示例。
在下文中一共展示了FileReader.Start方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
/// <summary>
/// The entry point of the program, where the program control starts and ends.
/// </summary>
/// <param name="args">The command-line arguments.</param>
static void Main(string[] args)
{
String path;
Console.Write("File to create torrent for <absolute path>: ");
path = Console.ReadLine();
while (!(File.Exists(path)))
{
Console.WriteLine("File does not exist, try again.");
Console.Write("File to create torrent for <absolute path>: ");
path = Console.ReadLine();
}
Sha1Hasher sha1Hasher = new Sha1Hasher();
FileReader fileReader = new FileReader(path, sha1Hasher.inputChannel, PIECE_SIZE);
string torrentPath = path + ".torrent";
FileStream torrentFile = new FileStream(torrentPath, FileMode.Create);
int pieces = (int)Math.Ceiling((double)fileReader.fileBytes.Length / (double)PIECE_SIZE);
TorrentFileWriter torrentFileWriter = new TorrentFileWriter(torrentFile, pieces, sha1Hasher.outputChannel);
torrentFileWriter.Start();
// Create the header of the torrent file
StringBuilder torrentHeader = new StringBuilder();
torrentHeader.Append("d8:announce44:udp://tracker.openbittorrent.com:80/announce");
torrentHeader.Append("8:encoding5:UTF-8");
torrentHeader.Append("4:info");
torrentHeader.Append("d6:lengthi" + fileReader.fileBytes.Length + "e");
string filename = path.Substring(path.LastIndexOf('/') + 1);
torrentHeader.Append("4:name" + filename.Length + ":" + filename);
torrentHeader.Append("12:piece lengthi" + PIECE_SIZE + "e");
torrentHeader.Append("6:pieces" + pieces * 20 + ":");
torrentFileWriter.inputChannel.Put(Encoding.UTF8.GetBytes(torrentHeader.ToString()));
sha1Hasher.Start();
fileReader.Start();
// Wait until initial writing has completed
while (!torrentFileWriter.WritingComplete()){}
// Append the bencoding ends
string end = "ee";
torrentFileWriter.inputChannel.Put(Encoding.UTF8.GetBytes(end));
// Wait until writing has completed again
while (!torrentFileWriter.WritingComplete()){}
// Stop the file writer
torrentFileWriter.Stop();
// Close the torrent file
torrentFile.Close();
Console.WriteLine("Torrent file created: \"" + torrentPath + "\"");
}