예제 #1
0
        public override void ReadTasks()
        {
            try
            {
                long remainingBytes = _fileLength;
                int  readCycle      = 0;

                using (BinaryReader bReader = new BinaryReader(File.Open(_inputFile, FileMode.Open, FileAccess.Read, FileShare.Read)))
                {
                    while (remainingBytes > 0)
                    {
                        List <byte> block = new List <byte>(Helper.blockSize);

                        if (readCycle == 0)
                        {
                            gzipHeader      = bReader.ReadBytes(gzipHeader.Length);
                            remainingBytes -= gzipHeader.Length;
                        }
                        block.AddRange(gzipHeader);

                        int foundCount = 0;
                        while (remainingBytes > 0)
                        {
                            var currentByte = bReader.ReadByte();
                            block.Add(currentByte);
                            remainingBytes--;
                            if (remainingBytes <= 0)
                            {
                                _blocks_toDecompress_array.Add(block.ToArray());
                                readCycle++;
                                break;
                            }
                            if (currentByte == gzipHeader[foundCount])
                            {
                                foundCount++;
                                if (foundCount != gzipHeader.Length)
                                {
                                    continue;
                                }

                                block.RemoveRange(block.Count - gzipHeader.Length, gzipHeader.Length);
                                _blocks_toDecompress_array.Add(block.ToArray());
                                readCycle++;
                                break;
                            }
                            foundCount = 0;
                        }
                    }
                }
                _blocks_processed_array = new byte[readCycle][];
                _offsets_calc           = new OffsetsCalculator(readCycle);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine("File split into blocks error");
            }
        }
예제 #2
0
 public Compression(string inputFile, string outputFile)
 {
     _inputFile               = inputFile;
     _outputFile              = outputFile;
     _iterations_calc         = new IterationsCalculator(new FileInfo(_inputFile).Length, Helper.blockSize);
     _iterations              = _iterations_calc.IterationCount();
     _blocks_toCompress_array = new byte[_iterations][];
     _blocks_processed_array  = new byte[_iterations][];
     _offsets_calc            = new OffsetsCalculator(_iterations);
     _fileLength              = new FileInfo(inputFile).Length;
 }