How to realize the asp.net2.0 of server-side compression package

Source: Internet
Author: User
asp.net2.0, how to implement the server-side compression packet self-extracting 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;

/**////<summary>
Summary description of Ziputility
</summary>
public class Ziputility
{
Public ziputility ()
{
//
TODO: Add constructor logic here
//
}

public static void Compress (stream source, stream destination)
{

using (GZipStream output = new GZipStream (destination, compressionmode.compress))
{

Pump (source, output);

}

}



public static void decompress (stream source, stream destination)
{

using (GZipStream input = new GZipStream (source, compressionmode.decompress))
{

Pump (input, destination);

}

}



private static void Pump (stream input, stream output)
{

byte[] bytes = new byte[4096];

int n;

while (n = input. Read (bytes, 0, bytes. Length))!= 0)
{

Output. Write (bytes, 0, N);

}

}

}
Simple application:
protected void Button1_Click (object sender, EventArgs e)
{
FileStream fs=file.openwrite ("D:/data.txt");
Stream C=this. FileUpload1.PostedFile.InputStream;
Ziputility.decompress (c, FS);
Fs. Close ();
C.close ();

}



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.