Ejemplo n.º 1
0
        public async Task <byte[]> Compress(byte[] Source)
        {
            byte[] compressed = new byte[Source.Length + Source.Length / 64 + 16 + 3 + 4];

            int compressedSize = 0;

            await Task.Run(() => {
                byte[] workMemory = new byte[WorkMemorySize_1x_1];

                if (is64Bit)
                {
                    Lzo2.lzo1x_1_compress_64(Source, Source.Length, compressed, ref compressedSize, workMemory);
                }
                else
                {
                    Lzo2.lzo1x_1_compress_32(Source, Source.Length, compressed, ref compressedSize, workMemory);
                }
            });

            byte[] sizedToFit = new byte[compressedSize];

            await Task.Run(() => Array.ConstrainedCopy(compressed, 0, sizedToFit, 0, compressedSize));

            return(sizedToFit);
        }
Ejemplo n.º 2
0
        public LzoCompression()
        {
            int init = is64Bit ? Lzo2.lzo_init_64(1, -1, -1, -1, -1, -1, -1, -1, -1, -1) : Lzo2.lzo_init_32(1, -1, -1, -1, -1, -1, -1, -1, -1, -1);

            if (init != 0)
            {
                throw new Exception("Initialization of lzo2.dll failed.");
            }
        }
Ejemplo n.º 3
0
        public async Task Decompress(byte[] Source, byte[] Destination)
        {
            await Task.Run(() => {
                int destinationSize = Destination.Length;

                if (is64Bit)
                {
                    Lzo2.lzo1x_decompress_64(Source, Source.Length, Destination, ref destinationSize, null);
                }
                else
                {
                    Lzo2.lzo1x_decompress_32(Source, Source.Length, Destination, ref destinationSize, null);
                }
            });
        }