예제 #1
0
        static void Main(string[] args)
        {
            // Create the compressor object
            LZOCompressor lzo = new LZOCompressor();

            // Build a quite redundant string
            StringBuilder sb = new StringBuilder();

            for (int i = 0; i < 10000; i++)
            {
                sb.Append("LZO.NET");
            }
            string str = sb.ToString();

            Console.WriteLine("Original-Length: " + str.Length);

            byte[] data = Encoding.Default.GetBytes(str);

            // Now compress the 70000 byte string to something much smaller
            byte[] compressed = lzo.Compress(data);
            Console.WriteLine("Compressed-Length: " + compressed.Length);

            // Decompress the string to its original content
            string str2 = Encoding.Default.GetString(lzo.Decompress(compressed));

            Console.WriteLine("Decompressed-Length: " + str2.Length);
            Console.WriteLine("Equality: " + str.Equals(str2));

            Console.WriteLine("benchmark...");
            Stopwatch stopWatch = new Stopwatch();
            int       count     = 0;

            stopWatch.Start();
            while (stopWatch.ElapsedMilliseconds < 2000)
            {
                lzo.Compress(data);
                count++;
            }
            stopWatch.Stop();
            Console.WriteLine("Compression throughput is (KByte/sec): " + data.Length * count / stopWatch.ElapsedMilliseconds);

            count = 0;
            stopWatch.Reset();
            stopWatch.Start();
            while (stopWatch.ElapsedMilliseconds < 2000)
            {
                lzo.Decompress(compressed);
                count++;
            }
            stopWatch.Stop();
            Console.WriteLine("Uncompression throughput is (KByte/sec): " + data.Length * count / stopWatch.ElapsedMilliseconds);

            Console.ReadKey();
        }
예제 #2
0
        static void Main(string[] args)
        {
            // Create the compressor object
            LZOCompressor lzo = new LZOCompressor();

            // Build a quite redundant string
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < 10000; i++)
            {
                sb.Append("LZO.NET");
            }
            string str = sb.ToString();
            Console.WriteLine("Original-Length: " + str.Length);

            byte[] data = Encoding.Default.GetBytes(str);

            // Now compress the 70000 byte string to something much smaller
            byte[] compressed = lzo.Compress(data);
            Console.WriteLine("Compressed-Length: " + compressed.Length);

            // Decompress the string to its original content
            string str2 = Encoding.Default.GetString(lzo.Decompress(compressed));
            Console.WriteLine("Decompressed-Length: " + str2.Length);
            Console.WriteLine("Equality: " + str.Equals(str2));

            Console.WriteLine("benchmark...");
            Stopwatch stopWatch = new Stopwatch();
            int count = 0;
            stopWatch.Start();
            while (stopWatch.ElapsedMilliseconds < 2000)
            {
                lzo.Compress(data);
                count++;
            }
            stopWatch.Stop();
            Console.WriteLine("Compression throughput is (KByte/sec): " + data.Length * count / stopWatch.ElapsedMilliseconds);

            count = 0;
            stopWatch.Reset();
            stopWatch.Start();
            while (stopWatch.ElapsedMilliseconds < 2000)
            {
                lzo.Decompress(compressed);
                count++;
            }
            stopWatch.Stop();
            Console.WriteLine("Uncompression throughput is (KByte/sec): " + data.Length * count / stopWatch.ElapsedMilliseconds);

            Console.ReadKey();
        }
예제 #3
0
 private void decompressLZO()
 {
     uncompressedData = new byte[uncompressedDataSize];
     lock (lockObject)
     {
         lzo.Decompress(compressedData, uncompressedData, uncompressedDataSize);
     }
 }
예제 #4
0
        /**解压线程*/
        private void deCompressFun()
        {
            while (isConnect)
            {
                try
                {
                    RecPacket     recPacket   = recPacketQueue.Dequeue();
                    LZOCompressor lzoCompress = new LZOCompressor();
                    if (recPacket != null)
                    {
                        RecPacket.PacketType      packetType    = recPacket.getPacketType();
                        DifferentBitmapWithCursor difbitWithCur = new DifferentBitmapWithCursor();
                        difbitWithCur.setPacketType(packetType);
                        switch (packetType)
                        {
                        case RecPacket.PacketType.BITMAP:
                            difbitWithCur.setBitmapType(recPacket.getBitmapType());
                            difbitWithCur.setCursorPoint(recPacket.getCursorPoint());
                            difbitWithCur.setDifPointsList(recPacket.getDifPointsList());
                            byte[] dataBytes = recPacket.getBitByts();
                            byte[] getByte   = lzoCompress.Decompress(dataBytes);
                            Bitmap temp      = (Bitmap)Bitmap.FromStream(new MemoryStream(getByte));

                            difbitWithCur.setDifBitmap(temp);
                            /**放入差异队列*/
                            deCompressDifQueue.Enqueue(difbitWithCur);
                            labelDif.Text = "差异队列大小:" + deCompressDifQueue.getQueueSize() + "\r\n";
                            break;

                        case RecPacket.PacketType.TEXT:
                            difbitWithCur.setStringValue(recPacket.getStringValue());
                            deCompressDifQueue.Enqueue(difbitWithCur);
                            labelDif.Text = "差异队列大小:" + deCompressDifQueue.getQueueSize() + "\r\n";
                            break;

                        default:
                            break;
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
예제 #5
0
        public void decompress(int compFlag)
        {
            if (compFlag == 0)
            {
                //uncompressed
                uncompressedData = (byte[])(compressedData.Clone());
            }
            else if (((CompressionTypes)compFlag & CompressionTypes.ZLIB) > 0)
            {
                try
                {
                    var byteStream = new MemoryStream();
                    var outStream  = new ZlibStream(byteStream, CompressionMode.Decompress);
                    outStream.Write(compressedData, 0, compressedData.Length);
                    uncompressedData = byteStream.GetBuffer();
                }
                catch (Exception e)
                {
                    logger.Error(e);
                }
            }
            else if (((CompressionTypes)compFlag & CompressionTypes.LZX) > 0)
            {
                logger.Error("Found COMPRESS_LZX, unsupported!");
            }
            else if (((CompressionTypes)compFlag & CompressionTypes.LZO) > 0)
            {
                uncompressedData = new byte[uncompressedDataSize];
                lock (lockObject)
                {
                    lzo.Decompress(compressedData, uncompressedData, uncompressedDataSize);
                }
            }

            if (uncompressedData != null)
            {
                uncompressedDataSize = uncompressedData.Length;
                compressedData       = null; //save memory
            }
        }
예제 #6
0
 private static byte[] NativeLZODecompressor(byte[] input, int outputLength)
 {
     return(LZOCompressor.Decompress(input));
 }
예제 #7
0
 public static byte[] DecompressLZO(byte[] input)
 {
     return(LZOCompressor.Decompress(input));
 }