Esempio n. 1
0
        /// <summary>
        /// Uncompress a byte array into a single string.
        /// </summary>
        /// <seealso cref="ZlibStream.CompressString(String)"/>
        /// <param name="compressed">
        /// A buffer containing ZLIB-compressed data.
        /// </param>
        public static String UncompressString(byte[] compressed)
        {
            // workitem 8460
            byte[] working  = new byte[1024];
            var    encoding = System.Text.Encoding.UTF8;

            using (var output = new MemoryStream())
            {
                using (var input = new MemoryStream(compressed))
                {
                    using (Stream decompressor = new ZlibStream(input))
                    {
                        int n;
                        while ((n = decompressor.Read(working, 0, working.Length)) != 0)
                        {
                            output.Write(working, 0, n);
                        }
                    }
                    // reset to allow read from start
                    output.Seek(0, SeekOrigin.Begin);
                    var sr = new StreamReader(output, encoding);
                    return(sr.ReadToEnd());
                }
            }
        }
Esempio n. 2
0
 /// <summary>
 /// Uncompress a 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>
 public static byte[] UncompressBuffer(byte[] compressed)
 {
     // workitem 8460
     byte[] working = new byte[1024];
     using (var output = new MemoryStream())
     {
         using (var input = new MemoryStream(compressed))
         {
             using (Stream decompressor = new ZlibStream(input))
             {
                 int n;
                 while ((n = decompressor.Read(working, 0, working.Length)) != 0)
                 {
                     output.Write(working, 0, n);
                 }
             }
             return(output.ToArray());
         }
     }
 }
Esempio n. 3
0
 /// <summary>
 /// Uncompress a byte array into a single string.
 /// </summary>
 /// <seealso cref="ZlibStream.CompressString(String)"/>
 /// <param name="compressed">
 /// A buffer containing ZLIB-compressed data.  
 /// </param>
 public static String UncompressString(byte[] compressed)
 {
     // workitem 8460
     byte[] working = new byte[1024];
     var encoding = System.Text.Encoding.UTF8;
     using (var output = new MemoryStream())
     {
         using (var input = new MemoryStream(compressed))
         {
             using (Stream decompressor = new ZlibStream(input))
             {
                 int n;
                 while ((n = decompressor.Read(working, 0, working.Length)) != 0)
                 {
                     output.Write(working, 0, n);
                 }
             }
             // reset to allow read from start
             output.Seek(0, SeekOrigin.Begin);
             var sr = new StreamReader(output, encoding);
             return sr.ReadToEnd();
         }
     }
 }
Esempio n. 4
0
 /// <summary>
 /// Uncompress a 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>
 public static byte[] UncompressBuffer(byte[] compressed)
 {
     // workitem 8460
     byte[] working = new byte[1024];
     using (var output = new MemoryStream())
     {
         using (var input = new MemoryStream(compressed))
         {
             using (Stream decompressor = new ZlibStream(input))
             {
                 int n;
                 while ((n = decompressor.Read(working, 0, working.Length)) != 0)
                 {
                     output.Write(working, 0, n);
                 }
             }
             return output.ToArray();
         }
     }
 }