Ejemplo n.º 1
0
        public uint FastStreamManual(int blockLength, int sourceLength)
        {
            sourceLength = Mem.RoundUp(sourceLength, blockLength);
            var targetLength = 2 * sourceLength;

            var context = (LZ4_xx.LZ4_stream_t *)Mem.AllocZero(sizeof(LZ4_xx.LZ4_stream_t));
            var source  = (byte *)Mem.Alloc(sourceLength);
            var target  = (byte *)Mem.Alloc(targetLength);

            try
            {
                Lorem.Fill(source, sourceLength);

                var sourceP = 0;
                var targetP = 0;

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

                return(Tools.Adler32(target, targetP));
            }
            finally
            {
                Mem.Free(context);
                Mem.Free(source);
                Mem.Free(target);
            }
        }
 protected override int EncodeBlock(
     byte *source, int sourceLength, byte *target, int targetLength) =>
 LZ4_64.LZ4_compress_fast_continue(
     _context, source, target, sourceLength, targetLength, 1);