Ejemplo n.º 1
0
        public static unsafe int Encode(byte *source, int sourceLength, byte *target, int targetLength, LZ4CompressionLevel level = LZ4CompressionLevel.Level0)
        {
            if (sourceLength <= 0)
            {
                return(0);
            }

            int encoded = level == LZ4CompressionLevel.Level0
                                ? LZ4Engine64.CompressDefault(source, target, sourceLength, targetLength)
                                : LZ4Engine64HC.CompressHC(source, target, sourceLength, targetLength, (int)level);

            return(encoded <= 0 ? -1 : encoded);
        }
Ejemplo n.º 2
0
        public uint FastStreamManual(int blockLength, int sourceLength)
        {
            sourceLength = LZ4MemoryHelper.RoundUp(sourceLength, blockLength);
            var targetLength = 2 * sourceLength;

            var context = (LZ4Engine.StreamT *)LZ4MemoryHelper.AllocZero(sizeof(LZ4Engine.StreamT));
            var source  = (byte *)LZ4MemoryHelper.Alloc(sourceLength);
            var target  = (byte *)LZ4MemoryHelper.Alloc(targetLength);

            try
            {
                Lorem.Fill(source, sourceLength);

                var sourceP = 0;
                var targetP = 0;

                while (sourceP < sourceLength && targetP < targetLength)
                {
                    targetP += LZ4Engine64.CompressFastContinue(
                        context,
                        source + sourceP,
                        target + targetP,
                        Math.Min(blockLength, sourceLength - sourceP),
                        targetLength - targetP,
                        1);
                    sourceP += blockLength;
                }

                return(Tools.Adler32(target, targetP));
            }
            finally
            {
                LZ4MemoryHelper.Free(context);
                LZ4MemoryHelper.Free(source);
                LZ4MemoryHelper.Free(target);
            }
        }
Ejemplo n.º 3
0
 /// <see cref="LZ4Encoder.EncodeBlock(byte*, int, byte*, int)"/>
 protected override int EncodeBlock(byte *source, int sourceLength, byte *target, int targetLength)
 {
     return(LZ4Engine64.CompressFastContinue(_context, source, target, sourceLength, targetLength, 1));
 }