Exemple #1
0
        public static unsafe byte[] Compress(byte *source, int sourceLength, LZ4CompressionLevel level = LZ4CompressionLevel.Level0)
        {
            if (sourceLength <= 0)
            {
                return(Array.Empty <byte>());
            }

            int   targetLength = sourceLength - 1;
            byte *target       = (byte *)LZ4MemoryHelper.Alloc(sourceLength);

            try
            {
                int encodedLength = Encode(source, sourceLength, target, targetLength, level);

                return(encodedLength <= 0
                    ? PickleV0(source, sourceLength, sourceLength)
                    : PickleV0(target, encodedLength, sourceLength));
            }
            finally
            {
                LZ4MemoryHelper.Free(target);
            }
        }
Exemple #2
0
 private static void FreeCtx(CCtxT *context)
 {
     LZ4MemoryHelper.Free(context);
 }