Ejemplo n.º 1
0
 public async Task <byte[]> Decompress(CompressionType type, byte[] compressed)
 {
     if (type != CompressionType.LZ4)
     {
         throw new ArgumentException("Only LZ4 Compression is supported at the moment.");
     }
     return(await Task.Run(() =>
     {
         LZ4Compressor comp = new LZ4Compressor("", K4os.Compression.LZ4.LZ4Level.L12_MAX);
         return comp.Decompress(compressed);
     }));
 }
Ejemplo n.º 2
0
        internal void LZ4Compressor_CanCompressAndDecompress()
        {
            // Arrange
            var message    = "hello world!";
            var compressor = new LZ4Compressor();

            // Act
            var messageBytes = Encoding.UTF8.GetBytes(message);
            var compressed   = compressor.Compress(messageBytes);
            var decompressed = compressor.Decompress(compressed);

            // Assert
            Assert.Equal(message, Encoding.UTF8.GetString(decompressed));
            this.Output.WriteLine(BitConverter.ToString(compressed));
        }
Ejemplo n.º 3
0
        internal void LZ4Compressor_DecompressFromPython()
        {
            // Arrange
            var message    = "hello world!";
            var expected   = Encoding.UTF8.GetBytes(message);
            var compressor = new LZ4Compressor();
            var fromPython = Convert.FromBase64String("BCJNGGhADAAAAAAAAABdDAAAgGhlbGxvIHdvcmxkIQAAAAA=");

            this.Output.WriteLine(Encoding.UTF8.GetString(fromPython));

            // Act
            var decompressed = compressor.Decompress(fromPython);

            // Assert
            Assert.Equal(expected, decompressed);
        }
Ejemplo n.º 4
0
        public void LZ4_Read_Write_Faster_Than_GZip()
        {
            var gzipCompressor = new GZipCompressor();
            var lz4Compressor  = new LZ4Compressor();

            double gzipSeconds = 0;
            double lz4Seconds  = 0;

            Stopwatch watch = new Stopwatch();

            watch.Start();

            for (int i = 0; i < 1000; i++)
            {
                byte[] data       = TestHelper.GetRandomByteArray(10);
                byte[] compressed = gzipCompressor.Compress(data);
                byte[] deflated   = gzipCompressor.Decompress(compressed);
                Assert.IsTrue(data.SequenceEqual(deflated));
            }

            watch.Stop();
            gzipSeconds = watch.Elapsed.TotalSeconds;

            watch = new Stopwatch();
            watch.Start();

            for (int i = 0; i < 1000; i++)
            {
                byte[] data       = TestHelper.GetRandomByteArray(10);
                byte[] compressed = lz4Compressor.Compress(data);
                byte[] deflated   = lz4Compressor.Decompress(compressed);
                Assert.IsTrue(data.SequenceEqual(deflated));
            }

            watch.Stop();
            lz4Seconds = watch.Elapsed.TotalSeconds;

            Assert.IsTrue(lz4Seconds < gzipSeconds);
        }