Esempio n. 1
0
        public void TorrentBuilderBuildsCorrectTorrent()
        {
            byte[] bytes;
            using (var ms = new MemoryStream())
            {
                using (var file = File.Open("torrent.torrent", FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    file.CopyTo(ms);
                }
                bytes = ms.ToArray();
            }
            var torrent = new TorrentSerializer().Deserialize(bytes);
            var builder = new TorrentBuilder(torrent.Encoding ?? Encoding.UTF8);

            foreach (var(path, len) in torrent.Info.Files)
            {
                builder.AddFile(string.Join(Path.DirectorySeparatorChar, path.Select(_ => ((BString)_).ToString())), len);
            }
            builder.SetPieceLength(torrent.Info.PieceLength);
            builder.CalculatePieces(new FSProvider());
            var builded = builder.Build();

            Assert.Equal(builded.Info.Pieces, torrent.Info.Pieces);
        }