Exemplo n.º 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>
        /// <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);
        }