this my class ,not use thrid party tool
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using System.IO.Compression;
using System.Runtime.Serialization.Formatters;
using System.Runtime.Serialization.Formatters.Binary;
using System.Xml.Serialization;
using System.Xml;
using System.Text;
namespace My.Common
{
public class function
{
public static MemoryStream CompressionStream(MemoryStream ms)
{
MemoryStream outStream = new MemoryStream();
using (GZipStream output = new GZipStream(outStream, CompressionMode.Compress, true))
{
byte[] bytes = new byte[ms.Length];
int n;
while ((n = ms.Read(bytes, 0, bytes.Length)) != 0)
{
output.Write(bytes, 0, n);
}
}
outStream.Seek(0, SeekOrigin.Begin);
return outStream;
}
public static MemoryStream DeCompressionStream(MemoryStream ms)
{
MemoryStream outStream = new MemoryStream();
using (GZipStream input = new GZipStream(ms, CompressionMode.Decompress, true))
{
byte[] bytes = new byte[4096];
int n;
while ((n = input.Read(bytes, 0, bytes.Length)) != 0)
{
outStream.Write(bytes, 0, n);
}
}
outStream.Flush();
outStream.Seek(0, SeekOrigin.Begin);
return outStream;
}
public static Stream DeCompressionStream(Stream ms)
{
MemoryStream outStream = new MemoryStream();
using (GZipStream input = new GZipStream(ms, CompressionMode.Decompress, true))
{
byte[] bytes = new byte[4096];
int n;
while ((n = input.Read(bytes, 0, bytes.Length)) != 0)
{
outStream.Write(bytes, 0, n);
}
}
outStream.Flush();
outStream.Seek(0, SeekOrigin.Begin);
return (Stream)outStream;
}
}
}