Ejemplo n.º 1
0
        public void CompressionImprovesWithDictionary()
        {
            var trainingData = new byte[100][];

            for (int i = 0; i < trainingData.Length; i++)
            {
                trainingData[i] = DataGenerator.GetSmallBuffer(DataFill.Random);
            }

            var dict = DictBuilder.TrainFromBuffer(trainingData);

            var compressionOptions = new CompressionOptions(dict);

            var testStream         = DataGenerator.GetSmallStream(DataFill.Random);
            var normalResultStream = new MemoryStream();

            using (var compressionStream = new CompressorStream(normalResultStream))
                testStream.CopyTo(compressionStream);

            var dictResultStream = new MemoryStream();

            using (var compressionStream = new CompressorStream(dictResultStream, compressionOptions))
                testStream.CopyTo(compressionStream);

            Assert.Greater(normalResultStream.Length, dictResultStream.Length);
        }
Ejemplo n.º 2
0
        public void CompressionShrinksData()
        {
            var inStream  = DataGenerator.GetLargeStream(DataFill.Sequential);
            var outStream = new MemoryStream();

            using (var compressionStream = new CompressorStream(outStream))
                inStream.CopyTo(compressionStream);

            Assert.Greater(inStream.Length, outStream.Length);
        }
Ejemplo n.º 3
0
        public void RoundTrip_StreamingStreaming()
        {
            var testStream = DataGenerator.GetLargeStream(DataFill.Sequential);
            var tempStream = new MemoryStream();

            using (var compressionStream = new CompressorStream(tempStream))
                testStream.CopyTo(compressionStream);

            var resultStream = new MemoryStream();

            tempStream.Position = 0;
            using (var decompressionsStream = new DecompressorStream(tempStream))
                decompressionsStream.CopyTo(resultStream);

            Validate(testStream.ToArray(), resultStream.ToArray());
        }
Ejemplo n.º 4
0
        public void RoundTrip_StreamingToBatch()
        {
            var testStream = DataGenerator.GetLargeStream(DataFill.Sequential);

            var tempStream = new MemoryStream();

            using (var compressorStream = new CompressorStream(testStream))
                tempStream.CopyTo(compressorStream);

            byte[] resultBuffer;

            using (var decompressor = new Decompressor())
                resultBuffer = decompressor.Unwrap(tempStream.ToArray());

            Validate(tempStream.ToArray(), resultBuffer);
        }