public void SmallCanCompressAndDecompressUsingStreamTransformer() { var str = "This is a string to compress and uncompress"; var data = Encoding.UTF8.GetBytes(str); byte[] compData; using (var cms = new AsyncMemoryStream()) using (var compressed = cms.AddTransformer(_compressor.CompressWriteStream)) { compressed.WriteAsync(data, 0, data.Length, CancellationToken.None).Wait(); compressed.Complete(CancellationToken.None).Wait(); compData = cms.ToArray(); } byte[] decData; using (var reader = new ReadStreamWrapper(new MemoryStream(compData))) using (var decompressed = reader.AddTransformer(_compressor.DecompressReadStream)) { decData = decompressed.ReadBytes().Result; } var decStr = Encoding.UTF8.GetString(decData, 0, decData.Length); Assert.AreEqual(str, decStr); }
public void LargeCanCompressAndDecompressUsingStreamTransformer() { var data = RandomData(1); byte[] compData; using (var cms = new AsyncMemoryStream()) using (var compressed = cms.AddTransformer(_compressor.CompressWriteStream)) { compressed.WriteAsync(data, 0, data.Length, CancellationToken.None).Wait(); compressed.Complete(CancellationToken.None).Wait(); compData = cms.ToArray(); } byte[] newData; using (var reader = new ReadStreamWrapper(new MemoryStream(compData))) using (var decompressed = reader.AddTransformer(_compressor.DecompressReadStream)) { newData = decompressed.ReadBytes().Result; } Assert.IsTrue(data.SequenceEqual(newData)); }