示例#1
0
        public void ToString_WithoutEncoding_EncodesUsingUTF8()
        {
            var bstring = new BString("æøå äö èéê ñ", Encoding.UTF8);
            var value   = bstring.ToString();

            value.Should().Be("æøå äö èéê ñ");
        }
示例#2
0
        private static void GetTorrentFileList(IList <Model.TorrentFileName> filelist, BDictionary file)
        {
            // File size in bytes (BNumber has implicit conversion to int and long)
            long size = (BNumber)file["length"];

            // List of all parts of the file path. 'dir1/dir2/file.ext' => dir1, dir2 and file.ext
            BList path = (BList)file["path"];

            string fullpath = String.Join("\\", path);

            // Last element is the file name
            BString fileName = (BString)path.Last();

            // Converts fileName (BString = bytes) to a string
            string fileNameString = fileName.ToString(Encoding.UTF8);

            var tf = new Model.TorrentFileName();

            tf.Name     = fileNameString;
            tf.Size     = size;
            tf.Path     = fullpath;
            tf.IsWanted = true;

            filelist.Add(tf);
        }
示例#3
0
        public void ToString_ISO88591()
        {
            var encoding = Encoding.GetEncoding("ISO-8859-1");
            var bstring  = new BString("æøå äö èéê ñ", encoding);
            var value    = bstring.ToString(encoding);

            value.Should().Be("æøå äö èéê ñ");
        }
示例#4
0
        /// <summary>
        /// Parses the encoding string to an <see cref="Encoding"/>.
        /// Returns null if parsing fails.
        /// </summary>
        /// <param name="bstring">The <see cref="BString"/> value to parse.</param>
        /// <returns>The parsed encoding or null if parsing fails.</returns>
        protected virtual Encoding ParseEncoding(BString bstring)
        {
            if (bstring == null)
            {
                return(null);
            }

            var str = bstring.ToString();

            try
            {
                return(Encoding.GetEncoding(str));
            }
            catch (Exception)
            {
                if (string.Equals(str, "UTF8", StringComparison.OrdinalIgnoreCase))
                {
                    return(Encoding.UTF8);
                }
            }

            return(null);
        }
示例#5
0
        public void ReadLocalTorrentFile()
        {
            bool isMultiFile;
            //string file = @"C:\Users\dan.PARADOX\Downloads\ubuntu-14.10-desktop-amd64.iso.torrent";
            string      localfile = @"C:\Users\dan.PARADOX\Downloads\[kat.cr]deadpool.2016.1080p.bluray.x264.dts.jyk.torrent";
            TorrentFile torrent   = Bencode.DecodeTorrentFile(localfile);

            List <string> filelist = new List <string>();

            if (torrent.Info.ContainsKey("files"))
            {
                BList files = (BList)torrent.Info["files"];

                foreach (BDictionary file in files)
                {
                    //http://stackoverflow.com/questions/32067409/decode-bencode-torrent-files

                    // File size in bytes (BNumber has implicit conversion to int and long)
                    int size = (BNumber)file["length"];

                    // List of all parts of the file path. 'dir1/dir2/file.ext' => dir1, dir2 and file.ext
                    BList path = (BList)file["path"];

                    string fullpath = String.Join("|", path);

                    // Last element is the file name
                    BString fileName = (BString)path.Last();

                    // Converts fileName (BString = bytes) to a string
                    string fileNameString = fileName.ToString(Encoding.UTF8);
                }
            }
            else
            {
                filelist.Add(torrent.Info["name"].ToString());
            }
        }
示例#6
0
 public void ToString_WithoutEncoding_EncodesUsingUTF8()
 {
     var bstring = new BString("æøå äö èéê ñ", Encoding.UTF8);
     var value = bstring.ToString();
     value.Should().Be("æøå äö èéê ñ");
 }
示例#7
0
 public void ToString_ISO88591()
 {
     var encoding = Encoding.GetEncoding("ISO-8859-1");
     var bstring = new BString("æøå äö èéê ñ", encoding);
     var value = bstring.ToString(encoding);
     value.Should().Be("æøå äö èéê ñ");
 }