public override string ToString()
 {
     return("BlockId = " + BlockId.ToString() +
            "\nCommands:\n" + string.Join(Environment.NewLine, Commands.Select(x => "   " + x.ToString())) +
            "\nInputBlocksNumbers = {" + string.Join("; ", InputBlocks.Select(x => x.ToString())) +
            "}\nOutputBlocksNumbers = {" + string.Join("; ", OutputBlocks.Select(x => x.ToString())) + "}");
 }
示例#2
0
        /// <summary>
        /// Reads of a source file
        /// </summary>
        /// <param name="fileInfo">Source file</param>
        protected override void ReadSource(FileInfo fileInfo)
        {
            using (var fileStream = new FileStream(fileInfo.FullName, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                var  blocksRead         = 0;
                long totalBytesRead     = 0;
                var  compressedFileSize = fileInfo.Length;

                ReadFileHeader(fileStream);
                totalBytesRead += ZipUtils.FileHeaderSize;

                while (!IsAborted)
                {
                    var blockHeader = new byte[ZipUtils.BlockHeaderSize];
                    var bytesRead   = fileStream.Read(blockHeader, 0, ZipUtils.BlockHeaderSize);
                    totalBytesRead += bytesRead;

                    var blockLength = BitConverter.ToInt32(blockHeader, 0);
                    var block       = new byte[blockLength];
                    bytesRead       = fileStream.Read(block, 0, blockLength);
                    totalBytesRead += bytesRead;

                    if (compressedFileSize - totalBytesRead <= 0)
                    {
                        InputBlocks.Enqueue(new ByteBlock(block, blocksRead, true));
                        break;
                    }

                    InputBlocks.Enqueue(new ByteBlock(block, blocksRead));
                    blocksRead++;
                }

                InputBlocks.CompleteFilling();
            }
        }
        /// <summary>
        /// Reads of a source file
        /// </summary>
        /// <param name="fileInfo">Source file</param>
        protected override void ReadSource(FileInfo fileInfo)
        {
            var buffer = new byte[OriginalBlockSize];

            using (var fileStream = new FileStream(fileInfo.FullName, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                int bytesRead;
                var blocksRead = 0;
                while ((bytesRead = fileStream.Read(buffer, 0, buffer.Length)) > 0 && !IsAborted)
                {
                    if (bytesRead < OriginalBlockSize)
                    {
                        OriginalLastBlockLength = bytesRead;
                    }

                    var blockBuffer = new byte[bytesRead];
                    Array.Copy(buffer, blockBuffer, blockBuffer.Length);
                    InputBlocks.Enqueue(new ByteBlock(blockBuffer, blocksRead));
                    blocksRead++;
                }

                InputBlocks.CompleteFilling();
            }
        }