예제 #1
0
        public static unsafe CompressStatus Compress2(CompressionHandle state, byte[] inBuf, ref int inBufSize, int inBufOffset, byte[] outBuf, ref int outBufSize, int outBufOffset, Flush flushType)
        {
            if (inBufOffset + inBufSize > inBuf.Length)
            {
                throw new ArgumentOutOfRangeException(nameof(inBuf), "Offset + Size is larger than the length of the array.");
            }
            if (outBufOffset + outBufSize > outBuf.Length)
            {
                throw new ArgumentOutOfRangeException(nameof(outBuf), "Offset + Size is larger than the length of the array.");

                fixed(byte *inBytes = inBuf, outBytes = outBuf)
                {
                    IntPtr         inSize  = new IntPtr(inBufSize);
                    IntPtr         outSize = new IntPtr(outBufSize);
                    CompressStatus result  = (CompressStatus)lzham_compress2(state, inBytes + inBufOffset, ref inSize, outBytes + outBufOffset, ref outSize, flushType);

                    inBufSize  = inSize.ToInt32();
                    outBufSize = outSize.ToInt32();
                    return(result);
                }
        }
예제 #2
0
        public static unsafe CompressStatus CompressMemory(CompressionParameters parameters, byte[] inBuf, ref int inBufSize, int inBufOffset, byte[] outBuf, ref int outBufSize, int outBufOffset, ref uint adler32)
        {
            if (inBufOffset + inBufSize > inBuf.Length)
            {
                throw new ArgumentOutOfRangeException(nameof(inBuf), "Offset + Size is larger than the length of the array.");
            }
            if (outBufOffset + outBufSize > outBuf.Length)
            {
                throw new ArgumentOutOfRangeException(nameof(outBuf), "Offset + Size is larger than the length of the array.");
            }

            parameters.Initialize();
            fixed(byte *inBytes = inBuf, outBytes = outBuf)
            {
                byte *         pBytes  = (byte *)&parameters;
                IntPtr         outSize = new IntPtr(outBufSize);
                CompressStatus result  = (CompressStatus)lzham_compress_memory(pBytes, outBytes + outBufOffset, ref outSize, inBytes + inBufOffset, inBufSize, ref adler32);

                outBufSize = outSize.ToInt32();
                return(result);
            }
        }