process GZip Encode - CSharp System.IO.Compression

CSharp examples for System.IO.Compression:GZip

Description

process GZip Encode

Demo Code


using System.IO.Compression;
using System.IO;//  ww w. j  a  v  a 2 s  .  co m
using System;

public class Main{
        public static byte[] processGZipEncode(byte[] content, int length)
        {
            var ms = new MemoryStream();
            ms.Seek(0, SeekOrigin.Begin);
            var zip = new GZipStream(ms, CompressionMode.Compress, true);
            zip.Write(content, 0, length);
            zip.Close();

            var r = new byte[ms.Length];
            Array.Copy(ms.GetBuffer(), r, ms.Length);

            ms.Close();

            return r;
        }
        public static byte[] processGZipEncode(byte[] content)
        {
            return processGZipEncode(content, content.Length);
        }
}

Related Tutorials