• 大小: 0.01M
    文件类型: .cs
    金币: 2
    下载: 1 次
    发布日期: 2021-06-11
  • 语言: C#
  • 标签: 其他  

资源简介

Torrent.cs

资源截图

代码片段和文件信息

using System;
using System.IO;
using System.Text;
using System.Collections.Generic;
using System.Text.Regularexpressions;

namespace System
{
    public class Torrent
    {
        #region 私有成员字段
        string announce = ““;
        Listject> announcelist = new Listject>();
        string comment = ““;
        string commentutf8 = ““;
        string createdby = ““;
        DateTime creationdate = new DateTime(1970 1 1 0 0 0);
        string encoding = ““;
        #endregion

        #region 属性
        public string Announce { get { return this.announce; } set { this.announce = value; } }
        public Listject> AnnounceList { get { return this.announcelist; } set { this.announcelist = value; } }
        public string Comment { get { return this.comment; } set { this.comment = value; } }
        public string CommentUTF8 { get { return this.commentutf8; } set { this.commentutf8 = value; } }
        public string CommentBy { get { return this.createdby; } set { this.createdby = value; } }
        public DateTime CreationDate { get { return this.creationdate; } set { this.creationdate = value; } }
        public string TorrentEncoding { get { return this.encoding; } set { this.encoding = value; } }
        #endregion

        FileStream fs;
        BinaryReader br;

        public Torrent(string path)
        {
            fs = new FileStream(path FileMode.Open);
            br = new BinaryReader(fs);
            byte[] buf = new byte[1];
            string str = ““;
            buf[0] = br.ReadByte();
            str = Encoding.UTF8.GetString(buf 0 1);
            if (str == “d“)
            {
                this.ReadAll();
            }
            else
            {
                Exception e = new Exception(“无法解析此文件“);
                throw e;
            }
        }

        int ReadInt(BinaryReader br)
        {

            return 0;
        }

        string ReadString(BinaryReader br)
        {
            byte[] buf = new byte[1];
            string str = ““;
            buf[0] = br.ReadByte();
            str = Encoding.UTF8.GetString(buf);
            Regex reg = new Regex(“^[0-9]*$“);
            if (reg.Match(str).Value != string.Empty)
            {
                buf[0] = br.ReadByte();
                string tmpstr = Encoding.UTF8.GetString(buf);
                while (tmpstr != “:“)
                {
                    str += tmpstr;
                    buf[0] = br.ReadByte();
                    tmpstr = Encoding.UTF8.GetString(buf);
                }
                int j = Convert.ToInt32(str);
                str = ““;
                byte[] buf2 = new byte[j];
                for (int i = 0; i < j; i++)
                {
                    buf2[i] = br.ReadByte();
                }
                str = Encoding.UTF8.GetString(buf2);
                return str;
            }
            else
            {
            

评论

共有 条评论