Пример #1
0
        private byte[] Compress(byte[] srcData, int bufferSize)
        {
            if (!this.CompressMode)
            {
                throw new Exception();
            }
            int length      = srcData.Length;
            int maxDestSize = Lz4.LZ4_compressBound(length);

            if (maxDestSize <= 0)
            {
                throw new Exception();
            }
            byte[] array1 = new byte[maxDestSize];
            int    num    = Lz4.LZ4_compress_default(srcData, array1, length, maxDestSize);

            if (0 >= num || num >= length)
            {
                throw new Exception();
            }
            Array.Resize <byte>(ref array1, num);
            byte[] array2 = new byte[bufferSize];
            Array.Copy((Array)array1, 0, (Array)array2, bufferSize - num, num);
            if (Lz4.LZ4_decompress_safe(array2, bufferSize - num, array2, 0, num, length) != length)
            {
                throw new Exception();
            }
            Array.Resize <byte>(ref array2, length);
            if (!((IEnumerable <byte>)array2).SequenceEqual <byte>((IEnumerable <byte>)srcData))
            {
                throw new Exception();
            }
            return(array1);
        }
Пример #2
0
 public static int LZ4_decompress_safe(byte[] source, int sourceOffset, byte[] dest, int destOffset, int compressedSize, int maxDecompressedSize)
 {
     using (new Lz4.ScopedGCHandle((object)source, GCHandleType.Pinned))
     {
         using (new Lz4.ScopedGCHandle((object)dest, GCHandleType.Pinned))
             return(Lz4.LZ4_decompress_safe(Marshal.UnsafeAddrOfPinnedArrayElement((Array)source, sourceOffset), Marshal.UnsafeAddrOfPinnedArrayElement((Array)dest, destOffset), compressedSize, maxDecompressedSize));
     }
 }
Пример #3
0
 public static int LZ4_compress_default(byte[] source, byte[] dest, int sourceSize, int maxDestSize)
 {
     using (new Lz4.ScopedGCHandle((object)source, GCHandleType.Pinned))
     {
         using (new Lz4.ScopedGCHandle((object)dest, GCHandleType.Pinned))
             return(Lz4.LZ4_compress_default(Marshal.UnsafeAddrOfPinnedArrayElement((Array)source, 0), Marshal.UnsafeAddrOfPinnedArrayElement((Array)dest, 0), sourceSize, maxDestSize));
     }
 }