public void CompressionImprovesWithDictionary()
        {
            var dict = TrainDict();
            var compressionOptions = new CompressionOptions(dict);

            var dataStream = DataGenerator.GetSmallStream(DataFill.Sequential);

            var normalResultStream = new MemoryStream();

            using (var compressionStream = new CompressionStream(normalResultStream))
                dataStream.CopyTo(compressionStream);

            dataStream.Seek(0, SeekOrigin.Begin);

            var dictResultStream = new MemoryStream();

            using (var compressionStream = new CompressionStream(dictResultStream, compressionOptions))
                dataStream.CopyTo(compressionStream);

            Assert.Greater(normalResultStream.Length, dictResultStream.Length);

            dictResultStream.Seek(0, SeekOrigin.Begin);

            var resultStream = new MemoryStream();

            using (var decompressionStream = new DecompressionStream(dictResultStream, new DecompressionOptions(dict)))
                decompressionStream.CopyTo(resultStream);

            Assert.AreEqual(dataStream.ToArray(), resultStream.ToArray());
        }
Exemple #2
0
        public void CompressionImprovesWithDictionary()
        {
            var dict = TrainDict();

            var dataStream = DataGenerator.GetSmallStream(DataFill.Sequential);

            var normalResultStream = new MemoryStream();

            using (var compressionStream = new CompressionStream(normalResultStream))
                dataStream.CopyTo(compressionStream);

            dataStream.Seek(0, SeekOrigin.Begin);

            var dictResultStream = new MemoryStream();

            using (var compressionStream = new CompressionStream(dictResultStream))
            {
                compressionStream.LoadDictionary(dict);
                dataStream.CopyTo(compressionStream);
            }

            Assert.True(normalResultStream.Length > dictResultStream.Length);

            dictResultStream.Seek(0, SeekOrigin.Begin);

            var resultStream = new MemoryStream();

            using (var decompressionStream = new DecompressionStream(dictResultStream))
            {
                decompressionStream.LoadDictionary(dict);
                decompressionStream.CopyTo(resultStream);
            }

            Assert.True(dataStream.ToArray().SequenceEqual(resultStream.ToArray()));
        }
        public void RoundTrip_BatchToStreaming()
        {
            var data = DataGenerator.GetLargeBuffer(DataFill.Sequential);

            byte[] compressed;
            using (var compressor = new Compressor())
                compressed = compressor.Wrap(data);

            var resultStream = new MemoryStream();

            using (var decompressionStream = new DecompressionStream(new MemoryStream(compressed)))
                decompressionStream.CopyTo(resultStream);

            Assert.AreEqual(data, resultStream.ToArray());
        }
        public void StreamingCompressionSimpleWrite(byte[] data, int offset, int count)
        {
            var tempStream = new MemoryStream();

            using (var compressionStream = new CompressionStream(tempStream))
                compressionStream.Write(data, offset, count);

            tempStream.Seek(0, SeekOrigin.Begin);

            var resultStream = new MemoryStream();

            using (var decompressionStream = new DecompressionStream(tempStream))
                decompressionStream.CopyTo(resultStream);

            var dataToCompress = new byte[count];

            Array.Copy(data, offset, dataToCompress, 0, count);

            Assert.AreEqual(dataToCompress, resultStream.ToArray());
        }
Exemple #5
0
        public void StreamingCompressionFlushDataFromInternalBuffers()
        {
            var testBuffer = new byte[1];

            var tempStream = new MemoryStream();

            using var compressionStream = new CompressionStream(tempStream);
            compressionStream.Write(testBuffer, 0, testBuffer.Length);
            compressionStream.Flush();

            Assert.True(tempStream.Length > 0);
            tempStream.Seek(0, SeekOrigin.Begin);

            //NOTE: without ZSTD_endStream call on compression
            var resultStream = new MemoryStream();

            using (var decompressionStream = new DecompressionStream(tempStream))
                decompressionStream.CopyTo(resultStream);

            Assert.True(testBuffer.SequenceEqual(resultStream.ToArray()));
        }
Exemple #6
0
 public void DecompressStream(int zstdBufferSize, int copyBufferSize)
 {
     using var decompressionStream = new DecompressionStream(new MemoryStream(CompressedStreamData), zstdBufferSize);
     decompressionStream.CopyTo(Stream.Null, copyBufferSize);
 }