Example #1
0
        public static NanoPost[] Unpack(byte[] bytes)
        {
            bytes = GZipUtil.Decompress(bytes);
            List <NanoPost> posts = new List <NanoPost>();
            string          str   = Encoding.UTF8.GetString(bytes);

            int count = int.Parse(str.Substring(0, 6), System.Globalization.NumberStyles.HexNumber);

            List <int>    sizes = new List <int>();
            List <string> raws  = new List <string>();

            for (int i = 0; i < count; i++)
            {
                int size = int.Parse(str.Substring((i + 1) * 6, 6), System.Globalization.NumberStyles.HexNumber);
                sizes.Add(size);
            }

            int offset = count * 6 + 6;

            for (int i = 0; i < sizes.Count; i++)
            {
                int size = sizes[i];
                raws.Add(str.Substring(offset, size));
                offset += size;
            }

            var containerHash       = SHA256.Create().ComputeHash(bytes);
            var containerHashString = "";

            containerHash.ToList().ForEach(b => containerHashString += b.ToString("x2"));

            for (int i = 0; i < raws.Count; i++)
            {
                var p = new NanoPost(raws[i]);
                p.ContainerTag = containerHashString;

                if (SpamDetector.IsSpam(p.Message))
                {
                    continue;
                }

                posts.Add(p);
            }

            return(posts.ToArray());
        }
Example #2
0
        public static NanoPost[] Unpack(byte[] bytes)
        {
            bytes = GZipUtil.Decompress(bytes);
            List <NanoPost> posts = new List <NanoPost>();
            string          str   = Encoding.UTF8.GetString(bytes);

            int count = int.Parse(str.Substring(0, 6), System.Globalization.NumberStyles.HexNumber);
            //int count = nbpack.NBPackMain.parse_number(str.Substring(0, 6), System.Globalization.NumberStyles.HexNumber);

            List <int>    sizes = new List <int>();
            List <string> raws  = new List <string>();

            for (int i = 0; i < count; i++)
            {
                int size = int.Parse(str.Substring((i + 1) * 6, 6), System.Globalization.NumberStyles.HexNumber);
//                int size = nbpack.NBPackMain.parse_number(str.Substring((i + 1) * 6, 6), System.Globalization.NumberStyles.HexNumber);
                sizes.Add(size);
            }

            int offset = count * 6 + 6;

            for (int i = 0; i < Math.Min(sizes.Count, IncomingPostsLimit); i++)
            {
                int size = sizes[i];
                raws.Add(str.Substring(offset, size));
                offset += size;
            }

            var containerHash       = SHA256.Create().ComputeHash(bytes);
            var containerHashString = "";

            containerHash.ToList().ForEach(b => containerHashString += b.ToString("x2"));

            for (int i = 0; i < Math.Min(raws.Count, IncomingPostsLimit); i++)
            {
                var p = new NanoPost(raws[i]);
                posts.Add(p);
            }

            return(posts.ToArray());
        }