Exemplo n.º 1
0
        public void LzmaCompressionDecompression()
        {
            var compressor = new LzmaCompressor {
                Level = 9
            };
            var data = new[] { "abcd", Repeat("xyz", 100) }
            .SelectMany(x => x.ToUtf8Bytes())
            .Concat(Enumerable.Range(0, 1_000_000).Select(x => (byte)x))
            .ToArray();

            var expected = data.ToArray();


            var compStream = new MemoryStream();

            compressor.Compress(data.ToStream(), compStream);
            var compressed = compStream.ToArray();

            Assert.Less(compressed.Length, data.Length);

            var decompStream = new MemoryStream();

            compressor.Decompress(compressed.ToStream(), decompStream);
            var decomp = decompStream.ToArray();

            Assert.AreEqual(expected, decomp);
        }
Exemplo n.º 2
0
        public static async Task <Result <AggregateException> > Deprocess(Stream input, Stream output, string password)
        {
            var comp = new LzmaCompressor();

            var pipe = new Pipe(
                (i, o) => EasyEncrypt.Decrypt(i, o, password),
                (i, o) => comp.Decompress(i, o)
                );

            pipe.SetInput(input);
            pipe.SetOutput(output);
            pipe.BufferSize = 1024 * 1024;

            return(await pipe.Execute());
        }