Use SharpZip for compression and decompression, and use sharpzip for compression and decompression

Source: Internet
Author: User

Use SharpZip for compression and decompression, and use sharpzip for compression and decompression
Use SharpZip for compression and decompression

Prepared by: Zuo qiuwen

 

When you are working on a project, we believe that we will often encounter the need to compress and decompress data streams or dataset byte [] or files, such as using webservice to update and download data, if the file is too large and is not compressed, it is believed that the transfer fails, I would like to share with you the use of a foreign open-source sharpzip class as the decompression class to decompress the code. Here we will make a summary for your reference. If you are interested, you can discuss and learn it together. Otherwise, you can skip it.

 

1. I have worked on a project before. This project has a function to synchronize data with the Headquarters. The client communicates with the Headquarters over the internet and transmits data. We use webservice, the passed data is dataset. At the beginning, I directly used dataset as a parameter for direct transmission. when the data is small, there is no problem. However, if the data is large, it basically fails. At this time, we must use compression. we compress it before transmission, and the server receives it, decompress it, and update it to the server database.

2,We can Http://www.icsharpcode.net/OpenSource/SharpZipLib/Default.aspx Download the source code.

The following figure shows the overall framework of my downloaded webservice:

3,SharpzipComplete code:

View Code

1) Here, the first part of the parameter is input in the form of an object, and the return value is byte [], and these parameters are used in teams.

2) the latter part can directly input byte [] as the parameter, compress it, and return byte []. Of course, both compression and decompression are used in pairs.

4,SharpzipThe function of the base class is mainly used for File compression. The following is the operation code for File compression:

1) For file operations, the following code

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.