public void WhatIsCompressedCanBeDecompressed() { const string expected = "FooBarBaz"; ZlibCompressionStrategy strategy = new ZlibCompressionStrategy(); byte[] compressed; using (MemoryStream target = new MemoryStream()) { using (StreamWriter compresser = new StreamWriter(strategy.WrapStreamForCompression(target))) { compresser.Write(expected); } target.Flush(); compressed = target.ToArray(); } using (MemoryStream source = new MemoryStream(compressed)) { using (StreamReader decompresser = new StreamReader(strategy.WrapStreamForDecompression(source))) { Assert.Equal(expected, decompresser.ReadToEnd()); } } }
/// <summary> /// Sets the compression paramiters. /// </summary> /// <param name="level">The compression level to use.</param> /// <param name="strategy">The strategy to use for compression.</param> /// <returns>The zlib status state.</returns> public ZlibCompressionState DeflateParams(ZlibCompression level, ZlibCompressionStrategy strategy) => this.Dstate == null ? ZlibCompressionState.ZSTREAMERROR : this.Dstate.DeflateParams(this, level, strategy);