public byte[] Compress() { _builder.Append(HALC.RedundancyMagicSignature); var literalBuffer = new ByteArrayBuilder(); while (HasMoreBytes()) { var repeatCount = GetRepeatCount(); // try RLE first if (repeatCount > HALC.RLECommandLength) { if (literalBuffer.Length > 0) { UseLiteral(literalBuffer.GetBytes()); literalBuffer = new ByteArrayBuilder(); } UseRLE(repeatCount); } else { var previousOccurance = GetPreviousOccurance(); if (previousOccurance.BestMatchLength > HALC.ShortPointerCommandLength && previousOccurance.BestMatchOffset <= HALC.MaxShortPointerOffset && previousOccurance.BestMatchLength <= HALC.MaxShortPointerLength) { if (literalBuffer.Length > 0) { UseLiteral(literalBuffer.GetBytes()); literalBuffer = new ByteArrayBuilder(); } UseShortPointer(previousOccurance); } else if (previousOccurance.BestMatchLength > HALC.LongPointerCommandLength) { if (literalBuffer.Length > 0) { UseLiteral(literalBuffer.GetBytes()); literalBuffer = new ByteArrayBuilder(); } UseLongPointer(previousOccurance); } else { literalBuffer.Append(_uncompressed[_compressionPointer]); _compressionPointer++; } } } if (literalBuffer.Length > 0) { UseLiteral(literalBuffer.GetBytes()); } return(_builder.GetBytes()); }
public RedundancyDecompressor(byte[] compressed) { _compressed = compressed; _builder = new ByteArrayBuilder(); }
public RedundancyCompressor(byte[] uncompressed) { _uncompressed = uncompressed; _builder = new ByteArrayBuilder(); }
public ProbabilityCompressor(byte[] data) { _data = data; _builder = new ByteArrayBuilder(); }