protected override void ProccessingData(object indexThread) { try { byte[] hederBytes; int lenghtBlock; int dataLenght; byte[] data; long position; long sizefile; while (true && !IsError) { BlockData block; if (BlockReaded.TryTakeBlock(out block)) { using (var memStream = new MemoryStream(block.Bytes)) { using (var gzipStream = new GZipStream(memStream, CompressionMode.Decompress)) { hederBytes = new byte[4] { block.Bytes[4], block.Bytes[5], block.Bytes[6], block.Bytes[7] }; lenghtBlock = BitConverter.ToInt32(hederBytes, 0); dataLenght = BitConverter.ToInt32(block.Bytes, lenghtBlock - 4); data = new byte[dataLenght]; gzipStream.Read(data, 0, dataLenght); //отделяем от data первые 8 байт - 4 байта позиция записи, 4 байта размер файла data = GetHelpersData(out position, out sizefile, data); BlockProcessed.AddBlock(new BlockData(position, sizefile, data)); BlocksProcessedCount++; } } } else { if (BlockReaded.IsFinish && BlocksProcessedCount == BlocksCount) { BlockProcessed.Finish(); } return; } } } catch (IOException e) { ErrorOutput(e, "Unable to complete decompression operation due to insufficient RAM. Please close other applications and try again. "); } catch (OutOfMemoryException e) { ErrorOutput(e, "Not enough RAM to complete file decompression. Please close other applications and try again. "); } catch (Exception e) { ErrorOutput(e); } finally { EventWaitHandleArray[(int)indexThread].Set(); } }
/// <summary> /// сжатие данных /// </summary> protected override void ProccessingData(object indexThread) { try { BlockData block; while (true && !IsError) { if (BlockReaded.TryTakeBlock(out block)) { using (var memStream = new MemoryStream()) { using (var gzipStream = new GZipStream(memStream, CompressionMode.Compress)) { gzipStream.Write(block.Bytes, 0, block.Bytes.Length); } BlockProcessed.AddBlock(new BlockData(memStream.ToArray())); BlocksProcessedCount++; } } else { if (BlockReaded.IsFinish && BlocksProcessedCount == BlocksCount) { BlockProcessed.Finish(); } return; } } } catch (IOException e) { ErrorOutput(e, "Unable to complete compression operation due to insufficient RAM. Please close other applications and try again. "); } catch (OutOfMemoryException e) { ErrorOutput(e, "Not enough RAM to complete file compression. Please close other applications and try again. "); } catch (Exception e) { ErrorOutput(e); } finally { EventWaitHandleArray[(int)indexThread].Set(); } }