Ejemplo n.º 1
0
        public CompressedBlockReaderTests()
        {
            _testBlocks = new List <byte[]>
            {
                BlockHeader.Concat(new byte[] { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, }).ToArray(),
                BlockHeader.Concat(new byte[] { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, }).ToArray(),
                BlockHeader.Concat(new byte[] { }).ToArray(),
            };

            _outputSharedQueue = new Mock <ISharedQueue <ByteBlock> >();
            _outputSharedQueue
            .Setup(x => x.IsActive).Returns(() => true);
            _outputSharedQueue
            .Setup(x => x.Push(It.IsAny <ByteBlock>()))
            .Callback <ByteBlock>((block) =>
            {
                _outputQueue.Enqueue(block);
            });

            _compressedBlockReader = new CompressedBlockReader(BlockHeader, uncompressedBlockSize: _testBlocks.First().Length);
        }
Ejemplo n.º 2
0
        public void ReadWriteBlock()
        {
            //Arrange
            byte[]      data         = { 1, 1, 2, 3, 5, 8, 13 };
            var         inputStream  = new MemoryStream(data);
            var         outputStream = new MemoryStream();
            BlockReader reader       = new UncompressedBlockReader(inputStream, data.Length);
            BlockWriter writer       = new CompressedBlockWriter(outputStream);

            //Act
            var result1 = reader.Read(out Block block1);

            writer.Write(block1);

            outputStream.Seek(0, SeekOrigin.Begin);
            reader = new CompressedBlockReader(outputStream);
            var result2 = reader.Read(out Block block2);

            //Assert
            Assert.True(result1 && result2);
            Assert.AreEqual(data, block2.Data);
        }
 protected override void Initialization()
 {
     try
     {
         inputStream  = BlockReader.GetInputStream(option.InputFileName);
         outputStream = BlockWriter.GetOutputStream(option.OutputFileName);
     }
     catch (FileNotFoundException)
     {
         Console.WriteLine("Файл не найден");
         isAborted = true;
         return;
     }
     catch (FileLoadException ex)
     {
         OutputConsole.DisplayError(ex);
         isAborted = true;
         return;
     }
     blockReader   = new CompressedBlockReader(inputStream);
     blockWriter   = new DecompressedBlockWriter(outputStream);
     blocksHandler = new BlockHandler(Environment.ProcessorCount, ex => Callback(ex), CompressionMode.Decompress);
 }