process GZip Decode - CSharp System.IO.Compression

CSharp examples for System.IO.Compression:GZip

Description

process GZip Decode

Demo Code


using System.IO.Compression;
using System.IO;// ww  w  .j  a va2s. c  o m
using System;

public class Main{
        public static byte[] processGZipDecode(byte[] content, int length)
        {
            var wms = new MemoryStream();

            var ms = new MemoryStream(content, 0, length);
            ms.Seek(0, SeekOrigin.Begin);
            var zip = new GZipStream(ms, CompressionMode.Decompress, true);

            var buf = new byte[4096];
            int n;
            while ((n = zip.Read(buf, 0, buf.Length)) != 0)
            {
                wms.Write(buf, 0, n);
            }

            zip.Close();
            ms.Close();

            var r = new byte[wms.Length];
            Array.Copy(wms.GetBuffer(), r, wms.Length);
            return r;
        }
        public static byte[] processGZipDecode(byte[] content)
        {
            return processGZipDecode(content, content.Length);
        }
}

Related Tutorials