Exemplo n.º 1
0
        private static int CheckZlibTail(byte[] array, int offset, int count, byte[] uncompressData)
        {
            ulong num = 1uL;

            num = Zlib.Adler32(num, uncompressData);
            byte[] bytes = BitConverter.GetBytes((uint)num);
            Array.Reverse(bytes);
            for (int i = 0; i < 4; i++)
            {
                if (array[offset + count - 1 - i] != bytes[3 - i])
                {
                    return(-1);
                }
            }
            return(0);
        }
Exemplo n.º 2
0
        public static byte[] Compress(byte[] array, int offset, int count)
        {
            if (array == null)
            {
                throw new ArgumentNullException("array");
            }
            if (offset < 0)
            {
                throw new ArgumentOutOfRangeException("offset");
            }
            if (count < 0)
            {
                throw new ArgumentOutOfRangeException("count");
            }
            if (array.Length - offset < count)
            {
                throw new ArgumentException("Invalid argument offset count");
            }
            MemoryStream memoryStream = new MemoryStream();

            using (DeflateStream deflateStream = new DeflateStream(memoryStream, CompressionMode.Compress, true))
            {
                deflateStream.Write(array, offset, count);
            }
            byte[] array2 = new byte[memoryStream.Length];
            memoryStream.Seek(0L, SeekOrigin.Begin);
            memoryStream.Read(array2, 0, array2.Length);
            memoryStream.Dispose();
            ulong num = 1uL;

            num = Zlib.Adler32(num, array);
            byte[] array3 = new byte[]
            {
                120,
                1
            };
            byte[] bytes = BitConverter.GetBytes((uint)num);
            Array.Reverse(bytes);
            byte[] array4 = new byte[array3.Length + array2.Length + bytes.Length];
            array3.CopyTo(array4, 0);
            array2.CopyTo(array4, array3.Length);
            bytes.CopyTo(array4, array3.Length + array2.Length);
            return(array4);
        }