Exemple #1
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;
            }
        }