GZip byte array - CSharp System.IO.Compression

CSharp examples for System.IO.Compression:GZip

Description

GZip byte array

Demo Code

/********//  www.j ava2s  . c  o m
 * @version   : 1.0.0
 * @author    : Ext.NET, Inc. http://www.ext.net/
 * @date      : 2011-06-15
 * @copyright : Copyright (c) 2011, Ext.NET, Inc. (http://www.ext.net/). All rights reserved.
 * @license   : See license.txt and http://www.ext.net/license/. 
 ********/
using System.Web;
using System.Text;
using System.IO.Compression;
using System.IO;

public class Main{
        public static byte[] GZip(byte[] instance)
        {
            MemoryStream stream = new MemoryStream();
            GZipStream zipstream = new GZipStream(stream, CompressionMode.Compress);
            zipstream.Write(instance, 0, instance.Length);
            zipstream.Close();

            return stream.ToArray();
        }
        public static byte[] GZip(string instance)
        {
            return GZip(Encoding.UTF8.GetBytes(instance));
        }
}

Related Tutorials