Represents a Zlib stream for compression or decompression.

The ZlibStream is a Decorator on a . It adds ZLIB compression or decompression to any stream.

Using this stream, applications can compress or decompress data via stream Read() and Write() operations. Either compresssion or decompression can occur through either reading or writing. The compression format used is ZLIB, which is documented in IETF RFC 1950, "ZLIB Compressed Data Format Specification version 3.3". This implementation of ZLIB always uses DEFLATE as the compression method. (see IETF RFC 1951, "DEFLATE Compressed Data Format Specification version 1.3.")

The ZLIB format allows for varying compression methods, window sizes, and dictionaries. This implementation always uses the DEFLATE compression method, a preset dictionary, and 15 window bits by default.

This class is similar to DeflateStream, except that it adds the RFC1950 header and trailer bytes to a compressed stream when compressing, or expects the RFC1950 header and trailer bytes when decompressing. It is also similar to the GZipStream.

Inheritance: System.IO.Stream
        /// <summary>
        ///   Uncompress a ZLIB-compressed byte array into a byte array.
        /// </summary>
        ///
        /// <seealso cref="ZlibStream.CompressBuffer(byte[])"/>
        /// <seealso cref="ZlibStream.UncompressString(byte[])"/>
        ///
        /// <param name="compressed">
        ///   A buffer containing ZLIB-compressed data.
        /// </param>
        ///
        /// <returns>The data in uncompressed form</returns>
        public static byte[] UncompressBuffer(byte[] compressed)
        {
            using (var input = new MemoryStream(compressed))
            {
                Stream decompressor =
                    new ZlibStream( input, CompressionMode.Decompress );

                return ZlibBaseStream.UncompressBuffer(compressed, decompressor);
            }
        }
        /// <summary>
        ///   Compress a byte array into a new byte array using ZLIB.
        /// </summary>
        ///
        /// <remarks>
        ///   Uncompress it with <see cref="ZlibStream.UncompressBuffer(byte[])"/>.
        /// </remarks>
        ///
        /// <seealso cref="ZlibStream.CompressString(string)"/>
        /// <seealso cref="ZlibStream.UncompressBuffer(byte[])"/>
        ///
        /// <param name="b">
        /// A buffer to compress.
        /// </param>
        ///
        /// <returns>The data in compressed form</returns>
        public static byte[] CompressBuffer(byte[] b)
        {
            using (var ms = new MemoryStream())
            {
                Stream compressor =
                    new ZlibStream( ms, CompressionMode.Compress, CompressionLevel.BestCompression );

                ZlibBaseStream.CompressBuffer(b, compressor);
                return ms.ToArray();
            }
        }