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); } }
private static CCtxT *AllocCtx() { return((CCtxT *)LZ4MemoryHelper.Alloc(sizeof(CCtxT))); }