Пример #1
0
        public void ReadBytes_BlockNumberTest(int bufferSize, string path, int blockNum, byte[] source)
        {
            using var fileStream = new FileStream(path, FileMode.Open, FileAccess.Read);

            using var bufferedStream = new BufferedStream(fileStream, bufferSize);

            var fileInfo = new FileInfo(path);

            var reader = new FileBytesReader(bufferedStream, bufferSize, fileInfo.Length);

            while (reader.CanRead)
            {
                var(buffer, blockNumber) = reader.ReadBytes();

                if (blockNumber == blockNum)
                {
                    Assert.AreEqual(source, buffer);
                }
            }
        }
Пример #2
0
        public void ReadBytes_LastBlockTest(int bufferSize, string path)
        {
            using var fileStream = new FileStream(path, FileMode.Open, FileAccess.Read);

            using var bufferedStream = new BufferedStream(fileStream, bufferSize);

            var fileInfo = new FileInfo(path);

            var reader = new FileBytesReader(bufferedStream, bufferSize, fileInfo.Length);

            var result = new List <byte[]>();

            while (reader.CanRead)
            {
                var(buffer, blockNumber) = reader.ReadBytes();

                result.Add(buffer);
            }

            Assert.AreEqual(fileInfo.Length % bufferSize, result.Last().Length);
        }