Ejemplo n.º 1
0
        private void Read()
        {
            try
            {
                using (FileStream _compressedFile = new FileStream(SourceFile, FileMode.Open))
                {
                    while (_compressedFile.Position < _compressedFile.Length)
                    {
                        byte[] lengthBuffer = new byte[8];                             //8
                        _compressedFile.Read(lengthBuffer, 0, lengthBuffer.Length);
                        int    blockLength    = BitConverter.ToInt32(lengthBuffer, 4); //4
                        byte[] compressedData = new byte[blockLength];
                        lengthBuffer.CopyTo(compressedData, 0);
                        _compressedFile.Read(compressedData, 8, blockLength - 8);
                        int    _dataSize  = BitConverter.ToInt32(compressedData, blockLength - 4);//-4
                        byte[] lastBuffer = new byte[_dataSize];

                        ByteBlock _block = new ByteBlock(_counter, lastBuffer, compressedData);
                        QueueReader.EnqueueForWriting(_block);
                        _counter++;

                        ConsoleProgress.ProgressBar(_compressedFile.Position, _compressedFile.Length);
                    }
                    QueueReader.Stop();
                }
            }

            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Cancelled = true;
            }
        }
Ejemplo n.º 2
0
        public override void Read(object sourceFile)
        {
            try
            {
                using (FileStream _compressedFile = new FileStream((string)sourceFile, FileMode.Open))
                {
                    while (_compressedFile.Position < _compressedFile.Length)
                    {
                        _readerEvent.WaitOne();

                        byte[] lengthBuffer = new byte[8];
                        _compressedFile.Read(lengthBuffer, 0, lengthBuffer.Length);
                        int    blockLength    = BitConverter.ToInt32(lengthBuffer, 4);
                        byte[] compressedData = new byte[blockLength];
                        lengthBuffer.CopyTo(compressedData, 0);

                        _compressedFile.Read(compressedData, 8, blockLength - 8);
                        int    _dataSize  = BitConverter.ToInt32(compressedData, blockLength - 4);
                        byte[] lastBuffer = new byte[_dataSize];

                        ByteBlock _block = new ByteBlock(counter, lastBuffer, compressedData);

                        QueueReader.EnqueueForWriting(_block);
                        counter++;
                        WorkInProgress(_compressedFile.Position, _compressedFile.Length);
                    }
                    QueueReader.Stop();
                    _workComplited = true;
                }
            }

            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                _cancelled     = true;
                _workComplited = true;
            }
        }
Ejemplo n.º 3
0
        private void Read()
        {
            try
            {
                using (FileStream _fileToBeCompressed = new FileStream(SourceFile, FileMode.Open))
                {
                    int    bytesRead;
                    byte[] lastBuffer;

                    while (_fileToBeCompressed.Position < _fileToBeCompressed.Length && !Cancelled)
                    {
                        if (_fileToBeCompressed.Length - _fileToBeCompressed.Position <= BlockSize)
                        {
                            bytesRead = (int)(_fileToBeCompressed.Length - _fileToBeCompressed.Position);
                        }

                        else
                        {
                            bytesRead = BlockSize;
                        }

                        lastBuffer = new byte[bytesRead];
                        _fileToBeCompressed.Read(lastBuffer, 0, bytesRead);
                        QueueReader.EnqueueForCompressing(lastBuffer);
                        ConsoleProgress.ProgressBar(_fileToBeCompressed.Position, _fileToBeCompressed.Length);
                    }

                    QueueReader.Stop();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Cancelled = true;
            }
        }