Beispiel #1
0
        /// <summary>
        ///   Compress a byte array into a new byte array using GZip.
        /// </summary>
        ///
        /// <remarks>
        ///   Uncompress it with <see cref="GZipStream.UncompressBuffer(byte[])"/>.
        /// </remarks>
        ///
        /// <seealso cref="GZipStream.CompressString(string)"/>
        /// <seealso cref="GZipStream.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())
            {
                System.IO.Stream compressor =
                    new GZipStream( ms, CompressionMode.Compress, CompressionLevel.BestCompression );

                ZlibBaseStream.CompressBuffer(b, compressor);
                return ms.ToArray();
            }
        }
Beispiel #2
0
 /// <summary>
 ///   Uncompress a GZip'ed byte array into a single string.
 /// </summary>
 ///
 /// <seealso cref="GZipStream.CompressString(String)"/>
 /// <seealso cref="GZipStream.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 MemoryStream(compressed))
     {
         Stream decompressor = new GZipStream(input, CompressionMode.Decompress);
         return ZlibBaseStream.UncompressString(compressed, decompressor);
     }
 }
Beispiel #3
0
        /// <summary>
        ///   Uncompress a GZip'ed byte array into a byte array.
        /// </summary>
        ///
        /// <seealso cref="GZipStream.CompressBuffer(byte[])"/>
        /// <seealso cref="GZipStream.UncompressString(byte[])"/>
        ///
        /// <param name="compressed">
        ///   A buffer containing data that has been compressed with GZip.
        /// </param>
        ///
        /// <returns>The data in uncompressed form</returns>
        public static byte[] UncompressBuffer(byte[] compressed)
        {
            using (var input = new System.IO.MemoryStream(compressed))
            {
                System.IO.Stream decompressor =
                    new GZipStream( input, CompressionMode.Decompress );

                return ZlibBaseStream.UncompressBuffer(compressed, decompressor);
            }
        }