Decompress byte array with GZip - CSharp System.IO.Compression

CSharp examples for System.IO.Compression:GZip

Description

Decompress byte array with GZip

Demo Code


using System.IO;/*from w  w w .j a va 2  s  . co m*/
using System.IO.Compression;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System;

public class Main{
        public static byte[] Decompress(byte[] gzBuffer)
        {
            MemoryStream ms = new MemoryStream();
            int msgLength = BitConverter.ToInt32(gzBuffer, 0);
            ms.Write(gzBuffer, 4, gzBuffer.Length - 4);

            byte[] buffer = new byte[msgLength];

            ms.Position = 0;
            GZipStream zip = new GZipStream(ms, CompressionMode.Decompress);
            zip.Read(buffer, 0, buffer.Length);

            return buffer;
        }
}

Related Tutorials