Ejemplo n.º 1
0
        /// <summary>
        ///   Uncompress a DEFLATE'd byte array into a single string.
        /// </summary>
        ///
        /// <seealso cref="DeflateStream.CompressString(String)"/>
        /// <seealso cref="DeflateStream.UncompressBuffer(byte[])"/>
        ///
        /// <param name="compressed">
        ///   A buffer containing GZIP-compressed data.  
        /// </param>
        ///
        /// <returns>The uncompressed string</returns>
        public static String UncompressString(byte[] compressed)
        {
            using (var input = new System.IO.MemoryStream(compressed))
            {
                System.IO.Stream decompressor =
                    new DeflateStream(input, CompressionMode.Decompress);

                return ZlibBaseStream.UncompressString(compressed, decompressor);
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 ///   Compress a string into a byte array using DEFLATE.
 /// </summary>
 ///
 /// <remarks>
 ///   Uncompress it with <see cref="DeflateStream.UncompressString(byte[])"/>.
 /// </remarks>
 ///
 /// <seealso cref="DeflateStream.UncompressString(byte[])"/>
 /// <seealso cref="DeflateStream.CompressBuffer(byte[])"/>
 ///
 /// <param name="s">
 ///   A string to compress. The string will first be encoded
 ///   using UTF8, then compressed.
 /// </param>
 ///
 /// <returns>The string in compressed form</returns>
 public static byte[] CompressString(String s)
 {
     using (var ms = new System.IO.MemoryStream())
     {
         System.IO.Stream compressor =
             new DeflateStream(ms, CompressionMode.Compress, CompressionLevel.BestCompression);
         ZlibBaseStream.CompressString(s, compressor);
         return ms.ToArray();
     }
 }