Decompress byte array - CSharp System.IO.Compression

CSharp examples for System.IO.Compression:GZip

Description

Decompress byte array

Demo Code


using System.Text;
using System.IO.Compression;
using System.IO;//from   w w  w  . ja  v  a  2 s .  c  o m
using System;

public class Main{
        public static byte[] Decompress(byte[] compressedData)
      {
         if (compressedData == null) return null;
         var inputStream = new MemoryStream(compressedData);
         var outputStream = new MemoryStream();
         var zip = new GZipStream(inputStream, CompressionMode.Decompress);
         var bytes = new byte[4096];
         int n;
         while ((n = zip.Read(bytes, 0, bytes.Length)) != 0)
            outputStream.Write(bytes, 0, n);
         return outputStream.ToArray();
      }
}

Related Tutorials