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;
            }
        }