Пример #1
0
        public void FastBinaryReader_ShouldWorkForAllSizesSingleThreaded()
        {
            const int max = 10000;

            var bytes = Enumerable.Range(0, max).Select(i => (byte)((i + 17) % 251)).ToArray();

            for (int i = 1; i < max; i++)
            {
                using (var stream = new MemoryStream(bytes, 0, i))
                {
                    using (var reader = new FastBinaryReader(stream, false))
                    {
                        int total = 0;
                        while (reader.Peek() != -1)
                        {
                            total++;

                            byte peek = (byte)reader.Peek();
                            byte read = (byte)reader.Read();

                            Assert.AreEqual(peek, read, "peek failed for byte " + total);
                            Assert.AreEqual(bytes[total - 1], peek, "read failed for byte " + total);
                        }

                        Assert.AreEqual(i, total, "Failed for i=" + i);
                    }
                }
            }
        }
Пример #2
0
        public void StepParser_ShouldReadFile(string path)
        {
            int bytes = 0;

            using (var file = new FastBinaryReader(path))
            {
                while (file.Peek() != -1)
                {
                    file.Read();
                    bytes++;
                }
            }
        }
Пример #3
0
        public void FastBinaryReader_ShouldReadFileSingleThreaded()
        {
            using (var reader = new FastBinaryReader(@"C:\ifc\Hote6005.ifc", false))
            {
                long bytes = 0;
                int  lines = 0;
                while (reader.Peek() != -1)
                {
                    if (reader.Read() == '\n')
                    {
                        lines++;
                    }

                    bytes++;
                }

                Console.WriteLine($"Bytes: {bytes}, Lines: {lines}");
            }
        }