protected override void ZipMethod() { try { while (QueueAfterRead.Count > 0 || !QueueAfterRead.IsEnqueueStoped) { if (GZipController.IsCancelled) { throw new AbortedOperationException("Decompress"); } if (!(QueueAfterRead.Dequeue() is CompressedByteBlock compressedBlock)) { continue; } using (MemoryStream ms = new MemoryStream(compressedBlock.Bytes)) { using (GZipStream gzipStream = new GZipStream(ms, CompressionMode.Decompress)) { var decompressedData = new byte[compressedBlock.DecompressedByteBlockSize]; gzipStream.Read(decompressedData, 0, decompressedData.Length); var decompressedBlock = new ByteBlock(compressedBlock.SerialNumber, decompressedData); QueueBeforeWrite.Enqueue(decompressedBlock); } } } } catch (Exception ex) { var message = $"Error in decompress thread. Error description: {ex.Message}"; LoggerProvider.Logger().Error(message); } }
protected override void ZipMethod() { try { while (QueueAfterRead.Count > 0 || !QueueAfterRead.IsEnqueueStoped) { if (GZipController.IsCancelled) { throw new AbortedOperationException("Compress"); } var block = QueueAfterRead.Dequeue(); if (block == null) { continue; } using (MemoryStream memoryStream = new MemoryStream()) { using (GZipStream gZipStream = new GZipStream(memoryStream, CompressionMode.Compress)) { gZipStream.Write(block.Bytes, 0, block.Bytes.Length); } var compressedData = memoryStream.ToArray(); var compressedBlock = new ByteBlock(block.SerialNumber, compressedData); QueueBeforeWrite.Enqueue(compressedBlock); } } } catch (Exception ex) { var message = $"Error in compressor thread. Error description: {ex.Message}"; LoggerProvider.Logger().Error(message); } }