Example #1
0
        /// <summary>Compresses data from one buffer into another.</summary>
        /// <param name="source">Input buffer.</param>
        /// <param name="sourceLength">Length of input buffer.</param>
        /// <param name="target">Output buffer.</param>
        /// <param name="targetLength">Output buffer length.</param>
        /// <returns>Number of bytes written, or negative value if output buffer is too small.</returns>
        private static unsafe int Encode(
            byte *source,
            int sourceLength,
            byte *target,
            int targetLength)
        {
            if (sourceLength <= 0)
            {
                return(0);
            }

            var encoded = LZ4_64.LZ4_compress_default(source, target, sourceLength, targetLength);

            return(encoded <= 0 ? -1 : encoded);
        }
Example #2
0
        /// <summary>Compresses data from one buffer into another.</summary>
        /// <param name="source">Input buffer.</param>
        /// <param name="sourceLength">Length of input buffer.</param>
        /// <param name="target">Output buffer.</param>
        /// <param name="targetLength">Output buffer length.</param>
        /// <param name="level">Compression level.</param>
        /// <returns>Number of bytes written, or negative value if output buffer is too small.</returns>
        public static unsafe int Encode(
            byte *source, int sourceLength,
            byte *target, int targetLength,
            LZ4Level level = LZ4Level.L00_FAST)
        {
            if (sourceLength <= 0)
            {
                return(0);
            }

            var encoded =
                level == LZ4Level.L00_FAST
                                        ? LZ4_64.LZ4_compress_default(source, target, sourceLength, targetLength)
                                        : LZ4_64_HC.LZ4_compress_HC(
                    source, target, sourceLength, targetLength, (int)level);

            return(encoded <= 0 ? -1 : encoded);
        }
Example #3
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);
            }
        }
Example #4
0
 public static unsafe int Encode(byte *source, byte *target, int sourceLength, int targetLength)
 {
     return(LZ4_64.LZ4_compress_default(source, target, sourceLength, targetLength));
 }
Example #5
0
 public static unsafe int Decode(byte[] source, byte[] target, int sourceLength)
 {
     fixed(byte *sourceP = source)
     fixed(byte *targetP = target)
     return(LZ4_64.LZ4_decompress_safe(sourceP, targetP, sourceLength, target.Length));
 }
Example #6
0
 public static unsafe int Decode(byte *source, byte *target, int sourceLength, int targetLength) =>
 LZ4_64.LZ4_decompress_safe(source, target, sourceLength, targetLength);
Example #7
0
 public static unsafe int Encode(byte[] source, byte[] target)
 {
     fixed(byte *sourceP = source)
     fixed(byte *targetP = target)
     return(LZ4_64.LZ4_compress_default(sourceP, targetP, source.Length, target.Length));
 }
 protected override int EncodeBlock(
     byte *source, int sourceLength, byte *target, int targetLength) =>
 LZ4_64.LZ4_compress_fast_continue(
     _context, source, target, sourceLength, targetLength, 1);