/// <summary> /// Считывание файла /// </summary> protected override void ReadFromFile() { Debug.WriteLine("Read start"); try { using (FileStream _sourceFile = new FileStream(sourceFile, FileMode.Open)) { byte[] _lastBuffer; totalBlockCount = (long)Math.Ceiling((decimal)(_sourceFile.Length * 1.0 / blockSize)); ConsoleProgressBar.SetFileSize(_sourceFile.Length); while (_sourceFile.Position < _sourceFile.Length && !cancelled) { byte[] _lengthBuffer = new byte[8]; _sourceFile.Read(_lengthBuffer, 0, _lengthBuffer.Length); int _blockLength = BitConverter.ToInt32(_lengthBuffer, 4); byte[] _compressedData = new byte[_blockLength]; _lengthBuffer.CopyTo(_compressedData, 0); _sourceFile.Read(_compressedData, 8, _blockLength - 8); int _dataSize = BitConverter.ToInt32(_compressedData, _blockLength - 4); _lastBuffer = new byte[_dataSize]; ByteBlock _block = new ByteBlock(counterForDecompress, _lastBuffer, _compressedData); queueReader.EnqueueForWriting(_block); counterForDecompress++; } } } catch (Exception ex) { cancelled = true; throw; } finally { queueReader.Stop(); Debug.WriteLine("Read end"); } }
/// <summary> /// Считывание файла /// </summary> protected override void ReadFromFile() { Debug.WriteLine("Read start"); try { using (FileStream _sourceFile = new FileStream(sourceFile, FileMode.Open)) { int _bytesCount; byte[] _lastBuffer; totalBlockCount = (long)Math.Ceiling((decimal)(_sourceFile.Length * 1.0 / blockSize)); ConsoleProgressBar.SetFileSize(_sourceFile.Length); while (_sourceFile.Position < _sourceFile.Length && !cancelled) { if (_sourceFile.Length - _sourceFile.Position <= blockSize) { _bytesCount = (int)(_sourceFile.Length - _sourceFile.Position); } else { _bytesCount = blockSize; } _lastBuffer = new byte[_bytesCount]; _sourceFile.Read(_lastBuffer, 0, _bytesCount); queueReader.EnqueueForCompressing(_lastBuffer); } } } catch (Exception ex) { cancelled = true; throw; } finally { queueReader.Stop(); Debug.WriteLine("Read end"); } }