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(); } }
protected override void ReadData() { try { using (var input = new FileStream(InputFile, FileMode.Open, FileAccess.Read)) { var lenght = input.Length; int readCount; byte[] bytes; while (input.Position < lenght && !IsError) { if (lenght - input.Position < BlockSize) { readCount = (int)(lenght - input.Position); } else { readCount = BlockSize; } bytes = new byte[readCount]; input.Read(bytes, 0, readCount); //добавим доп инф. о позиции массива байт в файле и размере файла bytes = AddedHelpersData(input.Position - readCount, lenght, bytes); BlockReaded.AddBlock(new BlockData(bytes)); } BlockReaded.Finish(); } } catch (OutOfMemoryException e) { ErrorOutput(e, "Not enough RAM to complete file read. Please close other applications and try again. "); } catch (Exception e) { ErrorOutput(e); } finally { EventWaitHandleRead.Set(); } }
protected override void ReadData() { try { using (var input = new FileStream(InputFile, FileMode.Open, FileAccess.Read)) { byte[] headerGzip; byte[] bytes; int lenghtBlock; while (input.Position < input.Length && !IsError) { //читаем заголовок запакованного блока и получаем размер полезной нагрузки указанной при записи headerGzip = new byte[8]; input.Read(headerGzip, 0, headerGzip.Length); lenghtBlock = BitConverter.ToInt32(headerGzip, 4); bytes = new byte[lenghtBlock]; headerGzip.CopyTo(bytes, 0); input.Read(bytes, headerGzip.Length, lenghtBlock - headerGzip.Length); BlockReaded.AddBlock(new BlockData(bytes)); } BlockReaded.Finish(); EventWaitHandleRead.Set(); } } catch (OutOfMemoryException e) { ErrorOutput(e, "Not enough RAM to complete file read. Please close other applications and try again. "); } catch (Exception e) { ErrorOutput(e); } finally { EventWaitHandleRead.Set(); } }