/// <summary> /// Compression of a block method that is used as callback for <see cref="CollectionProcessorThreadPool{T}"/> /// </summary> /// <param name="block">Processing block</param> protected override void ProcessBlock(ByteBlock block) { if (block == null || IsAborted) { return; } using (var memoryStream = new MemoryStream()) { using (var gZipStream = new GZipStream(memoryStream, CompressionMode.Compress)) { gZipStream.Write(block.Buffer, 0, block.Buffer.Length); } var compressedBlock = memoryStream.ToArray().AddByteBlockLengthHeader(); OutputBlocks.Add(block.BlockNumber, compressedBlock); } }
/// <summary> /// Decompression of a block method that is used as callback for <see cref="CollectionProcessorThreadPool{T}"/> /// </summary> /// <param name="block">Processing block</param> protected override void ProcessBlock(ByteBlock block) { if (block == null || IsAborted) { return; } using (var memoryStream = new MemoryStream(block.Buffer)) { var decompressedBlock = block.IsLast ? new byte[OriginalLastBlockLength] : new byte[OriginalBlockSize]; using (var gZipStream = new GZipStream(memoryStream, CompressionMode.Decompress)) { gZipStream.Read(decompressedBlock, 0, decompressedBlock.Length); } OutputBlocks.Add(block.BlockNumber, decompressedBlock); } }
/// <summary> /// Procession of a block method that is used as callback for <see cref="CollectionProcessorThreadPool{T}"/> /// </summary> /// <param name="block">Processing block</param> protected abstract void ProcessBlock(ByteBlock block);