Esempio n. 1
0
        public int WriteCompressedBytes(byte[] input)
        {
            byte[] encryptionKey = new byte[] { 0xDC, 0x45, 0xA6, 0x9C, 0xD3, 0x72, 0x4C, 0xAB };
            byte[] outputBuffer  = new byte[input.Length * 2];

            int compressedSize = LZ4Handler.LZ4_compress(input, outputBuffer, input.Length);

            for (int i = 0; i < compressedSize; i++)
            {
                outputBuffer[i] ^= encryptionKey[i % 8];
            }

            Write(outputBuffer, 0, compressedSize);

            return(compressedSize);
        }
        public byte[] ReadCompressedBytes(int count, uint decompressedSize)
        {
            byte[] encryptionKey = new byte[] { 0xDC, 0x45, 0xA6, 0x9C, 0xD3, 0x72, 0x4C, 0xAB };

            byte[] input  = ReadBytes(count);
            byte[] output = new byte[(int)decompressedSize];

            for (int i = 0; i < input.Length; i++)
            {
                input[i] ^= encryptionKey[i % 8];
            }

            int result = LZ4Handler.LZ4_decompress_safe(input, output, input.Length, (int)decompressedSize);

            if (result != decompressedSize)
            {
                throw new ArgumentException();
            }

            return(output);
        }