C # zip and decompress the folder

Source: Internet
Author: User

SharpLibZip is required. The Code is as follows:

Zip. cs Public class Zip
{
/// <Summary>
/// Compressed folder
/// </Summary>
/// <Param name = "dirPath"> path of the compressed folder </param>
/// <Param name = "fileName"> generated zip file path </param>
/// <Param name = "level"> compression level 0-9 0: storage level 9: maximum compression </param>
/// <Param name = "bufferSize"> buffer size of the file to be read </param>
Public void CompressDirectory (string dirPath, string fileName, int level, int bufferSize)
{
Byte [] buffer = new byte [bufferSize];
Using (ZipOutputStream s = new ZipOutputStream (File. Create (fileName )))
{
S. SetLevel (level );
CompressDirectory (dirPath, dirPath, s, buffer );
S. Finish ();
S. Close ();
}
}

/// <Summary>
/// Compressed folder
/// </Summary>
/// <Param name = "root"> compressed folder path </param>
/// <Param name = "path"> path of the folder to be compressed </param>
/// <Param name = "s"> </param>
//

Related Article

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.